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  // ATTACHMENT AND JOINT PROPERTIES
54  //
55  Q_PROPERTY(QString skeletonModelURL READ getSkeletonModelURLFromScript NOTIFY skeletonModelURLChanged)
56  Q_PROPERTY(QVector<AttachmentData> attachmentData READ getAttachmentData)
57  Q_PROPERTY(QStringList jointNames READ getJointNames)
58 
59  //
60  // AUDIO PROPERTIES
61  //
62  Q_PROPERTY(float audioLoudness READ getAudioLoudness)
63  Q_PROPERTY(float audioAverageLoudness READ getAudioAverageLoudness)
64 
65  //
66  // MATRIX PROPERTIES
67  //
68  Q_PROPERTY(glm::mat4 sensorToWorldMatrix READ getSensorToWorldMatrix)
69  Q_PROPERTY(glm::mat4 controllerLeftHandMatrix READ getControllerLeftHandMatrix)
70  Q_PROPERTY(glm::mat4 controllerRightHandMatrix READ getControllerRightHandMatrix)
71 
72  Q_PROPERTY(bool hasPriority READ getHasPriority)
73 
74 public:
75  ScriptAvatarData(AvatarSharedPointer avatarData);
76 
77  //
78  // PHYSICAL PROPERTIES: POSITION AND ORIENTATION
79  //
80  glm::vec3 getPosition() const;
81  float getTargetScale() const;
82  glm::vec3 getHandPosition() const;
83  float getBodyPitch() const;
84  float getBodyYaw() const;
85  float getBodyRoll() const;
86  glm::quat getOrientation() const;
87  glm::quat getHeadOrientation() const;
88  float getHeadPitch() const;
89  float getHeadYaw() const;
90  float getHeadRoll() const;
91  //
92  // PHYSICAL PROPERTIES: VELOCITY
93  //
94  glm::vec3 getVelocity() const;
95  glm::vec3 getAngularVelocity() const;
96 
97  //
98  // IDENTIFIER PROPERTIES
99  //
100  QUuid getSessionUUID() const;
101  QString getDisplayName() const;
102  QString getSessionDisplayName() const;
103  bool getIsReplicated() const;
104  bool getLookAtSnappingEnabled() const;
105 
106  //
107  // ATTACHMENT AND JOINT PROPERTIES
108  //
109  QString getSkeletonModelURLFromScript() const;
110 
111  /*@jsdoc
112  * Gets the pointing state of the hands to control where the laser emanates from. If the right index finger is pointing, the
113  * laser emanates from the tip of that finger, otherwise it emanates from the palm.
114  * @function ScriptAvatar.getHandState
115  * @returns {HandState|number} The pointing state of the hand, or <code>-1</code> if the avatar data aren't available.
116  */
117  Q_INVOKABLE char getHandState() const;
118 
119  /*@jsdoc
120  * Gets the rotation of a joint relative to its parent. For information on the joint hierarchy used, see
121  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.
122  * @function ScriptAvatar.getJointRotation
123  * @param {number} index - The index of the joint.
124  * @returns {Quat} The rotation of the joint relative to its parent, or {@link Quat(0)|Quat.IDENTITY} if the avatar data
125  * aren't available.
126  */
127  Q_INVOKABLE glm::quat getJointRotation(int index) const;
128 
129  /*@jsdoc
130  * Gets the translation of a joint relative to its parent, in model coordinates.
131  * <p><strong>Warning:</strong> These coordinates are not necessarily in meters.</p>
132  * <p>For information on the joint hierarchy used, see
133  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.</p>
134  * @function ScriptAvatar.getJointTranslation
135  * @param {number} index - The index of the joint.
136  * @returns {Vec3} The translation of the joint relative to its parent, in model coordinates, or {@link Vec3(0)|Vec3.ZERO}
137  * if the avatar data aren't available.
138  */
139  Q_INVOKABLE glm::vec3 getJointTranslation(int index) const;
140 
141  /*@jsdoc
142  * Gets the rotation of a joint relative to its parent. For information on the joint hierarchy used, see
143  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.
144  * @function ScriptAvatar.getJointRotation
145  * @param {string} name - The name of the joint.
146  * @returns {Quat} The rotation of the joint relative to its parent, or {@link Quat(0)|Quat.IDENTITY} if the avatar data
147  * aren't available.
148  */
149  Q_INVOKABLE glm::quat getJointRotation(const QString& name) const;
150 
151  /*@jsdoc
152  * Gets the translation of a joint relative to its parent, in model coordinates.
153  * <p><strong>Warning:</strong> These coordinates are not necessarily in meters.</p>
154  * <p>For information on the joint hierarchy used, see
155  * <a href="https://docs.overte.org/create/avatars/avatar-standards.html">Avatar Standards</a>.</p>
156  * @function ScriptAvatar.getJointTranslation
157  * @param {number} name - The name of the joint.
158  * @returns {Vec3} The translation of the joint relative to its parent, in model coordinates, or {@link Vec3(0)|Vec3.ZERO}
159  * if the avatar data aren't available.
160  */
161  Q_INVOKABLE glm::vec3 getJointTranslation(const QString& name) const;
162 
163  /*@jsdoc
164  * Gets the rotations of all joints in the avatar. Each joint's rotation is relative to its parent joint.
165  * @function ScriptAvatar.getJointRotations
166  * @returns {Quat[]} The rotations of all joints relative to each's parent, or <code>[]</code> if the avatar data aren't
167  * available. The values are in the same order as the array returned by {@link ScriptAvatar.getJointNames}.
168  */
169  Q_INVOKABLE QVector<glm::quat> getJointRotations() const;
170 
171  /*@jsdoc
172  * Gets the translations of all joints in the avatar. Each joint's translation is relative to its parent joint, in
173  * model coordinates.
174  * <p><strong>Warning:</strong> These coordinates are not necessarily in meters.</p>
175  * @function ScriptAvatar.getJointTranslations
176  * @returns {Vec3[]} The translations of all joints relative to each's parent, in model coordinates, or <code>[]</code> if
177  * the avatar data aren't available. The values are in the same order as the array returned by
178  * {@link ScriptAvatar.getJointNames}.
179  */
180  Q_INVOKABLE QVector<glm::vec3> getJointTranslations() const;
181 
182  /*@jsdoc
183  * Checks that the data for a joint are valid.
184  * @function ScriptAvatar.isJointDataValid
185  * @param {number} index - The index of the joint.
186  * @returns {boolean} <code>true</code> if the joint data are valid, <code>false</code> if not or the avatar data aren't
187  * available.
188  */
189  Q_INVOKABLE bool isJointDataValid(const QString& name) const;
190 
191  /*@jsdoc
192  * Gets the joint index for a named joint. The joint index value is the position of the joint in the array returned by
193  * {@linkScriptAvatar.getJointNames}.
194  * @function ScriptAvatar.getJointIndex
195  * @param {string} name - The name of the joint.
196  * @returns {number} The index of the joint if valid and avatar data are available, otherwise <code>-1</code>.
197  */
198  Q_INVOKABLE int getJointIndex(const QString& name) const;
199 
200  /*@jsdoc
201  * Gets the names of all the joints in the avatar.
202  * @function ScriptAvatar.getJointNames
203  * @returns {string[]} The joint names, or <code>[]</code> if the avatar data aren't available.
204  */
205  Q_INVOKABLE QStringList getJointNames() const;
206 
207  /*@jsdoc
208  * Gets information about the models currently attached to the avatar.
209  * @function ScriptAvatar.getAttachmentData
210  * @returns {AttachmentData[]} Information about all models attached to the avatar, or <code>[]</code> if the avatar data
211  * aren't available.
212  * @deprecated This function is deprecated and will be removed. Use avatar entities instead.
213  */
214  Q_INVOKABLE QVector<AttachmentData> getAttachmentData() const;
215 
216 #if DEV_BUILD || PR_BUILD
217  Q_INVOKABLE AvatarEntityMap getAvatarEntities() const;
218 #endif
219 
220  //
221  // AUDIO PROPERTIES
222  //
223  float getAudioLoudness() const;
224  float getAudioAverageLoudness() const;
225 
226  //
227  // MATRIX PROPERTIES
228  //
229  glm::mat4 getSensorToWorldMatrix() const;
230  glm::mat4 getControllerLeftHandMatrix() const;
231  glm::mat4 getControllerRightHandMatrix() const;
232 
233  bool getHasPriority() const;
234 
235 signals:
236 
237  /*@jsdoc
238  * Triggered when the avatar's <code>displayName</code> property value changes.
239  * @function ScriptAvatar.displayNameChanged
240  * @returns {Signal}
241  */
242  void displayNameChanged();
243 
244  /*@jsdoc
245  * Triggered when the avatar's <code>sessionDisplayName</code> property value changes.
246  * @function ScriptAvatar.sessionDisplayNameChanged
247  * @returns {Signal}
248  */
249  void sessionDisplayNameChanged();
250 
251  /*@jsdoc
252  * Triggered when the avatar's model (i.e., <code>skeletonModelURL</code> property value) changes.
253  * @function ScriptAvatar.skeletonModelURLChanged
254  * @returns {Signal}
255  */
256  void skeletonModelURLChanged();
257 
258  /*@jsdoc
259  * Triggered when the avatar's <code>lookAtSnappingEnabled</code> property value changes.
260  * @function ScriptAvatar.lookAtSnappingChanged
261  * @param {boolean} enabled - <code>true</code> if look-at snapping is enabled, <code>false</code> if not.
262  * @returns {Signal}
263  */
264  void lookAtSnappingChanged(bool enabled);
265 
266 public slots:
267 
268  /*@jsdoc
269  * Gets the rotation of a joint relative to the avatar.
270  * @function ScriptAvatar.getAbsoluteJointRotationInObjectFrame
271  * @param {number} index - The index of the joint.
272  * @returns {Quat} The rotation of the joint relative to the avatar, or {@link Quat(0)|Quat.IDENTITY} if the avatar data
273  * aren't available.
274  */
275  glm::quat getAbsoluteJointRotationInObjectFrame(int index) const;
276 
277  /*@jsdoc
278  * Gets the translation of a joint relative to the avatar.
279  * @function ScriptAvatar.getAbsoluteJointTranslationInObjectFrame
280  * @param {number} index - The index of the joint.
281  * @returns {Vec3} The translation of the joint relative to the avatar, or {@link Vec3(0)|Vec3.ZERO} if the avatar data
282  * aren't available.
283  */
284  glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const;
285 
286 protected:
287  std::weak_ptr<AvatarData> _avatarData;
288 };
289 
290 #endif // hifi_ScriptAvatarData_h