mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:37:49 +02:00
Merge pull request #13653 from ElderOrb/fake-wearables-fix
FB16870: Avatar Wearables showing incorrect number
This commit is contained in:
commit
2ac9463830
4 changed files with 63 additions and 12 deletions
|
@ -144,9 +144,19 @@ void AvatarBookmarks::removeBookmark(const QString& bookmarkName) {
|
||||||
emit bookmarkDeleted(bookmarkName);
|
emit bookmarkDeleted(bookmarkName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isWearableEntity(const EntityItemPointer& entity) {
|
||||||
|
return entity->isVisible() && entity->getParentJointIndex() != INVALID_JOINT_INDEX &&
|
||||||
|
(entity->getParentID() == DependencyManager::get<NodeList>()->getSessionUUID() || entity->getParentID() == DependencyManager::get<AvatarManager>()->getMyAvatar()->getSelfID());
|
||||||
|
}
|
||||||
|
|
||||||
void AvatarBookmarks::updateAvatarEntities(const QVariantList &avatarEntities) {
|
void AvatarBookmarks::updateAvatarEntities(const QVariantList &avatarEntities) {
|
||||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
myAvatar->removeAvatarEntities();
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
|
myAvatar->removeAvatarEntities([&](const QUuid& entityID) {
|
||||||
|
auto entity = entityTree->findEntityByID(entityID);
|
||||||
|
return entity && isWearableEntity(entity);
|
||||||
|
});
|
||||||
|
|
||||||
addAvatarEntities(avatarEntities);
|
addAvatarEntities(avatarEntities);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +173,12 @@ void AvatarBookmarks::loadBookmark(const QString& bookmarkName) {
|
||||||
QVariantMap bookmark = bookmarkEntry.value().toMap();
|
QVariantMap bookmark = bookmarkEntry.value().toMap();
|
||||||
if (!bookmark.empty()) {
|
if (!bookmark.empty()) {
|
||||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
myAvatar->removeAvatarEntities();
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
|
myAvatar->removeAvatarEntities([&](const QUuid& entityID) {
|
||||||
|
auto entity = entityTree->findEntityByID(entityID);
|
||||||
|
return entity && isWearableEntity(entity);
|
||||||
|
});
|
||||||
const QString& avatarUrl = bookmark.value(ENTRY_AVATAR_URL, "").toString();
|
const QString& avatarUrl = bookmark.value(ENTRY_AVATAR_URL, "").toString();
|
||||||
myAvatar->useFullAvatarURL(avatarUrl);
|
myAvatar->useFullAvatarURL(avatarUrl);
|
||||||
qCDebug(interfaceapp) << "Avatar On " << avatarUrl;
|
qCDebug(interfaceapp) << "Avatar On " << avatarUrl;
|
||||||
|
@ -233,6 +248,27 @@ QVariantMap AvatarBookmarks::getAvatarDataToBookmark() {
|
||||||
bookmark.insert(ENTRY_AVATAR_URL, avatarUrl);
|
bookmark.insert(ENTRY_AVATAR_URL, avatarUrl);
|
||||||
bookmark.insert(ENTRY_AVATAR_SCALE, avatarScale);
|
bookmark.insert(ENTRY_AVATAR_SCALE, avatarScale);
|
||||||
bookmark.insert(ENTRY_AVATAR_ATTACHMENTS, myAvatar->getAttachmentsVariant());
|
bookmark.insert(ENTRY_AVATAR_ATTACHMENTS, myAvatar->getAttachmentsVariant());
|
||||||
bookmark.insert(ENTRY_AVATAR_ENTITIES, myAvatar->getAvatarEntitiesVariant());
|
|
||||||
|
QScriptEngine scriptEngine;
|
||||||
|
QVariantList wearableEntities;
|
||||||
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
|
auto avatarEntities = myAvatar->getAvatarEntityData();
|
||||||
|
for (auto entityID : avatarEntities.keys()) {
|
||||||
|
auto entity = entityTree->findEntityByID(entityID);
|
||||||
|
if (!entity || !isWearableEntity(entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QVariantMap avatarEntityData;
|
||||||
|
EncodeBitstreamParams params;
|
||||||
|
auto desiredProperties = entity->getEntityProperties(params);
|
||||||
|
desiredProperties += PROP_LOCAL_POSITION;
|
||||||
|
desiredProperties += PROP_LOCAL_ROTATION;
|
||||||
|
EntityItemProperties entityProperties = entity->getProperties(desiredProperties);
|
||||||
|
QScriptValue scriptProperties = EntityItemPropertiesToScriptValue(&scriptEngine, entityProperties);
|
||||||
|
avatarEntityData["properties"] = scriptProperties.toVariant();
|
||||||
|
wearableEntities.append(QVariant(avatarEntityData));
|
||||||
|
}
|
||||||
|
bookmark.insert(ENTRY_AVATAR_ENTITIES, wearableEntities);
|
||||||
return bookmark;
|
return bookmark;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1608,14 +1608,16 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
|
||||||
emit skeletonModelURLChanged();
|
emit skeletonModelURLChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::removeAvatarEntities() {
|
void MyAvatar::removeAvatarEntities(const std::function<bool(const QUuid& entityID)>& condition) {
|
||||||
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
auto treeRenderer = DependencyManager::get<EntityTreeRenderer>();
|
||||||
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr;
|
||||||
if (entityTree) {
|
if (entityTree) {
|
||||||
entityTree->withWriteLock([&] {
|
entityTree->withWriteLock([&] {
|
||||||
AvatarEntityMap avatarEntities = getAvatarEntityData();
|
AvatarEntityMap avatarEntities = getAvatarEntityData();
|
||||||
for (auto entityID : avatarEntities.keys()) {
|
for (auto entityID : avatarEntities.keys()) {
|
||||||
entityTree->deleteEntity(entityID, true, true);
|
if (!condition || condition(entityID)) {
|
||||||
|
entityTree->deleteEntity(entityID, true, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "MyCharacterController.h"
|
#include "MyCharacterController.h"
|
||||||
#include "RingBufferHistory.h"
|
#include "RingBufferHistory.h"
|
||||||
#include <ThreadSafeValueCache.h>
|
#include <ThreadSafeValueCache.h>
|
||||||
|
#include <EntityItem.h>
|
||||||
|
|
||||||
class AvatarActionHold;
|
class AvatarActionHold;
|
||||||
class ModelItemID;
|
class ModelItemID;
|
||||||
|
@ -926,7 +927,7 @@ public:
|
||||||
* @returns {object[]}
|
* @returns {object[]}
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE QVariantList getAvatarEntitiesVariant();
|
Q_INVOKABLE QVariantList getAvatarEntitiesVariant();
|
||||||
void removeAvatarEntities();
|
void removeAvatarEntities(const std::function<bool(const QUuid& entityID)>& condition = {});
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* @function MyAvatar.isFlying
|
* @function MyAvatar.isFlying
|
||||||
|
|
|
@ -29,13 +29,25 @@ function executeLater(callback) {
|
||||||
Script.setTimeout(callback, 300);
|
Script.setTimeout(callback, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMyAvatarWearables() {
|
var INVALID_JOINT_INDEX = -1
|
||||||
var wearablesArray = MyAvatar.getAvatarEntitiesVariant();
|
function isWearable(avatarEntity) {
|
||||||
|
return avatarEntity.properties.visible === true && avatarEntity.properties.parentJointIndex !== INVALID_JOINT_INDEX &&
|
||||||
|
(avatarEntity.properties.parentID === MyAvatar.sessionUUID || avatarEntity.properties.parentID === MyAvatar.SELF_ID);
|
||||||
|
}
|
||||||
|
|
||||||
for(var i = 0; i < wearablesArray.length; ++i) {
|
function getMyAvatarWearables() {
|
||||||
var wearable = wearablesArray[i];
|
var entitiesArray = MyAvatar.getAvatarEntitiesVariant();
|
||||||
var localRotation = wearable.properties.localRotation;
|
var wearablesArray = [];
|
||||||
wearable.properties.localRotationAngles = Quat.safeEulerAngles(localRotation)
|
|
||||||
|
for (var i = 0; i < entitiesArray.length; ++i) {
|
||||||
|
var entity = entitiesArray[i];
|
||||||
|
if (!isWearable(entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var localRotation = entity.properties.localRotation;
|
||||||
|
entity.properties.localRotationAngles = Quat.safeEulerAngles(localRotation)
|
||||||
|
wearablesArray.push(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wearablesArray;
|
return wearablesArray;
|
||||||
|
|
Loading…
Reference in a new issue