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 a reference to the ith clip.
102  const GU_AgentClip &clip(exint i) const
103  { sortClipsIfNeeded(); return *myClips(i); }
104 
105  /// Return the clip count.
106  exint numClips() const { return myClips.size(); }
107 
108  /// Add a transform group to the agent definition. Replaces any
109  /// pre-existing group of the same name.
110  void addTransformGroup(const GU_AgentTransformGroupConstPtr &group);
111 
112  /// Remove a transform group from the agent definition by name.
113  void removeTransformGroup(const UT_StringRef &name);
114 
115  /// Return the list of groups.
117  { sortTransformGroupsIfNeeded(); return myTransformGroups; }
118 
119  /// Get a pointer to a specfic group. This may be a NULL pointer.
120  const GU_AgentTransformGroup *transformGroup(const UT_StringRef &name) const;
121 
122  /// Get the index of a transform group, or -1 if it does not exist.
123  exint transformGroupIndex(const UT_StringRef &name) const;
124 
125  /// Get the default transform group, which contains all transforms in the
126  /// rig.
128  { return *myDefaultTransformGroup; }
129 
130  /// Get a reference to the ith group.
132  { sortTransformGroupsIfNeeded(); return *myTransformGroups(i); }
133 
134  /// Return the transform group count.
135  exint numTransformGroups() const { return myTransformGroups.size(); }
136 
137  /// Return the metadata dictionary. This may be a nullptr.
138  const GU_AgentMetadataConstPtr &metadata() const { return myMetadata; }
139 
140  /// Replace the metadata dictionary.
142  { myMetadata = data; }
143 
144  /// Add a custom data item to the agent definition. Replaces any
145  /// pre-existing item of the same name.
146  void addCustomDataItem(const GU_AgentCustomDataItemConstPtr &data);
147 
148  /// Remove a custom data item from the agent definition by name.
149  void removeCustomDataItem(const UT_StringRef &name);
150 
151  /// Return the list of custom data items.
153  { sortCustomDataItemsIfNeeded(); return myCustomDataItems; }
154 
155  /// Get a pointer to a specfic data item by name. This may be a NULL
156  /// pointer.
157  const GU_AgentCustomDataItem *customDataItem(const UT_StringRef &name) const;
158 
159  /// Get a reference to the ith custom data item.
161  { sortCustomDataItemsIfNeeded(); return *myCustomDataItems[i]; }
162 
163  /// Return the number of custom data items.
164  exint numCustomDataItems() const { return myCustomDataItems.size(); }
165 
166  /// Constructs a new instance of a GU_AgentCustomDataItem. The provided
167  /// agent definition can be used if the data item requires references to
168  /// the rig, shape library, etc.
169  using CustomDataItemConstructor =
170  std::function<GU_AgentCustomDataItemPtr (const GU_AgentDefinition &)>;
171 
172  /// Register a new custom data item type.
173  static void registerCustomDataItemType(
174  const UT_StringHolder &dataitemtype,
175  CustomDataItemConstructor constructor);
176 
177  /// Called by GU_Agent during startup to register custom data item types.
178  static void installCustomDataItemTypes();
179 
180 private:
181  void sortLayersIfNeeded() const;
182  void sortClipsIfNeeded() const;
183  void sortTransformGroupsIfNeeded() const;
184  void sortCustomDataItemsIfNeeded() const;
185 
186  /// Constructs the default transform group that contains all of the joints.
187  void addDefaultTransformGroup();
188 
189 private:
190  GU_AgentRigConstPtr myRig;
191  GU_AgentShapeLibConstPtr myShapeLib;
192 
194  UT_StringMap<exint> myLayersIndex;
195 
197  UT_StringMap<exint> myClipsIndex;
198 
200  UT_StringMap<exint> myTransformGroupsIndex;
201  GU_AgentTransformGroupConstPtr myDefaultTransformGroup;
202 
203  GU_AgentMetadataConstPtr myMetadata;
204 
206  UT_StringMap<exint> myCustomDataItemsIndex;
207 
208  bool myAreLayersSorted;
209  bool myAreClipsSorted;
210  bool myAreTransformGroupsSorted;
211  bool myAreCustomDataItemsSorted;
212 };
213 
214 extern "C" {
215  /// Entry point for registering custom data item types.
217 };
218 
219 #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:1298
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:35
GLuint const GLchar * name
Definition: glcorearb.h:785
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:856
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:130
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.
GLboolean GLuint group
Definition: glew.h:2750
const UT_Array< GU_AgentCustomDataItemConstPtr > & customDataItems() const
Return the list of custom data items.
exint numCustomDataItems() const
Return the number of custom data items.
UT_IntrusivePtr< const GU_AgentDefinition > GU_AgentDefinitionConstPtr