mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-08 06:32:35 +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.
|
||||
* <p><strong>Warning:</strong> Potentially an expensive call. Do not use if possible.</p>
|
||||
* @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>
|
||||
* var avatarEntityData = Avatar.getAvatarEntityData();
|
||||
* print("Avatar entities: " + JSON.stringify(avatarEntityData));
|
||||
|
|
|
@ -1810,6 +1810,46 @@ void MyAvatar::prepareAvatarEntityDataForReload() {
|
|||
_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 {
|
||||
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
||||
updateStaleAvatarEntityBlobs();
|
||||
|
|
|
@ -1856,11 +1856,12 @@ public:
|
|||
/**jsdoc
|
||||
* Gets details of all avatar entities.
|
||||
* @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>
|
||||
* var avatarEntityData = MyAvatar.getAvatarEntityData();
|
||||
* print("Avatar entities: " + JSON.stringify(avatarEntityData));
|
||||
*/
|
||||
AvatarEntityMap getAvatarEntityData() 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 {
|
||||
// overridden where needed
|
||||
// NOTE: the return value is expected to be a map of unfortunately-formatted-binary-blobs
|
||||
|
|
|
@ -1390,6 +1390,8 @@ public:
|
|||
/**jsdoc
|
||||
* @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.
|
||||
virtual AvatarEntityMap getAvatarEntityDataNonDefault() const;
|
||||
|
|
|
@ -5097,10 +5097,13 @@ bool EntityItemProperties::blobToProperties(QScriptEngine& scriptEngine, const Q
|
|||
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.
|
||||
// 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();
|
||||
QJsonDocument jsonProperties = QJsonDocument::fromVariant(variantProperties);
|
||||
// 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;
|
||||
public:
|
||||
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());
|
||||
virtual ~EntityItemProperties() = default;
|
||||
|
|
Loading…
Reference in a new issue