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 a reference to the ith layer.
78  const GU_AgentLayer &layer(exint i) const
79  { sortLayersIfNeeded(); return *myLayers(i); }
80 
81  /// Return the layer count.
82  exint numLayers() const { return myLayers.size(); }
83 
84  /// Add a clip to the agent definition. Replaces any pre-existing clip of
85  /// the same name.
86  void addClip(const GU_AgentClipConstPtr &clip);
87 
88  /// Remove a clip from the agent definition by name.
89  void removeClip(const UT_StringRef &name);
90 
91  /// Return the list of clips.
93  { sortClipsIfNeeded(); return myClips; }
94 
95  /// Get a pointer to a specfic clip. This may be a NULL pointer.
96  const GU_AgentClip *clip(const UT_StringRef &name) const;
97 
98  /// Get a reference to the ith clip.
99  const GU_AgentClip &clip(exint i) const
100  { sortClipsIfNeeded(); return *myClips(i); }
101 
102  /// Return the clip count.
103  exint numClips() const { return myClips.size(); }
104 
105  /// Add a transform group to the agent definition. Replaces any
106  /// pre-existing group of the same name.
107  void addTransformGroup(const GU_AgentTransformGroupConstPtr &group);
108 
109  /// Remove a transform group from the agent definition by name.
110  void removeTransformGroup(const UT_StringRef &name);
111 
112  /// Return the list of groups.
114  { sortTransformGroupsIfNeeded(); return myTransformGroups; }
115 
116  /// Get a pointer to a specfic group. This may be a NULL pointer.
117  const GU_AgentTransformGroup *transformGroup(const UT_StringRef &name) const;
118 
119  /// Get the index of a transform group, or -1 if it does not exist.
120  exint transformGroupIndex(const UT_StringRef &name) const;
121 
122  /// Get the default transform group, which contains all transforms in the
123  /// rig.
125  { return *myDefaultTransformGroup; }
126 
127  /// Get a reference to the ith group.
129  { sortTransformGroupsIfNeeded(); return *myTransformGroups(i); }
130 
131  /// Return the transform group count.
132  exint numTransformGroups() const { return myTransformGroups.size(); }
133 
134  /// Return the metadata dictionary. This may be a nullptr.
135  const GU_AgentMetadataConstPtr &metadata() const { return myMetadata; }
136 
137  /// Replace the metadata dictionary.
139  { myMetadata = data; }
140 
141  /// Add a custom data item to the agent definition. Replaces any
142  /// pre-existing item of the same name.
143  void addCustomDataItem(const GU_AgentCustomDataItemConstPtr &data);
144 
145  /// Remove a custom data item from the agent definition by name.
146  void removeCustomDataItem(const UT_StringRef &name);
147 
148  /// Return the list of custom data items.
150  { sortCustomDataItemsIfNeeded(); return myCustomDataItems; }
151 
152  /// Get a pointer to a specfic data item by name. This may be a NULL
153  /// pointer.
154  const GU_AgentCustomDataItem *customDataItem(const UT_StringRef &name) const;
155 
156  /// Get a reference to the ith custom data item.
158  { sortCustomDataItemsIfNeeded(); return *myCustomDataItems[i]; }
159 
160  /// Return the number of custom data items.
161  exint numCustomDataItems() const { return myCustomDataItems.size(); }
162 
163  /// Constructs a new instance of a GU_AgentCustomDataItem. The provided
164  /// agent definition can be used if the data item requires references to
165  /// the rig, shape library, etc.
166  using CustomDataItemConstructor =
167  std::function<GU_AgentCustomDataItemPtr (const GU_AgentDefinition &)>;
168 
169  /// Register a new custom data item type.
170  static void registerCustomDataItemType(
171  const UT_StringHolder &dataitemtype,
172  CustomDataItemConstructor constructor);
173 
174  /// Called by GU_Agent during startup to register custom data item types.
175  static void installCustomDataItemTypes();
176 
177 private:
178  void sortLayersIfNeeded() const;
179  void sortClipsIfNeeded() const;
180  void sortTransformGroupsIfNeeded() const;
181  void sortCustomDataItemsIfNeeded() const;
182 
183  /// Constructs the default transform group that contains all of the joints.
184  void addDefaultTransformGroup();
185 
186 private:
187  GU_AgentRigConstPtr myRig;
188  GU_AgentShapeLibConstPtr myShapeLib;
189 
191  UT_StringMap<exint> myLayersIndex;
192 
194  UT_StringMap<exint> myClipsIndex;
195 
197  UT_StringMap<exint> myTransformGroupsIndex;
198  GU_AgentTransformGroupConstPtr myDefaultTransformGroup;
199 
200  GU_AgentMetadataConstPtr myMetadata;
201 
203  UT_StringMap<exint> myCustomDataItemsIndex;
204 
205  bool myAreLayersSorted;
206  bool myAreClipsSorted;
207  bool myAreTransformGroupsSorted;
208  bool myAreCustomDataItemsSorted;
209 };
210 
211 extern "C" {
212  /// Entry point for registering custom data item types.
214 };
215 
216 #endif
const GU_AgentMetadataConstPtr & metadata() const
Return the metadata dictionary. This may be a nullptr.
GLuint const GLchar * name
Definition: glew.h:1814
exint numTransformGroups() const
Return the transform group count.
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:76
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
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.
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.
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
exint numClips() const
Return the clip count.
const GU_AgentCustomDataItem & customDataItem(exint i) const
Get a reference to the ith custom data item.
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
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
GLfloat GLfloat p
Definition: glew.h:16321
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
Definition: ImathBoxAlgo.h:89
const UT_Array< GU_AgentTransformGroupConstPtr > & transformGroups() const
Return the list of groups.
GLint GLboolean GLint layer
Definition: glew.h:3601
const UT_Array< GU_AgentCustomDataItemConstPtr > & customDataItems() const
Return the list of custom data items.
exint numCustomDataItems() const
Return the number of custom data items.
GLboolean GLuint group
Definition: glew.h:2745
UT_IntrusivePtr< const GU_AgentDefinition > GU_AgentDefinitionConstPtr