From 96eb137df26917155625d9fa223b18e8a5cea03e Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 6 Mar 2019 15:53:25 -0800 Subject: [PATCH 1/3] fix debugAvatarMixer.js --- interface/src/ui/overlays/Overlays.cpp | 3 ++- .../developer/debugging/debugAvatarMixer.js | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index dfd698f6c5..c776cffd67 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -204,7 +204,8 @@ QString Overlays::overlayToEntityType(const QString& type) { #define RENAME_PROP(o, e) \ { \ auto iter = overlayProps.find(#o); \ - if (iter != overlayProps.end()) { \ + if (iter != overlayProps.end() && \ + !overlayProps.contains(#e)) { \ overlayProps[#e] = iter.value(); \ } \ } diff --git a/scripts/developer/debugging/debugAvatarMixer.js b/scripts/developer/debugging/debugAvatarMixer.js index 90f2de13a9..fad4283f7c 100644 --- a/scripts/developer/debugging/debugAvatarMixer.js +++ b/scripts/developer/debugging/debugAvatarMixer.js @@ -19,6 +19,11 @@ Script.include("/~/system/libraries/controllers.js"); var isShowingOverlays = true; var debugOverlays = {}; +var textSizeOverlay = Overlays.addOverlay("text3d", { + position: MyAvatar.position, + lineHeight: 0.1, + visible: false +}); function removeOverlays() { // enumerate the overlays and remove them @@ -31,6 +36,8 @@ function removeOverlays() { } } + Overlays.deleteOverlay(textSizeOverlay); + debugOverlays = {}; } @@ -60,8 +67,6 @@ function updateOverlays() { var overlayPosition = avatar.getJointPosition("Head"); overlayPosition.y += 1.15; - var rows = 8; - var text = avatarID + "\n" +"--- Data from Mixer ---\n" +"All: " + AvatarManager.getAvatarDataRate(avatarID).toFixed(2) + "kbps (" + AvatarManager.getAvatarUpdateRate(avatarID).toFixed(2) + "hz)" + "\n" @@ -85,9 +90,11 @@ function updateOverlays() { //+" SM: " + AvatarManager.getAvatarSimulationRate(avatarID,"skeletonModel").toFixed(2) + "hz \n" +" JD: " + AvatarManager.getAvatarSimulationRate(avatarID,"jointData").toFixed(2) + "hz \n" + var dimensions = Overlays.textSize(textSizeOverlay, text); if (avatarID in debugOverlays) { // keep the overlay above the current position of this avatar Overlays.editOverlay(debugOverlays[avatarID][0], { + dimensions: { x: 1.1 * dimensions.width, y: 0.6 * dimensions.height }, position: overlayPosition, text: text }); @@ -95,15 +102,9 @@ function updateOverlays() { // add the overlay above this avatar var newOverlay = Overlays.addOverlay("text3d", { position: overlayPosition, - dimensions: { - x: 1.25, - y: rows * 0.13 - }, + dimensions: { x: 1.1 * dimensions.width, y: 0.6 * dimensions.height }, lineHeight: 0.1, - font:{size:0.1}, text: text, - size: 1, - scale: 0.4, color: { red: 255, green: 255, blue: 255}, alpha: 1, solid: true, From 380df059ffb62a8f723f18c4454af2b272bff3f7 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 6 Mar 2019 18:18:39 -0800 Subject: [PATCH 2/3] fix shapes app --- interface/src/avatar/MyAvatar.cpp | 3 +- interface/src/ui/overlays/Overlays.cpp | 29 +++++++++++++++---- .../src/RenderableModelEntityItem.cpp | 8 ++--- .../src/RenderableModelEntityItem.h | 2 +- .../src/RenderableZoneEntityItem.h | 2 +- libraries/entities/src/EntityItem.cpp | 4 +-- libraries/entities/src/EntityItem.h | 2 +- libraries/entities/src/EntityTree.cpp | 23 ++++++++++----- libraries/entities/src/LightEntityItem.cpp | 4 +-- libraries/entities/src/LightEntityItem.h | 2 +- libraries/shared/src/SpatiallyNestable.cpp | 10 ++++--- libraries/shared/src/SpatiallyNestable.h | 2 +- 12 files changed, 60 insertions(+), 31 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index faa9f88ae9..bfcb9269d5 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -910,7 +910,7 @@ void MyAvatar::simulate(float deltaTime, bool inView) { recorder->recordFrame(FRAME_TYPE, toFrame(*this)); } - locationChanged(); + locationChanged(true, false); // if a entity-child of this avatar has moved outside of its queryAACube, update the cube and tell the entity server. auto entityTreeRenderer = qApp->getEntities(); EntityTreePointer entityTree = entityTreeRenderer ? entityTreeRenderer->getTree() : nullptr; @@ -920,6 +920,7 @@ void MyAvatar::simulate(float deltaTime, bool inView) { zoneInteractionProperties = entityTreeRenderer->getZoneInteractionProperties(); EntityEditPacketSender* packetSender = qApp->getEntityEditPacketSender(); forEachDescendant([&](SpatiallyNestablePointer object) { + locationChanged(true, false); // we need to update attached queryAACubes in our own local tree so point-select always works // however we don't want to flood the update pipeline with AvatarEntity updates, so we assume // others have all info required to properly update queryAACube of AvatarEntities on their end diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index c776cffd67..1bcb040a77 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -494,15 +494,34 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove RENAME_PROP_CONVERT(p1, p1, [](const QVariant& v) { return vec3toVariant(glm::vec3(0.0f)); }); RENAME_PROP_CONVERT(p2, p2, [=](const QVariant& v) { glm::vec3 position; + bool hasPosition = false; + glm::quat rotation; + bool hasRotation = false; + auto iter2 = overlayProps.find("position"); if (iter2 != overlayProps.end()) { position = vec3FromVariant(iter2.value()); - } else if (!add) { - EntityPropertyFlags desiredProperties; - desiredProperties += PROP_POSITION; - position = DependencyManager::get()->getEntityProperties(id, desiredProperties).getPosition(); + hasPosition = true; } - return vec3toVariant(vec3FromVariant(v) - position); + iter2 = overlayProps.find("rotation"); + if (iter2 != overlayProps.end()) { + rotation = quatFromVariant(iter2.value()); + hasRotation = true; + } + + if (!add && !(hasPosition && hasRotation)) { + auto entity = DependencyManager::get()->getEntity(id); + if (entity) { + if (!hasPosition) { + position = entity->getWorldPosition(); + } + if (!hasRotation) { + rotation = entity->getWorldOrientation(); + } + } + } + + return vec3toVariant(glm::inverse(rotation) * (vec3FromVariant(v) - position)); }); RENAME_PROP(localStart, p1); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index e842d98714..03c50008a0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -928,9 +928,9 @@ void RenderableModelEntityItem::setJointTranslationsSet(const QVector& tra _needsJointSimulation = true; } -void RenderableModelEntityItem::locationChanged(bool tellPhysics) { +void RenderableModelEntityItem::locationChanged(bool tellPhysics, bool tellChildren) { DETAILED_PERFORMANCE_TIMER("locationChanged"); - EntityItem::locationChanged(tellPhysics); + EntityItem::locationChanged(tellPhysics, tellChildren); auto model = getModel(); if (model && model->isLoaded()) { model->updateRenderItems(); @@ -1032,9 +1032,7 @@ void RenderableModelEntityItem::copyAnimationJointDataToModel() { }); if (changed) { - forEachChild([&](SpatiallyNestablePointer object) { - object->locationChanged(false); - }); + locationChanged(false, true); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 9adff9ca01..2fd1041c5f 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -108,7 +108,7 @@ public: virtual void setJointTranslations(const QVector& translations) override; virtual void setJointTranslationsSet(const QVector& translationsSet) override; - virtual void locationChanged(bool tellPhysics = true) override; + virtual void locationChanged(bool tellPhysics = true, bool tellChildren = true) override; virtual int getJointIndex(const QString& name) const override; virtual QStringList getJointNames() const override; diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index 32b5cf94a0..2fa55f1540 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -150,7 +150,7 @@ public: virtual bool addToScene(const EntityItemPointer& self, const render::ScenePointer& scene, render::Transaction& transaction) override; virtual void removeFromScene(const EntityItemPointer& self, const render::ScenePointer& scene, render::Transaction& transaction) override; private: - virtual void locationChanged(bool tellPhysics = true) override { EntityItem::locationChanged(tellPhysics); notifyBoundChanged(); } + virtual void locationChanged(bool tellPhysics = true, bool tellChildren = true) override { EntityItem::locationChanged(tellPhysics, tellChildren); notifyBoundChanged(); } virtual void dimensionsChanged() override { EntityItem::dimensionsChanged(); notifyBoundChanged(); } void notifyBoundChanged(); void notifyChangedRenderItem(); diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index d9614a0918..80db432fd0 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -2593,7 +2593,7 @@ QList EntityItem::getActionsOfType(EntityDynamicType typeT return result; } -void EntityItem::locationChanged(bool tellPhysics) { +void EntityItem::locationChanged(bool tellPhysics, bool tellChildren) { requiresRecalcBoxes(); if (tellPhysics) { _flags |= Simulation::DIRTY_TRANSFORM; @@ -2602,7 +2602,7 @@ void EntityItem::locationChanged(bool tellPhysics) { tree->entityChanged(getThisPointer()); } } - SpatiallyNestable::locationChanged(tellPhysics); // tell all the children, also + SpatiallyNestable::locationChanged(tellPhysics, tellChildren); std::pair data(_spaceIndex, glm::vec4(getWorldPosition(), _boundingRadius)); emit spaceUpdate(data); somethingChangedNotification(); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 3fbfde6b24..f8c9c3b6f7 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -518,7 +518,7 @@ public: virtual bool getMeshes(MeshProxyList& result) { return true; } - virtual void locationChanged(bool tellPhysics = true) override; + virtual void locationChanged(bool tellPhysics = true, bool tellChildren = true) override; virtual bool getScalesWithParent() const override; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d4f15fa8b2..5234e77075 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2039,6 +2039,8 @@ void EntityTree::fixupNeedsParentFixups() { Simulation::DIRTY_COLLISION_GROUP | Simulation::DIRTY_TRANSFORM); entityChanged(entity); + entity->locationChanged(true, false); + entity->forEachDescendant([&](SpatiallyNestablePointer object) { if (object->getNestableType() == NestableType::Entity) { EntityItemPointer descendantEntity = std::static_pointer_cast(object); @@ -2047,8 +2049,8 @@ void EntityTree::fixupNeedsParentFixups() { Simulation::DIRTY_TRANSFORM); entityChanged(descendantEntity); } + object->locationChanged(true, false); }); - entity->locationChanged(true); // Update our parent's bounding box bool success = false; @@ -3002,8 +3004,19 @@ void EntityTree::updateEntityQueryAACubeWorker(SpatiallyNestablePointer object, // if the queryBox has changed, tell the entity-server EntityItemPointer entity = std::dynamic_pointer_cast(object); if (entity) { - // NOTE: we rely on side-effects of the entity->updateQueryAACube() call in the following if() conditional: - if (entity->updateQueryAACube() || force) { + bool queryAACubeChanged = false; + if (!entity->hasChildren()) { + // updateQueryAACube will also update all ancestors' AACubes, so we only need to call this for leaf nodes + queryAACubeChanged = entity->updateQueryAACube(); + } else { + AACube oldCube = entity->getQueryAACube(); + object->forEachDescendant([&](SpatiallyNestablePointer descendant) { + updateEntityQueryAACubeWorker(descendant, packetSender, moveOperator, force, tellServer); + }); + queryAACubeChanged = oldCube != entity->getQueryAACube(); + } + + if (queryAACubeChanged || force) { bool success; AACube newCube = entity->getQueryAACube(success); if (success) { @@ -3027,10 +3040,6 @@ void EntityTree::updateEntityQueryAACubeWorker(SpatiallyNestablePointer object, entityChanged(entity); } } - - object->forEachDescendant([&](SpatiallyNestablePointer descendant) { - updateEntityQueryAACubeWorker(descendant, packetSender, moveOperator, force, tellServer); - }); } void EntityTree::updateEntityQueryAACube(SpatiallyNestablePointer object, EntityEditPacketSender* packetSender, diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index 88aae9691c..fcfda66319 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -55,8 +55,8 @@ void LightEntityItem::setUnscaledDimensions(const glm::vec3& value) { } } -void LightEntityItem::locationChanged(bool tellPhysics) { - EntityItem::locationChanged(tellPhysics); +void LightEntityItem::locationChanged(bool tellPhysics, bool tellChildren) { + EntityItem::locationChanged(tellPhysics, tellChildren); withWriteLock([&] { _lightPropertiesChanged = true; }); diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index 26b74f02cd..cc64121cb3 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -74,7 +74,7 @@ public: static bool getLightsArePickable() { return _lightsArePickable; } static void setLightsArePickable(bool value) { _lightsArePickable = value; } - virtual void locationChanged(bool tellPhysics) override; + virtual void locationChanged(bool tellPhysics, bool tellChildren) override; virtual void dimensionsChanged() override; bool lightPropertiesChanged() const { return _lightPropertiesChanged; } diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index d202afc59f..4d97f43e6a 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -1100,10 +1100,12 @@ void SpatiallyNestable::forEachDescendantTest(const ChildLambdaTest& actor) cons } } -void SpatiallyNestable::locationChanged(bool tellPhysics) { - forEachChild([&](SpatiallyNestablePointer object) { - object->locationChanged(tellPhysics); - }); +void SpatiallyNestable::locationChanged(bool tellPhysics, bool tellChildren) { + if (tellChildren) { + forEachChild([&](SpatiallyNestablePointer object) { + object->locationChanged(tellPhysics, tellChildren); + }); + } } AACube SpatiallyNestable::getMaximumAACube(bool& success) const { diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 6b709f0352..f52dc4bf8b 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -211,7 +211,7 @@ public: void dump(const QString& prefix = "") const; - virtual void locationChanged(bool tellPhysics = true); // called when a this object's location has changed + virtual void locationChanged(bool tellPhysics = true, bool tellChildren = true); // called when a this object's location has changed virtual void dimensionsChanged() { _queryAACubeSet = false; } // called when a this object's dimensions have changed virtual void parentDeleted() { } // called on children of a deleted parent From dc4e2645da1439e193e3cbf88e346f4d524a3916 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 7 Mar 2019 08:05:32 -0800 Subject: [PATCH 3/3] even better! --- libraries/entities/src/EntityTree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 5234e77075..fffcd943c3 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -3010,7 +3010,7 @@ void EntityTree::updateEntityQueryAACubeWorker(SpatiallyNestablePointer object, queryAACubeChanged = entity->updateQueryAACube(); } else { AACube oldCube = entity->getQueryAACube(); - object->forEachDescendant([&](SpatiallyNestablePointer descendant) { + object->forEachChild([&](SpatiallyNestablePointer descendant) { updateEntityQueryAACubeWorker(descendant, packetSender, moveOperator, force, tellServer); }); queryAACubeChanged = oldCube != entity->getQueryAACube();