mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 16:04:56 +02:00
Add new MyAvatar.getAvatarEntityData() implementation for API
This commit is contained in:
parent
9144e78cb9
commit
c7f82a8264
7 changed files with 58 additions and 5 deletions
|
@ -173,7 +173,7 @@ public:
|
||||||
* Gets details of all avatar entities.
|
* Gets details of all avatar entities.
|
||||||
* <p><strong>Warning:</strong> Potentially an expensive call. Do not use if possible.</p>
|
* <p><strong>Warning:</strong> Potentially an expensive call. Do not use if possible.</p>
|
||||||
* @function Avatar.getAvatarEntityData
|
* @function Avatar.getAvatarEntityData
|
||||||
* @returns {AvatarEntityMap} Details of the avatar entities.
|
* @returns {AvatarEntityMap} Details of all avatar entities.
|
||||||
* @example <caption>Report the current avatar entities.</caption>
|
* @example <caption>Report the current avatar entities.</caption>
|
||||||
* var avatarEntityData = Avatar.getAvatarEntityData();
|
* var avatarEntityData = Avatar.getAvatarEntityData();
|
||||||
* print("Avatar entities: " + JSON.stringify(avatarEntityData));
|
* print("Avatar entities: " + JSON.stringify(avatarEntityData));
|
||||||
|
|
|
@ -1810,6 +1810,46 @@ void MyAvatar::prepareAvatarEntityDataForReload() {
|
||||||
_reloadAvatarEntityDataFromSettings = true;
|
_reloadAvatarEntityDataFromSettings = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AvatarEntityMap MyAvatar::getAvatarEntityData() const {
|
||||||
|
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
||||||
|
AvatarEntityMap data;
|
||||||
|
|
||||||
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
|
if (!entityTree) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QUuid> avatarEntityIDs;
|
||||||
|
_avatarEntitiesLock.withReadLock([&] {
|
||||||
|
avatarEntityIDs = _packedAvatarEntityData.keys();
|
||||||
|
});
|
||||||
|
for (const auto& entityID : avatarEntityIDs) {
|
||||||
|
auto entity = entityTree->findEntityByID(entityID);
|
||||||
|
if (!entity) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
EncodeBitstreamParams params;
|
||||||
|
auto desiredProperties = entity->getEntityProperties(params);
|
||||||
|
desiredProperties += PROP_LOCAL_POSITION;
|
||||||
|
desiredProperties += PROP_LOCAL_ROTATION;
|
||||||
|
desiredProperties += PROP_LOCAL_VELOCITY;
|
||||||
|
desiredProperties += PROP_LOCAL_ANGULAR_VELOCITY;
|
||||||
|
desiredProperties += PROP_LOCAL_DIMENSIONS;
|
||||||
|
EntityItemProperties properties = entity->getProperties(desiredProperties);
|
||||||
|
|
||||||
|
QByteArray blob;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(_scriptEngineLock);
|
||||||
|
EntityItemProperties::propertiesToBlob(*_scriptEngine, getID(), properties, blob, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
data[entityID] = blob;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
AvatarEntityMap MyAvatar::getAvatarEntityDataNonDefault() const {
|
AvatarEntityMap MyAvatar::getAvatarEntityDataNonDefault() const {
|
||||||
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
||||||
updateStaleAvatarEntityBlobs();
|
updateStaleAvatarEntityBlobs();
|
||||||
|
|
|
@ -1856,11 +1856,12 @@ public:
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Gets details of all avatar entities.
|
* Gets details of all avatar entities.
|
||||||
* @function MyAvatar.getAvatarEntityData
|
* @function MyAvatar.getAvatarEntityData
|
||||||
* @returns {AvatarEntityMap} Details of the avatar entities.
|
* @returns {AvatarEntityMap} Details of all avatar entities.
|
||||||
* @example <caption>Report the current avatar entities.</caption>
|
* @example <caption>Report the current avatar entities.</caption>
|
||||||
* var avatarEntityData = MyAvatar.getAvatarEntityData();
|
* var avatarEntityData = MyAvatar.getAvatarEntityData();
|
||||||
* print("Avatar entities: " + JSON.stringify(avatarEntityData));
|
* print("Avatar entities: " + JSON.stringify(avatarEntityData));
|
||||||
*/
|
*/
|
||||||
|
AvatarEntityMap getAvatarEntityData() const override;
|
||||||
|
|
||||||
AvatarEntityMap getAvatarEntityDataNonDefault() const override;
|
AvatarEntityMap getAvatarEntityDataNonDefault() const override;
|
||||||
|
|
||||||
|
|
|
@ -3046,6 +3046,12 @@ void AvatarData::clearAvatarEntity(const QUuid& entityID, bool requiresRemovalFr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AvatarEntityMap AvatarData::getAvatarEntityData() const {
|
||||||
|
// overridden where needed
|
||||||
|
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
||||||
|
return AvatarEntityMap();
|
||||||
|
}
|
||||||
|
|
||||||
AvatarEntityMap AvatarData::getAvatarEntityDataNonDefault() const {
|
AvatarEntityMap AvatarData::getAvatarEntityDataNonDefault() const {
|
||||||
// overridden where needed
|
// overridden where needed
|
||||||
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
||||||
|
|
|
@ -1390,6 +1390,8 @@ public:
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @comment Documented in derived classes' JSDoc because implementations are different.
|
* @comment Documented in derived classes' JSDoc because implementations are different.
|
||||||
*/
|
*/
|
||||||
|
// Get avatar entity data with all property values. Used in API.
|
||||||
|
Q_INVOKABLE virtual AvatarEntityMap getAvatarEntityData() const;
|
||||||
|
|
||||||
// Get avatar entity data with non-default property values. Used internally.
|
// Get avatar entity data with non-default property values. Used internally.
|
||||||
virtual AvatarEntityMap getAvatarEntityDataNonDefault() const;
|
virtual AvatarEntityMap getAvatarEntityDataNonDefault() const;
|
||||||
|
|
|
@ -5097,10 +5097,13 @@ bool EntityItemProperties::blobToProperties(QScriptEngine& scriptEngine, const Q
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItemProperties::propertiesToBlob(QScriptEngine& scriptEngine, const QUuid& myAvatarID, const EntityItemProperties& properties, QByteArray& blob) {
|
void EntityItemProperties::propertiesToBlob(QScriptEngine& scriptEngine, const QUuid& myAvatarID,
|
||||||
|
const EntityItemProperties& properties, QByteArray& blob, bool allProperties) {
|
||||||
// DANGER: this method is NOT efficient.
|
// DANGER: this method is NOT efficient.
|
||||||
// begin recipe for extracting unfortunately-formatted-binary-blob from EntityItem
|
// begin recipe for extracting unfortunately-formatted-binary-blob from EntityItem
|
||||||
QScriptValue scriptValue = EntityItemNonDefaultPropertiesToScriptValue(&scriptEngine, properties);
|
QScriptValue scriptValue = allProperties
|
||||||
|
? EntityItemPropertiesToScriptValue(&scriptEngine, properties)
|
||||||
|
: EntityItemNonDefaultPropertiesToScriptValue(&scriptEngine, properties);
|
||||||
QVariant variantProperties = scriptValue.toVariant();
|
QVariant variantProperties = scriptValue.toVariant();
|
||||||
QJsonDocument jsonProperties = QJsonDocument::fromVariant(variantProperties);
|
QJsonDocument jsonProperties = QJsonDocument::fromVariant(variantProperties);
|
||||||
// the ID of the parent/avatar changes from session to session. use a special UUID to indicate the avatar
|
// the ID of the parent/avatar changes from session to session. use a special UUID to indicate the avatar
|
||||||
|
|
|
@ -118,7 +118,8 @@ class EntityItemProperties {
|
||||||
friend class MaterialEntityItem;
|
friend class MaterialEntityItem;
|
||||||
public:
|
public:
|
||||||
static bool blobToProperties(QScriptEngine& scriptEngine, const QByteArray& blob, EntityItemProperties& properties);
|
static bool blobToProperties(QScriptEngine& scriptEngine, const QByteArray& blob, EntityItemProperties& properties);
|
||||||
static void propertiesToBlob(QScriptEngine& scriptEngine, const QUuid& myAvatarID, const EntityItemProperties& properties, QByteArray& blob);
|
static void propertiesToBlob(QScriptEngine& scriptEngine, const QUuid& myAvatarID, const EntityItemProperties& properties,
|
||||||
|
QByteArray& blob, bool allProperties = false);
|
||||||
|
|
||||||
EntityItemProperties(EntityPropertyFlags desiredProperties = EntityPropertyFlags());
|
EntityItemProperties(EntityPropertyFlags desiredProperties = EntityPropertyFlags());
|
||||||
virtual ~EntityItemProperties() = default;
|
virtual ~EntityItemProperties() = default;
|
||||||
|
|
Loading…
Reference in a new issue