Overte C++ Documentation
AnimOverlay.h
1 //
2 // AnimOverlay.h
3 //
4 // Created by Anthony J. Thibault on 9/2/15.
5 // Copyright (c) 2015 High Fidelity, Inc. All rights reserved.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_AnimOverlay_h
12 #define hifi_AnimOverlay_h
13 
14 #include "AnimNode.h"
15 
16 // Overlay the AnimPoses from one AnimNode on top of another AnimNode.
17 // child[0] is overlayed on top of child[1]. The boneset is used
18 // to control blending on a per-bone bases.
19 // alpha gives the ability to fade in and fade out overlays.
20 // alpha of 0, will have no overlay, final pose will be 100% from child[1].
21 // alpha of 1, will be a full overlay.
22 
23 class AnimOverlay : public AnimNode {
24 public:
25  friend class AnimTests;
26 
27  /*@jsdoc
28  * <p>Specifies sets of joints.</p>
29  * <table>
30  * <thead>
31  * <tr><th>Value</th><th>Name</th><th>Description</th>
32  * </thead>
33  * <tbody>
34  * <tr><td><code>0</code></td><td>FullBodyBoneSet</td><td>All joints.</td></tr>
35  * <tr><td><code>1</code></td><td>UpperBodyBoneSet</td><td>Only the "Spine" joint and its children.</td></tr>
36  * <tr><td><code>2</code></td><td>LowerBodyBoneSet</td><td>Only the leg joints and their children.</td></tr>
37  * <tr><td><code>3</code></td><td>LeftArmBoneSet</td><td>Joints that are the children of the "LeftShoulder"
38  * joint.</td></tr>
39  * <tr><td><code>4</code></td><td>RightArmBoneSet</td><td>Joints that are the children of the "RightShoulder"
40  * joint.</td></tr>
41  * <tr><td><code>5</code></td><td>AboveTheHeadBoneSet</td><td>Joints that are the children of the "Head"
42  * joint.</td></tr>
43  * <tr><td><code>6</code></td><td>BelowTheHeadBoneSet</td><td>Joints that are NOT the children of the "head"
44  * joint.</td></tr>
45  * <tr><td><code>7</code></td><td>HeadOnlyBoneSet</td><td>The "Head" joint.</td></tr>
46  * <tr><td><code>8</code></td><td>SpineOnlyBoneSet</td><td>The "Spine" joint.</td></tr>
47  * <tr><td><code>9</code></td><td>EmptyBoneSet</td><td>No joints.</td></tr>
48  * <tr><td><code>10</code></td><td>LeftHandBoneSet</td><td>joints that are the children of the "LeftHand"
49  * joint.</td></tr>
50  * <tr><td><code>11</code></td><td>RightHandBoneSet</td><td>Joints that are the children of the "RightHand"
51  * joint.</td></tr>
52  * <tr><td><code>12</code></td><td>HipsOnlyBoneSet</td><td>The "Hips" joint.</td></tr>
53  * <tr><td><code>13</code></td><td>BothFeetBoneSet</td><td>The "LeftFoot" and "RightFoot" joints.</td></tr>
54  * </tbody>
55  * </table>
56  * @typedef {number} MyAvatar.AnimOverlayBoneSet
57  */
58  enum BoneSet {
59  FullBodyBoneSet = 0,
60  UpperBodyBoneSet,
61  LowerBodyBoneSet,
62  LeftArmBoneSet,
63  RightArmBoneSet,
64  AboveTheHeadBoneSet,
65  BelowTheHeadBoneSet,
66  HeadOnlyBoneSet,
67  SpineOnlyBoneSet,
68  EmptyBoneSet,
69  LeftHandBoneSet,
70  RightHandBoneSet,
71  HipsOnlyBoneSet,
72  BothFeetBoneSet,
73  NumBoneSets
74  };
75 
76  AnimOverlay(const QString& id, BoneSet boneSet, float alpha);
77  virtual ~AnimOverlay() override;
78 
79  virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, const AnimContext& context, float dt, AnimVariantMap& triggersOut) override;
80 
81  void setBoneSetVar(const QString& boneSetVar) { _boneSetVar = boneSetVar; }
82  void setAlphaVar(const QString& alphaVar) { _alphaVar = alphaVar; }
83 
84  protected:
85  void buildBoneSet(BoneSet boneSet);
86 
87  // for AnimDebugDraw rendering
88  virtual const AnimPoseVec& getPosesInternal() const override;
89  virtual void setSkeletonInternal(AnimSkeleton::ConstPointer skeleton) override;
90 
91  AnimPoseVec _poses;
92  BoneSet _boneSet;
93  float _alpha;
94  std::vector<float> _boneSetVec;
95 
96  QString _boneSetVar;
97  QString _alphaVar;
98 
99  void buildFullBodyBoneSet();
100  void buildUpperBodyBoneSet();
101  void buildLowerBodyBoneSet();
102  void buildLeftArmBoneSet();
103  void buildRightArmBoneSet();
104  void buildAboveTheHeadBoneSet();
105  void buildBelowTheHeadBoneSet();
106  void buildHeadOnlyBoneSet();
107  void buildSpineOnlyBoneSet();
108  void buildEmptyBoneSet();
109  void buildLeftHandBoneSet();
110  void buildRightHandBoneSet();
111  void buildHipsOnlyBoneSet();
112  void buildBothFeetBoneSet();
113 
114  // no copies
115  AnimOverlay(const AnimOverlay&) = delete;
116  AnimOverlay& operator=(const AnimOverlay&) = delete;
117 };
118 
119 #endif // hifi_AnimOverlay_h