Overte C++ Documentation
ScriptAvatarData.h
1 //
2 // ScriptAvatarData.h
3 // libraries/script-engine/src
4 //
5 // Created by Zach Fox on 2017-04-10.
6 // Copyright 2017 High Fidelity, Inc.
7 // Copyright 2021 Vircadia contributors.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_ScriptAvatarData_h
14 #define hifi_ScriptAvatarData_h
15 
16 #include <QtCore/QObject>
17 
18 #include "AvatarData.h"
19 
20 class ScriptAvatarData : public QObject {
21  Q_OBJECT
22 
23  //
24  // PHYSICAL PROPERTIES: POSITION AND ORIENTATION
25  //
26  Q_PROPERTY(glm::vec3 position READ getPosition)
27  Q_PROPERTY(float scale READ getTargetScale)
28  Q_PROPERTY(glm::vec3 handPosition READ getHandPosition)
29  Q_PROPERTY(float bodyPitch READ getBodyPitch)
30  Q_PROPERTY(float bodyYaw READ getBodyYaw)
31  Q_PROPERTY(float bodyRoll READ getBodyRoll)
32  Q_PROPERTY(glm::quat orientation READ getOrientation)
33  Q_PROPERTY(glm::quat headOrientation READ getHeadOrientation)
34  Q_PROPERTY(float headPitch READ getHeadPitch)
35  Q_PROPERTY(float headYaw READ getHeadYaw)
36  Q_PROPERTY(float headRoll READ getHeadRoll)
37  //
38  // PHYSICAL PROPERTIES: VELOCITY
39  //
40  Q_PROPERTY(glm::vec3 velocity READ getVelocity)
41  Q_PROPERTY(glm::vec3 angularVelocity READ getAngularVelocity)
42 
43  //
44  // IDENTIFIER PROPERTIES
45  //
46  Q_PROPERTY(QUuid sessionUUID READ getSessionUUID)
47  Q_PROPERTY(QString displayName READ getDisplayName NOTIFY displayNameChanged)
48  Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName NOTIFY sessionDisplayNameChanged)
49  Q_PROPERTY(bool isReplicated READ getIsReplicated)
50  Q_PROPERTY(bool lookAtSnappingEnabled READ getLookAtSnappingEnabled NOTIFY lookAtSnappingChanged)
51 
52  //
53  // JOINT PROPERTIES
54  //
55  Q_PROPERTY(QString skeletonModelURL READ getSkeletonModelURLFromScript NOTIFY skeletonModelURLChanged)
56  Q_PROPERTY(QStringList jointNames READ getJointNames)
57 
58  //
59  // AUDIO PROPERTIES
60  //
61  Q_PROPERTY(float audioLoudness READ getAudioLoudness)
62  Q_PROPERTY(float audioAverageLoudness READ getAudioAverageLoudness)
63 
64  //
65  // MATRIX PROPERTIES
66  //
67  Q_PROPERTY(glm::mat4 sensorToWorldMatrix READ getSensorToWorldMatrix)
68  Q_PROPERTY(glm::mat4 controllerLeftHandMatrix READ getControllerLeftHandMatrix)
69  Q_PROPERTY(glm::mat4 controllerRightHandMatrix READ getControllerRightHandMatrix)
70 
71  Q_PROPERTY(bool hasPriority READ getHasPriority)
72 
73 public:
74  ScriptAvatarData(AvatarSharedPointer avatarData);
75 
76  //
77  // PHYSICAL PROPERTIES: POSITION AND ORIENTATION
78  //
79  glm::vec3 getPosition() const;
80  float getTargetScale() const;
81  glm::vec3 getHandPosition() const;
82  float getBodyPitch() const;
83  float getBodyYaw() const;
84  float getBodyRoll() const;
85  glm::quat getOrientation() const;
86  glm::quat getHeadOrientation() const;
87  float getHeadPitch() const;
88  float getHeadYaw() const;
89  float getHeadRoll() const;
90  //
91  // PHYSICAL PROPERTIES: VELOCITY
92  //
93  glm::vec3 getVelocity() const;
94  glm::vec3 getAngularVelocity() const;
95 
96  //
97  // IDENTIFIER PROPERTIES
98  //
99  QUuid getSessionUUID() const;
100  QString getDisplayName() const;
101  QString getSessionDisplayName() const;
102  bool getIsReplicated() const;
103  bool getLookAtSnappingEnabled() const;
104 
105  //
106  // JOINT PROPERTIES
107  //
108  QString getSkeletonModelURLFromScript() const;
109 
110  /*@jsdoc
111  * Gets the pointing state of the hands to control where the laser emanates from. If the right index finger is pointing, the
112  * laser emanates from the tip of that finger, otherwise it emanates from the palm.
113  * @function ScriptAvatar.getHandState
114  * @returns {HandState|number} The pointing state of the hand, or <code>-1</code> if the avatar data aren't available.
115  */
116  Q_INVOKABLE char getHandState() const;
117 
118  /*@jsdoc
119  * Gets the rotation of a joint relative to its parent. For information on the joint hierarchy used, see
120  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.
121  * @function ScriptAvatar.getJointRotation
122  * @param {number} index - The index of the joint.
123  * @returns {Quat} The rotation of the joint relative to its parent, or {@link Quat(0)|Quat.IDENTITY} if the avatar data
124  * aren't available.
125  */
126  Q_INVOKABLE glm::quat getJointRotation(int index) const;
127 
128  /*@jsdoc
129  * Gets the translation of a joint relative to its parent, in model coordinates.
130  * <p><strong>Warning:</strong> These coordinates are not necessarily in meters.</p>
131  * <p>For information on the joint hierarchy used, see
132  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.</p>
133  * @function ScriptAvatar.getJointTranslation
134  * @param {number} index - The index of the joint.
135  * @returns {Vec3} The translation of the joint relative to its parent, in model coordinates, or {@link Vec3(0)|Vec3.ZERO}
136  * if the avatar data aren't available.
137  */
138  Q_INVOKABLE glm::vec3 getJointTranslation(int index) const;
139 
140  /*@jsdoc
141  * Gets the rotation of a joint relative to its parent. For information on the joint hierarchy used, see
142  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.
143  * @function ScriptAvatar.getJointRotation
144  * @param {string} name - The name of the joint.
145  * @returns {Quat} The rotation of the joint relative to its parent, or {@link Quat(0)|Quat.IDENTITY} if the avatar data
146  * aren't available.
147  */
148  Q_INVOKABLE glm::quat getJointRotation(const QString& name) const;
149 
150  /*@jsdoc
151  * Gets the translation of a joint relative to its parent, in model coordinates.
152  * <p><strong>Warning:</strong> These coordinates are not necessarily in meters.</p>
153  * <p>For information on the joint hierarchy used, see
154  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.</p>
155  * @function ScriptAvatar.getJointTranslation
156  * @param {number} name - The name of the joint.
157  * @returns {Vec3} The translation of the joint relative to its parent, in model coordinates, or {@link Vec3(0)|Vec3.ZERO}
158  * if the avatar data aren't available.
159  */
160  Q_INVOKABLE glm::vec3 getJointTranslation(const QString& name) const;
161 
162  /*@jsdoc
163  * Gets the rotations of all joints in the avatar. Each joint's rotation is relative to its parent joint.
164  * @function ScriptAvatar.getJointRotations
165  * @returns {Quat[]} The rotations of all joints relative to each's parent, or <code>[]</code> if the avatar data aren't
166  * available. The values are in the same order as the array returned by {@link ScriptAvatar.getJointNames}.
167  */
168  Q_INVOKABLE QVector<glm::quat> getJointRotations() const;
169 
170  /*@jsdoc
171  * Gets the translations of all joints in the avatar. Each joint's translation is relative to its parent joint, in
172  * model coordinates.
173  * <p><strong>Warning:</strong> These coordinates are not necessarily in meters.</p>
174  * @function ScriptAvatar.getJointTranslations
175  * @returns {Vec3[]} The translations of all joints relative to each's parent, in model coordinates, or <code>[]</code> if
176  * the avatar data aren't available. The values are in the same order as the array returned by
177  * {@link ScriptAvatar.getJointNames}.
178  */
179  Q_INVOKABLE QVector<glm::vec3> getJointTranslations() const;
180 
181  /*@jsdoc
182  * Checks that the data for a joint are valid.
183  * @function ScriptAvatar.isJointDataValid
184  * @param {number} index - The index of the joint.
185  * @returns {boolean} <code>true</code> if the joint data are valid, <code>false</code> if not or the avatar data aren't
186  * available.
187  */
188  Q_INVOKABLE bool isJointDataValid(const QString& name) const;
189 
190  /*@jsdoc
191  * Gets the joint index for a named joint. The joint index value is the position of the joint in the array returned by
192  * {@linkScriptAvatar.getJointNames}.
193  * @function ScriptAvatar.getJointIndex
194  * @param {string} name - The name of the joint.
195  * @returns {number} The index of the joint if valid and avatar data are available, otherwise <code>-1</code>.
196  */
197  Q_INVOKABLE int getJointIndex(const QString& name) const;
198 
199  /*@jsdoc
200  * Gets the names of all the joints in the avatar.
201  * @function ScriptAvatar.getJointNames
202  * @returns {string[]} The joint names, or <code>[]</code> if the avatar data aren't available.
203  */
204  Q_INVOKABLE QStringList getJointNames() const;
205 
206 #if DEV_BUILD || PR_BUILD
207  Q_INVOKABLE AvatarEntityMap getAvatarEntities() const;
208 #endif
209 
210  //
211  // AUDIO PROPERTIES
212  //
213  float getAudioLoudness() const;
214  float getAudioAverageLoudness() const;
215 
216  //
217  // MATRIX PROPERTIES
218  //
219  glm::mat4 getSensorToWorldMatrix() const;
220  glm::mat4 getControllerLeftHandMatrix() const;
221  glm::mat4 getControllerRightHandMatrix() const;
222 
223  bool getHasPriority() const;
224 
225 signals:
226 
227  /*@jsdoc
228  * Triggered when the avatar's <code>displayName</code> property value changes.
229  * @function ScriptAvatar.displayNameChanged
230  * @returns {Signal}
231  */
232  void displayNameChanged();
233 
234  /*@jsdoc
235  * Triggered when the avatar's <code>sessionDisplayName</code> property value changes.
236  * @function ScriptAvatar.sessionDisplayNameChanged
237  * @returns {Signal}
238  */
239  void sessionDisplayNameChanged();
240 
241  /*@jsdoc
242  * Triggered when the avatar's model (i.e., <code>skeletonModelURL</code> property value) changes.
243  * @function ScriptAvatar.skeletonModelURLChanged
244  * @returns {Signal}
245  */
246  void skeletonModelURLChanged();
247 
248  /*@jsdoc
249  * Triggered when the avatar's <code>lookAtSnappingEnabled</code> property value changes.
250  * @function ScriptAvatar.lookAtSnappingChanged
251  * @param {boolean} enabled - <code>true</code> if look-at snapping is enabled, <code>false</code> if not.
252  * @returns {Signal}
253  */
254  void lookAtSnappingChanged(bool enabled);
255 
256 public slots:
257 
258  /*@jsdoc
259  * Gets the rotation of a joint relative to the avatar.
260  * @function ScriptAvatar.getAbsoluteJointRotationInObjectFrame
261  * @param {number} index - The index of the joint.
262  * @returns {Quat} The rotation of the joint relative to the avatar, or {@link Quat(0)|Quat.IDENTITY} if the avatar data
263  * aren't available.
264  */
265  glm::quat getAbsoluteJointRotationInObjectFrame(int index) const;
266 
267  /*@jsdoc
268  * Gets the translation of a joint relative to the avatar.
269  * @function ScriptAvatar.getAbsoluteJointTranslationInObjectFrame
270  * @param {number} index - The index of the joint.
271  * @returns {Vec3} The translation of the joint relative to the avatar, or {@link Vec3(0)|Vec3.ZERO} if the avatar data
272  * aren't available.
273  */
274  glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const;
275 
276 protected:
277  std::weak_ptr<AvatarData> _avatarData;
278 };
279 
280 #endif // hifi_ScriptAvatarData_h