From 22901a40c80d299775f8265663cdc9c2aeb6af74 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 30 Mar 2017 17:27:40 -0700 Subject: [PATCH] Expose Avatar skeletons to JavaScript --- interface/src/avatar/Avatar.cpp | 24 ++++++++++++++++++++++++ interface/src/avatar/Avatar.h | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 626719b42e..ade98c63d8 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -1395,6 +1395,30 @@ void Avatar::setParentJointIndex(quint16 parentJointIndex) { } } +QList Avatar::getSkeleton() { + SkeletonModelPointer skeletonModel = _skeletonModel; + if (skeletonModel) { + RigPointer rig = skeletonModel->getRig(); + if (rig) { + AnimSkeleton::ConstPointer skeleton = rig->getAnimSkeleton(); + if (skeleton) { + QList list; + list.reserve(skeleton->getNumJoints()); + for (int i = 0; i < skeleton->getNumJoints(); i++) { + QVariantMap obj; + obj["name"] = skeleton->getJointName(i); + obj["index"] = i; + obj["parentIndex"] = skeleton->getParentIndex(i); + list.push_back(obj); + } + return list; + } + } + } + + return QList(); +} + void Avatar::addToScene(AvatarSharedPointer myHandle) { render::ScenePointer scene = qApp->getMain3DScene(); if (scene) { diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index d4bd03367e..ba7e1c617e 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -55,6 +55,16 @@ class Texture; class Avatar : public AvatarData { Q_OBJECT + + /**jsdoc + * An avatar is representation of yourself or another user. The Avatar API can be used to query or manipulate the avatar of a user. + * NOTE: Avatar extends AvatarData, see those namespace for more properties/methods. + * + * @namespace Avatar + * @augments AvatarData + * + * @property skeletonOffset {Vec3} can be used to apply a translation offset between the avatar's position and the registration point of the 3d model. + */ Q_PROPERTY(glm::vec3 skeletonOffset READ getSkeletonOffset WRITE setSkeletonOffset) public: @@ -169,6 +179,21 @@ public: Q_INVOKABLE virtual quint16 getParentJointIndex() const override { return SpatiallyNestable::getParentJointIndex(); } Q_INVOKABLE virtual void setParentJointIndex(quint16 parentJointIndex) override; + /**jsdoc + * Information about a single joint in an Avatar's skeleton hierarchy. + * @typedef Avatar.SkeletonJoint + * @property {string} name - name of joint + * @property {number} index - joint index + * @property {number} parentIndex - index of this joint's parent (-1 if no parent) + */ + + /**jsdoc + * Returns an array of joints, where each joint is an object containing name, index and parentIndex fields. + * @function Avatar.getSkeleton + * @returns {Avatar.SkeletonJoint[]} returns a list of information about each joint in this avatar's skeleton. + */ + Q_INVOKABLE QList getSkeleton(); + // NOT thread safe, must be called on main thread. glm::vec3 getUncachedLeftPalmPosition() const; glm::quat getUncachedLeftPalmRotation() const;