mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 16:43:33 +02:00
Working avatar fade in / fade out except that it is also triggered on bubble collisions
This commit is contained in:
parent
aba8be595e
commit
381e0c64a8
9 changed files with 90 additions and 17 deletions
|
@ -274,19 +274,20 @@ void AvatarManager::simulateAvatarFades(float deltaTime) {
|
|||
return;
|
||||
}
|
||||
|
||||
const float SHRINK_RATE = 0.15f;
|
||||
const float MIN_FADE_SCALE = MIN_AVATAR_SCALE;
|
||||
//const float SHRINK_RATE = 0.15f;
|
||||
//const float MIN_FADE_SCALE = MIN_AVATAR_SCALE;
|
||||
|
||||
QReadLocker locker(&_hashLock);
|
||||
QVector<AvatarSharedPointer>::iterator avatarItr = _avatarsToFade.begin();
|
||||
const render::ScenePointer& scene = qApp->getMain3DScene();
|
||||
while (avatarItr != _avatarsToFade.end()) {
|
||||
auto avatar = std::static_pointer_cast<Avatar>(*avatarItr);
|
||||
avatar->setTargetScale(avatar->getUniformScale() * SHRINK_RATE);
|
||||
avatar->animateScaleChanges(deltaTime);
|
||||
if (avatar->getTargetScale() <= MIN_FADE_SCALE) {
|
||||
// TEMP OP avatar->setTargetScale(avatar->getUniformScale() * SHRINK_RATE);
|
||||
// TEMP OP avatar->animateScaleChanges(deltaTime);
|
||||
// TEMP OP if (avatar->getTargetScale() <= MIN_FADE_SCALE) {
|
||||
if (!avatar->isFading(scene)) {
|
||||
// fading to zero is such a rare event we push a unique transaction for each
|
||||
if (avatar->isInScene()) {
|
||||
const render::ScenePointer& scene = qApp->getMain3DScene();
|
||||
render::Transaction transaction;
|
||||
avatar->removeFromScene(*avatarItr, scene, transaction);
|
||||
scene->enqueueTransaction(transaction);
|
||||
|
@ -329,6 +330,7 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar
|
|||
DependencyManager::get<UsersScriptingInterface>()->avatarDisconnected(avatar->getSessionUUID());
|
||||
}
|
||||
_avatarsToFade.push_back(removedAvatar);
|
||||
avatar->fadeOut(qApp->getMain3DScene());
|
||||
}
|
||||
|
||||
void AvatarManager::clearOtherAvatars() {
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <DebugDraw.h>
|
||||
#include <shared/Camera.h>
|
||||
#include <SoftAttachmentModel.h>
|
||||
#include <render/TransitionStage.h>
|
||||
|
||||
#include "Logging.h"
|
||||
|
||||
|
@ -493,6 +494,39 @@ void Avatar::addToScene(AvatarSharedPointer self, const render::ScenePointer& sc
|
|||
for (auto& attachmentModel : _attachmentModels) {
|
||||
attachmentModel->addToScene(scene, transaction);
|
||||
}
|
||||
|
||||
_mustFadeIn = true;
|
||||
}
|
||||
|
||||
bool Avatar::isFading(render::ScenePointer scene) const {
|
||||
if (isInScene()) {
|
||||
const auto& item = scene->getItem(_renderItemID);
|
||||
auto transitionId = item.getTransitionId();
|
||||
return _isWaitingForFade || transitionId!= render::TransitionStage::INVALID_INDEX;
|
||||
}
|
||||
return _isWaitingForFade;
|
||||
}
|
||||
|
||||
void Avatar::fadeIn(render::ScenePointer scene) {
|
||||
render::Transaction transaction;
|
||||
fade(transaction, render::Transition::USER_ENTER_DOMAIN);
|
||||
scene->enqueueTransaction(transaction);
|
||||
}
|
||||
|
||||
void Avatar::fadeOut(render::ScenePointer scene) {
|
||||
render::Transaction transaction;
|
||||
fade(transaction, render::Transition::USER_LEAVE_DOMAIN);
|
||||
scene->enqueueTransaction(transaction);
|
||||
}
|
||||
|
||||
void Avatar::fade(render::Transaction& transaction, render::Transition::Type type) {
|
||||
transaction.transitionItem(_renderItemID, type);
|
||||
for (auto& attachmentModel : _attachmentModels) {
|
||||
for (auto itemId : attachmentModel->fetchRenderItemIDs()) {
|
||||
transaction.transitionItem(itemId, type, _renderItemID);
|
||||
}
|
||||
}
|
||||
_isWaitingForFade = true;
|
||||
}
|
||||
|
||||
void Avatar::removeFromScene(AvatarSharedPointer self, const render::ScenePointer& scene, render::Transaction& transaction) {
|
||||
|
@ -645,6 +679,8 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
|
|||
}
|
||||
|
||||
void Avatar::fixupModelsInScene(const render::ScenePointer& scene) {
|
||||
bool canTryFade{ false };
|
||||
|
||||
_attachmentsToDelete.clear();
|
||||
|
||||
// check to see if when we added our models to the scene they were ready, if they were not ready, then
|
||||
|
@ -653,6 +689,7 @@ void Avatar::fixupModelsInScene(const render::ScenePointer& scene) {
|
|||
if (_skeletonModel->isRenderable() && _skeletonModel->needsFixupInScene()) {
|
||||
_skeletonModel->removeFromScene(scene, transaction);
|
||||
_skeletonModel->addToScene(scene, transaction);
|
||||
canTryFade = true;
|
||||
}
|
||||
for (auto attachmentModel : _attachmentModels) {
|
||||
if (attachmentModel->isRenderable() && attachmentModel->needsFixupInScene()) {
|
||||
|
@ -661,6 +698,20 @@ void Avatar::fixupModelsInScene(const render::ScenePointer& scene) {
|
|||
}
|
||||
}
|
||||
|
||||
if (_mustFadeIn && canTryFade) {
|
||||
// Do it now to be sure all the sub items are ready and the fade is sent to them too
|
||||
fade(transaction, render::Transition::USER_ENTER_DOMAIN);
|
||||
_mustFadeIn = false;
|
||||
}
|
||||
|
||||
if (isInScene()) {
|
||||
const auto& item = scene->getItem(_renderItemID);
|
||||
auto transitionId = item.getTransitionId();
|
||||
if (_isWaitingForFade && transitionId != render::TransitionStage::INVALID_INDEX) {
|
||||
_isWaitingForFade = false;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto attachmentModelToRemove : _attachmentsToRemove) {
|
||||
attachmentModelToRemove->removeFromScene(scene, transaction);
|
||||
}
|
||||
|
|
|
@ -250,6 +250,10 @@ public:
|
|||
void addPhysicsFlags(uint32_t flags);
|
||||
bool isInPhysicsSimulation() const { return _physicsCallback != nullptr; }
|
||||
|
||||
void fadeIn(render::ScenePointer scene);
|
||||
void fadeOut(render::ScenePointer scene);
|
||||
bool isFading(render::ScenePointer scene) const;
|
||||
|
||||
public slots:
|
||||
|
||||
// FIXME - these should be migrated to use Pose data instead
|
||||
|
@ -294,6 +298,8 @@ protected:
|
|||
// protected methods...
|
||||
bool isLookingAtMe(AvatarSharedPointer avatar) const;
|
||||
|
||||
void fade(render::Transaction& transaction, render::Transition::Type type);
|
||||
|
||||
glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
|
||||
glm::vec3 getBodyUpDirection() const { return getOrientation() * IDENTITY_UP; }
|
||||
glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const;
|
||||
|
@ -342,6 +348,8 @@ private:
|
|||
bool _initialized { false };
|
||||
bool _isLookAtTarget { false };
|
||||
bool _isAnimatingScale { false };
|
||||
bool _mustFadeIn{ false };
|
||||
bool _isWaitingForFade{ false };
|
||||
|
||||
static int _jointConesID;
|
||||
|
||||
|
|
|
@ -594,7 +594,13 @@ bool FadeJob::update(const Config& config, const render::ScenePointer& scene, re
|
|||
bool continueTransition = true;
|
||||
|
||||
if (item.exist()) {
|
||||
auto& aabb = item.getBound();
|
||||
auto aabb = item.getBound();
|
||||
if (render::Item::isValidID(transition.boundItemId)) {
|
||||
auto& boundItem = scene->getItem(transition.boundItemId);
|
||||
if (boundItem.exist()) {
|
||||
aabb = boundItem.getBound();
|
||||
}
|
||||
}
|
||||
auto& dimensions = aabb.getDimensions();
|
||||
|
||||
assert(timing < FadeConfig::TIMING_COUNT);
|
||||
|
@ -645,7 +651,7 @@ bool FadeJob::update(const Config& config, const render::ScenePointer& scene, re
|
|||
transition.baseInvSize.y = 1.f / dimensions.y;
|
||||
transition.baseInvSize.z = 1.f / eventConfig.baseSize.z;
|
||||
continueTransition = transition.threshold < 1.f;
|
||||
if (transition.eventType == render::Transition::USER_ENTER_DOMAIN) {
|
||||
if (transition.eventType == render::Transition::USER_LEAVE_DOMAIN) {
|
||||
transition.threshold = 1.f - transition.threshold;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,9 @@ void Transaction::removeItem(ItemID id) {
|
|||
_removedItems.emplace_back(id);
|
||||
}
|
||||
|
||||
void Transaction::transitionItem(ItemID id, Transition::Type transition) {
|
||||
void Transaction::transitionItem(ItemID id, Transition::Type transition, ItemID boundId) {
|
||||
_transitioningItems.emplace_back(id);
|
||||
_transitioningItemBounds.emplace_back(boundId);
|
||||
_transitionTypes.emplace_back(transition);
|
||||
}
|
||||
|
||||
|
@ -53,6 +54,7 @@ void Transaction::merge(const Transaction& transaction) {
|
|||
_updateFunctors.insert(_updateFunctors.end(), transaction._updateFunctors.begin(), transaction._updateFunctors.end());
|
||||
_resetSelections.insert(_resetSelections.end(), transaction._resetSelections.begin(), transaction._resetSelections.end());
|
||||
_transitioningItems.insert(_transitioningItems.end(), transaction._transitioningItems.begin(), transaction._transitioningItems.end());
|
||||
_transitioningItemBounds.insert(_transitioningItemBounds.end(), transaction._transitioningItemBounds.begin(), transaction._transitioningItemBounds.end());
|
||||
_transitionTypes.insert(_transitionTypes.end(), transaction._transitionTypes.begin(), transaction._transitionTypes.end());
|
||||
}
|
||||
|
||||
|
@ -124,7 +126,7 @@ void Scene::processTransactionQueue() {
|
|||
removeItems(consolidatedTransaction._removedItems);
|
||||
|
||||
// Transitions
|
||||
transitionItems(consolidatedTransaction._transitioningItems, consolidatedTransaction._transitionTypes);
|
||||
transitionItems(consolidatedTransaction._transitioningItems, consolidatedTransaction._transitionTypes, consolidatedTransaction._transitioningItemBounds);
|
||||
|
||||
// Update the numItemsAtomic counter AFTER the pending changes went through
|
||||
_numAllocatedItems.exchange(maxID);
|
||||
|
@ -233,8 +235,9 @@ void Scene::updateItems(const ItemIDs& ids, UpdateFunctors& functors) {
|
|||
}
|
||||
}
|
||||
|
||||
void Scene::transitionItems(const ItemIDs& ids, const TransitionTypes& types) {
|
||||
void Scene::transitionItems(const ItemIDs& ids, const TransitionTypes& types, const ItemIDs& boundIds) {
|
||||
auto transitionType = types.begin();
|
||||
auto boundId = boundIds.begin();
|
||||
auto transitionStage = getStage<TransitionStage>(TransitionStage::getName());
|
||||
|
||||
for (auto itemId : ids) {
|
||||
|
@ -242,7 +245,6 @@ void Scene::transitionItems(const ItemIDs& ids, const TransitionTypes& types) {
|
|||
const auto& item = _items[itemId];
|
||||
if (item.exist()) {
|
||||
auto transitionId = INVALID_INDEX;
|
||||
const auto& item = _items[itemId];
|
||||
|
||||
// Remove pre-existing transition, if need be
|
||||
if (item.getTransitionId() != render::TransitionStage::INVALID_INDEX) {
|
||||
|
@ -250,7 +252,7 @@ void Scene::transitionItems(const ItemIDs& ids, const TransitionTypes& types) {
|
|||
}
|
||||
// Add a new one.
|
||||
if (*transitionType != Transition::NONE) {
|
||||
transitionId = transitionStage->addTransition(itemId, *transitionType);
|
||||
transitionId = transitionStage->addTransition(itemId, *transitionType, *boundId);
|
||||
}
|
||||
|
||||
setItemTransition(itemId, transitionId);
|
||||
|
@ -258,6 +260,7 @@ void Scene::transitionItems(const ItemIDs& ids, const TransitionTypes& types) {
|
|||
|
||||
// next loop
|
||||
transitionType++;
|
||||
boundId++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
void resetItem(ItemID id, const PayloadPointer& payload);
|
||||
void removeItem(ItemID id);
|
||||
|
||||
void transitionItem(ItemID id, Transition::Type transition);
|
||||
void transitionItem(ItemID id, Transition::Type transition, ItemID boundId = render::Item::INVALID_ITEM_ID);
|
||||
|
||||
template <class T> void updateItem(ItemID id, std::function<void(T&)> func) {
|
||||
updateItem(id, std::make_shared<UpdateFunctor<T>>(func));
|
||||
|
@ -62,6 +62,7 @@ public:
|
|||
ItemIDs _removedItems;
|
||||
ItemIDs _updatedItems;
|
||||
ItemIDs _transitioningItems;
|
||||
ItemIDs _transitioningItemBounds;
|
||||
TransitionTypes _transitionTypes;
|
||||
UpdateFunctors _updateFunctors;
|
||||
|
||||
|
@ -148,7 +149,7 @@ protected:
|
|||
void resetItems(const ItemIDs& ids, Payloads& payloads);
|
||||
void removeItems(const ItemIDs& ids);
|
||||
void updateItems(const ItemIDs& ids, UpdateFunctors& functors);
|
||||
void transitionItems(const ItemIDs& ids, const TransitionTypes& types);
|
||||
void transitionItems(const ItemIDs& ids, const TransitionTypes& types, const ItemIDs& boundIds);
|
||||
|
||||
void collectSubItems(ItemID parentId, ItemIDs& subItems) const;
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace render {
|
|||
|
||||
Type eventType{ ELEMENT_ENTER_DOMAIN };
|
||||
ItemID itemId{ Item::INVALID_ITEM_ID };
|
||||
ItemID boundItemId{ Item::INVALID_ITEM_ID };
|
||||
double time{ 0.0 };
|
||||
glm::vec3 noiseOffset{ 0.f, 0.f, 0.f };
|
||||
glm::vec3 baseOffset{ 0.f, 0.f, 0.f };
|
||||
|
|
|
@ -6,12 +6,13 @@ using namespace render;
|
|||
|
||||
std::string TransitionStage::_name("Transition");
|
||||
|
||||
TransitionStage::Index TransitionStage::addTransition(ItemID itemId, Transition::Type type) {
|
||||
TransitionStage::Index TransitionStage::addTransition(ItemID itemId, Transition::Type type, ItemID boundId) {
|
||||
Transition transition;
|
||||
Index id;
|
||||
|
||||
transition.eventType = type;
|
||||
transition.itemId = itemId;
|
||||
transition.boundItemId = boundId;
|
||||
id = _transitions.newElement(transition);
|
||||
_activeTransitionIds.push_back(id);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace render {
|
|||
|
||||
Transition& editTransition(Index TransitionId) { return _transitions.edit(TransitionId); }
|
||||
|
||||
Index addTransition(ItemID itemId, Transition::Type type);
|
||||
Index addTransition(ItemID itemId, Transition::Type type, ItemID boundId);
|
||||
void removeTransition(Index index);
|
||||
|
||||
TransitionIdList::iterator begin() { return _activeTransitionIds.begin(); }
|
||||
|
|
Loading…
Reference in a new issue