HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MocapStreamRokokoHDK.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: MocapStreamRokokoHDK.h ( KineFX Library, C++)
7  *
8  */
9 #ifndef __MOCAPSTREAMROKOKOHDK_H_INCLUDED__
10 #define __MOCAPSTREAMROKOKOHDK_H_INCLUDED__
11 
12 #include <MC/MC_MocapStreamImpl.h>
13 #include <UT/UT_ArrayStringSet.h>
14 
15 namespace HDK_Sample
16 {
17 
19 {
20 public:
21  /// Initializes the MC_MocapStream::ServerOptions class with the default
22  /// values for the different parameters on the MocapStream SOP and define
23  /// which parameters are visible.
25  14043, "", "", "", 0, 0, 32768,
26  {true, false, false, false, false, false, true, false, false, false}}
27  );
28  ~MocapStreamRokokoHDK() override;
29 
30  /// Creates a unique pointer to the the MocapStreamRokokoHDK device from
31  /// a set of server options.
32  ///
33  /// This must be implemented and is used in the connection process.
35  {
36  return UTmakeUnique<MocapStreamRokokoHDK>(opts);
37  }
38 
39  bool parsePacket(UT_StringHolder& packet,
40  fpreal packet_time,
41  bool &parse_incomplete) override;
42  void updateJoints(GU_Detail *gdp,
43  const MC_MocapStreamCookParms &cookparms,
44  const MC_MocapStreamCookParms &prev_cookparms) override;
45  void buildSkeleton(GU_Detail *gdp, UT_StringHolder name) override;
46  void removeSkeleton(const UT_StringHolder& name) override;
47 
48  /// Define the label for this device. This will be added in the "Device"
49  /// menu on the MocapStream SOP.
50  const char* label() const override { return "Rokoko Studio - HDK"; }
51 
52  /// Define a unique name for this device. This will be used to distinguish
53  /// This device from other MocapStream devices.
54  const char* name() const override { return "rokoko_hdk"; }
55 
56 private:
57  void computeSkeletonTransforms();
58 
59  // A structure to hold all of the data for a single point in the motion
60  // capture stream.
61  struct ActorPoint
62  {
63  ActorPoint()
64  : myWorldXform(1.0)
65  , myLocalXform(1.0)
66  , myDidReceive(true)
67  {}
68 
69  UT_Matrix4F myWorldXform;
70  UT_Matrix4F myLocalXform;
71 
72  bool myDidReceive;
73  };
74 
75  // A structure to hold all of the data for a single actor (skeleton or
76  // rigid body) in the motion capture stream.
77  struct Actor
78  {
79  Actor()
80  : myOccurances(0)
81  , myIsDirty(true)
82  {}
83 
84  UT_StringHolder myName;
85 
86  UT_Array<ActorPoint> myPoints;
87  UT_ArrayStringMap<fpreal> myBlendShapes;
88 
89  int myOccurances;
90  bool myIsDirty;
91  };
92 
93  // A structure to hold a set of actors (either skeletons or rigid bodies)
94  // streamed from Rokoko Studio.
95  class ActorList
96  {
97  public:
98  ActorList() {}
99  ~ActorList() {}
100 
101  exint size() { return myActors.size(); }
102 
103  void resetOccurances()
104  {
105  for (auto &actor : myActors)
106  {
107  actor.myOccurances = 0;
108  }
109  }
110 
111  Actor *addActor(UT_StringHolder name)
112  {
113  if (myNameToIdx.contains(name))
114  {
115  Actor &actor = myActors(myNameToIdx[name]);
116  actor.myPoints.clear();
117  return &actor;
118  }
119 
120  Actor new_actor;
121  new_actor.myName = name;
122 
123  myActors.append(new_actor);
124  myNameToIdx[name] = myActors.entries()-1;
125 
126  return &myActors(myActors.entries()-1);
127  }
128 
129  Actor *findActor(UT_StringHolder name)
130  {
131  if (myNameToIdx.contains(name))
132  return &myActors(myNameToIdx[name]);
133 
134  return nullptr;
135  }
136 
137  bool removeActor(UT_StringHolder name)
138  {
139  if (!myNameToIdx.contains(name))
140  return false;
141 
142  exint removed_idx = myNameToIdx[name];
143  myActors.removeIndex(removed_idx);
144 
145  for (auto it = myNameToIdx.begin(); !it.atEnd(); ++it)
146  {
147  if (it->second > removed_idx)
148  it->second--;
149  }
150 
151  return true;
152  }
153 
154  Actor &operator()(exint i)
155  {
156  if (i < 0)
157  i = 0;
158  if (i >= myActors.size())
159  i = myActors.size()-1;
160 
161  return myActors(i);
162  }
163  private:
164  UT_ArrayStringMap<exint> myNameToIdx;
165  UT_Array<Actor> myActors;
166  };
167 
168  ActorList mySkeletons;
169  ActorList myProps;
170 
171  UT_ArrayStringMap<UT_StringArray> myNodeBlendShapes;
172 };
173 }
174 #endif
bool parsePacket(UT_StringHolder &packet, fpreal packet_time, bool &parse_incomplete) override
int64 exint
Definition: SYS_Types.h:125
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
UT_UniquePtr< MC_MocapStreamImpl > clone(const ServerOptions &opts) override
const char * name() const override
GLuint const GLchar * name
Definition: glcorearb.h:786
void removeSkeleton(const UT_StringHolder &name) override
Removes the stored data for a skeleton.
void buildSkeleton(GU_Detail *gdp, UT_StringHolder name) override
void updateJoints(GU_Detail *gdp, const MC_MocapStreamCookParms &cookparms, const MC_MocapStreamCookParms &prev_cookparms) override
GLsizeiptr size
Definition: glcorearb.h:664
fpreal64 fpreal
Definition: SYS_Types.h:277
const char * label() const override
MocapStreamRokokoHDK(const ServerOptions &opts=ServerOptions{14043,"","","", 0, 0, 32768,{true, false, false, false, false, false, true, false, false, false}})