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_Function.h>
25 #include <UT/UT_IntrusivePtr.h>
26 #include <UT/UT_StringMap.h>
27 
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.
71  const UT_Array<GU_AgentLayerConstPtr> &layers() const { return myLayers; }
72 
73  /// Get a pointer to a specfic layer. This may be a NULL pointer.
74  const GU_AgentLayer *layer(const UT_StringRef &name) const;
75 
76  /// Get the index of a layer, or -1 if it does not exist.
78  { return myLayersIndex.get(name, -1); }
79 
80  /// Get a reference to the ith layer.
81  const GU_AgentLayer &layer(exint i) const { return *myLayers(i); }
82 
83  /// Return the layer count.
84  exint numLayers() const { return myLayers.size(); }
85 
86  /// Sorts the layers by name, if any layers have been added or removed since
87  /// the last sort.
88  void sortLayersIfNeeded();
89 
90  /// Add a clip to the agent definition. Replaces any pre-existing clip of
91  /// the same name.
92  void addClip(const GU_AgentClipConstPtr &clip);
93 
94  /// Remove a clip from the agent definition by name.
95  void removeClip(const UT_StringRef &name);
96 
97  /// Return the list of clips.
98  const UT_Array<GU_AgentClipConstPtr> &clips() const { return myClips; }
99 
100  /// Get a pointer to a specfic clip. This may be a NULL pointer.
101  const GU_AgentClip *clip(const UT_StringRef &name) const;
102 
103  /// Get the index of a clip, or -1 if it does not exist.
105  { return myClipsIndex.get(name, -1); }
106 
107  /// Get a reference to the ith clip.
108  const GU_AgentClip &clip(exint i) const { return *myClips(i); }
109 
110  /// Return the clip count.
111  exint numClips() const { return myClips.size(); }
112 
113  /// Sorts the clips by name, if any clips have been added or removed since
114  /// the last sort.
115  void sortClipsIfNeeded();
116 
117  /// Get a rest clip, which contains a single sample at the rig's rest
118  /// pose. This can be used as a fallback for scenarios where a valid clip is
119  /// required.
120  /// Note this clip is not included in the clip catalog and is not saved with
121  /// the agent definition.
122  const GU_AgentClip &restClip() const { return *myRestClip; }
123 
124  /// Add a transform group to the agent definition. Replaces any
125  /// pre-existing group of the same name.
126  void addTransformGroup(const GU_AgentTransformGroupConstPtr &group);
127 
128  /// Remove a transform group from the agent definition by name.
129  void removeTransformGroup(const UT_StringRef &name);
130 
131  /// Return the list of groups.
133  { return myTransformGroups; }
134 
135  /// Get a pointer to a specfic group. This may be a NULL pointer.
136  const GU_AgentTransformGroup *transformGroup(const UT_StringRef &name) const;
137 
138  /// Get the index of a transform group, or -1 if it does not exist.
140  { return myTransformGroupsIndex.get(name, -1); }
141 
142  /// Get the default transform group, which contains all transforms in the
143  /// rig.
145  { return *myDefaultTransformGroup; }
146 
147  /// Get a reference to the ith group.
149  { return *myTransformGroups(i); }
150 
151  /// Return the transform group count.
152  exint numTransformGroups() const { return myTransformGroups.size(); }
153 
154  /// Sorts the transform groups by name, if any groups have been added or
155  /// removed since the last sort.
156  void sortTransformGroupsIfNeeded();
157 
158  /// Return the metadata dictionary. This may be a nullptr.
159  const GU_AgentMetadataConstPtr &metadata() const { return myMetadata; }
160 
161  /// Replace the metadata dictionary.
163  { myMetadata = data; }
164 
165  /// Add a custom data item to the agent definition. Replaces any
166  /// pre-existing item of the same name.
167  void addCustomDataItem(const GU_AgentCustomDataItemConstPtr &data);
168 
169  /// Remove a custom data item from the agent definition by name.
170  void removeCustomDataItem(const UT_StringRef &name);
171 
172  /// Return the list of custom data items.
174  { return myCustomDataItems; }
175 
176  /// Get a pointer to a specfic data item by name. This may be a NULL
177  /// pointer.
178  const GU_AgentCustomDataItem *customDataItem(const UT_StringRef &name) const;
179 
180  /// Get a reference to the ith custom data item.
182  { return *myCustomDataItems[i]; }
183 
184  /// Return the number of custom data items.
185  exint numCustomDataItems() const { return myCustomDataItems.size(); }
186 
187  /// Sorts the custom data items by name, if any items have been added or
188  /// removed since the last sort.
189  void sortCustomDataItemsIfNeeded();
190 
191  /// Constructs a new instance of a GU_AgentCustomDataItem. The provided
192  /// agent definition can be used if the data item requires references to
193  /// the rig, shape library, etc.
194  using CustomDataItemConstructor =
196 
197  /// Register a new custom data item type.
198  static void registerCustomDataItemType(
199  const UT_StringHolder &dataitemtype,
200  CustomDataItemConstructor constructor);
201 
202  /// Called by GU_Agent during startup to register custom data item types.
203  static void installCustomDataItemTypes();
204 
205  /// Sorts the clips, layers, transform groups, and custom data items by
206  /// name, if any items have been added or removed since the last sort.
207  /// This is equivalent to individually calling sortClipsIfNeeded() and
208  /// similar methods.
209  void sortItemsIfNeeded();
210 
211  /// Runs agent functions on a specific dso.
212  static bool runDSO(const char* lib_path);
213 
214 private:
215  /// Constructs the default transform group that contains all of the joints.
216  void addDefaultTransformGroup();
217 
218  /// Constructs the fallback clip which contains a single sample (rest pose).
219  void buildRestClip();
220 
221 private:
222  GU_AgentRigConstPtr myRig;
223  GU_AgentShapeLibConstPtr myShapeLib;
224 
226  UT_StringMap<exint> myLayersIndex;
227 
229  UT_StringMap<exint> myClipsIndex;
230  GU_AgentClipConstPtr myRestClip;
231 
233  UT_StringMap<exint> myTransformGroupsIndex;
234  GU_AgentTransformGroupConstPtr myDefaultTransformGroup;
235 
236  GU_AgentMetadataConstPtr myMetadata;
237 
239  UT_StringMap<exint> myCustomDataItemsIndex;
240 
241  bool myAreLayersSorted;
242  bool myAreClipsSorted;
243  bool myAreTransformGroupsSorted;
244  bool myAreCustomDataItemsSorted;
245 };
246 
247 inline const GU_AgentLayer *
249 {
250  const exint idx = layerIndex(name);
251  return (idx >= 0) ? myLayers[idx].get() : nullptr;
252 }
253 
254 inline const GU_AgentClip *
256 {
257  const exint idx = clipIndex(name);
258  return (idx >= 0) ? myClips[idx].get() : nullptr;
259 }
260 
261 inline const GU_AgentTransformGroup *
263 {
264  const exint idx = transformGroupIndex(name);
265  return (idx >= 0) ? myTransformGroups[idx].get() : nullptr;
266 }
267 
268 inline const GU_AgentCustomDataItem *
270 {
271  const exint idx = myCustomDataItemsIndex.get(name, -1);
272  return (idx >= 0) ? myCustomDataItems[idx].get() : nullptr;
273 }
274 
275 extern "C" {
276  /// Entry point for registering custom data item types.
278 };
279 
280 #endif
const GU_AgentLayer * layer(const UT_StringRef &name) const
Get a pointer to a specfic layer. This may be a NULL pointer.
exint transformGroupIndex(const UT_StringRef &name) const
Get the index of a transform group, or -1 if it does not exist.
UT_Function< GU_AgentCustomDataItemPtr(const GU_AgentDefinition &)> CustomDataItemConstructor
const GU_AgentMetadataConstPtr & metadata() const
Return the metadata dictionary. This may be a nullptr.
exint numTransformGroups() const
Return the transform group count.
const GU_AgentTransformGroup & defaultTransformGroup() const
#define SYS_VISIBILITY_EXPORT
GLboolean * data
Definition: glcorearb.h:131
const UT_Array< GU_AgentClipConstPtr > & clips() const
Return the list of clips.
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:87
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
A reference counter base class for use with UT_IntrusivePtr.
const GU_AgentShapeLibConstPtr & shapeLibrary() const
UT_IntrusivePtr< GU_AgentDefinition > GU_AgentDefinitionPtr
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
exint numLayers() const
Return the layer count.
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(const UT_StringRef &name) const
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
const GU_AgentClip & clip(exint i) const
Get a reference to the ith clip.
#define GU_API
Definition: GU_API.h:14
const GU_AgentClip * clip(const UT_StringRef &name) const
Get a pointer to a specfic clip. This may be a NULL pointer.
const GU_AgentClip & restClip() const
GLuint const GLchar * name
Definition: glcorearb.h:786
std::function< T > UT_Function
Definition: UT_Function.h:37
const GU_AgentTransformGroup * transformGroup(const UT_StringRef &name) const
Get a pointer to a specfic group. This may be a NULL pointer.
const UT_Array< GU_AgentTransformGroupConstPtr > & transformGroups() const
Return the list of groups.
SYS_FORCE_INLINE ITEM_T get(const UT_StringRef &key, const ITEM_T &defval) const
Definition: UT_StringMap.h:63
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
const UT_Array< GU_AgentCustomDataItemConstPtr > & customDataItems() const
Return the list of custom data items.
exint layerIndex(const UT_StringRef &name) const
Get the index of a layer, or -1 if it does not exist.
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 clipIndex(const UT_StringRef &name) const
Get the index of a clip, or -1 if it does not exist.
exint numCustomDataItems() const
Return the number of custom data items.
Definition: format.h:1821
UT_IntrusivePtr< const GU_AgentDefinition > GU_AgentDefinitionConstPtr