From b1e7c3d4fd770f04450feae1dea54d1999598854 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 6 Feb 2019 16:04:40 -0800 Subject: [PATCH] allow negative dimensions for planar overlays via HACK, set default texture for line overlays to white pixel --- interface/resources/images/whitePixel.png | Bin 0 -> 155 bytes interface/src/ui/overlays/Overlays.cpp | 66 +++++++++++++++++++++- interface/src/ui/overlays/Overlays.h | 3 +- 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 interface/resources/images/whitePixel.png diff --git a/interface/resources/images/whitePixel.png b/interface/resources/images/whitePixel.png new file mode 100644 index 0000000000000000000000000000000000000000..fe2ec44cb704a92cedd8ffd53be63b92b34a2a75 GIT binary patch literal 155 zcmeAS@N?(olHy`uVBq!ia0y~yU|O>_%)r2R7=#&*=dVa%U|^6aag8Vm&QB{TPb^AhC`ioAE78kK zEm1JhGt@IpagP95!{h1V7$Om#{Nw+Bdj{5jO#hafHnuP@Ffe$!`njxgN@xNA#_B0L literal 0 HcmV?d00001 diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 150fa22cd5..8a0f3cfd8b 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -301,7 +301,14 @@ QString Overlays::overlayToEntityType(const QString& type) { } \ } +static QHash savedRotations = QHash(); + EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& overlayProps, const QString& type, bool add, const QUuid& id) { + glm::quat rotation; + return convertOverlayToEntityProperties(overlayProps, rotation, type, add, id); +} + +EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& overlayProps, glm::quat& rotationToSave, const QString& type, bool add, const QUuid& id) { overlayProps["type"] = type; SET_OVERLAY_PROP_DEFAULT(alpha, 0.7); @@ -541,6 +548,58 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove normals.append(vec3toVariant(Vectors::UP)); SET_OVERLAY_PROP_DEFAULT(normals, normals); } + + SET_OVERLAY_PROP_DEFAULT(textures, PathUtils::resourcesUrl() + "images/whitePixel.png"); + } + + if (type == "Text" || type == "Image" || type == "Grid" || type == "Web") { + glm::quat originalRotation = ENTITY_ITEM_DEFAULT_ROTATION; + { + auto iter = overlayProps.find("rotation"); + if (iter != overlayProps.end()) { + originalRotation = quatFromVariant(iter.value()); + } else { + iter = overlayProps.find("localRotation"); + if (iter != overlayProps.end()) { + originalRotation = quatFromVariant(iter.value()); + } else if (!add) { + auto iter2 = savedRotations.find(id); + if (iter2 != savedRotations.end()) { + originalRotation = iter2.value(); + } + } + } + } + + if (!add) { + savedRotations[id] = originalRotation; + } else { + rotationToSave = originalRotation; + } + + glm::vec3 dimensions = ENTITY_ITEM_DEFAULT_DIMENSIONS; + { + auto iter = overlayProps.find("dimensions"); + if (iter != overlayProps.end()) { + dimensions = vec3FromVariant(iter.value()); + } + } + + bool rotateX = dimensions.y < 0.0f; + bool rotateY = dimensions.x < 0.0f; + + { + glm::quat rotation = originalRotation; + if (rotateX) { + rotation = glm::angleAxis((float)M_PI, rotation * Vectors::RIGHT) * rotation; + } + if (rotateY) { + rotation = glm::angleAxis((float)M_PI, rotation * Vectors::UP) * rotation; + } + + overlayProps["localRotation"] = quatToVariant(rotation); + overlayProps["dimensions"] = vec3toVariant(glm::abs(dimensions)); + } } QScriptEngine scriptEngine; @@ -714,7 +773,12 @@ QUuid Overlays::addOverlay(const QString& type, const QVariant& properties) { if (type == "rectangle3d") { propertyMap["shape"] = "Quad"; } - return DependencyManager::get()->addEntityInternal(convertOverlayToEntityProperties(propertyMap, entityType, true), entity::HostType::LOCAL); + glm::quat rotationToSave; + QUuid id = DependencyManager::get()->addEntityInternal(convertOverlayToEntityProperties(propertyMap, rotationToSave, entityType, true), entity::HostType::LOCAL); + if (entityType == "Text" || entityType == "Image" || entityType == "Grid" || entityType == "Web") { + savedRotations[id] = rotationToSave; + } + return id; } QUuid Overlays::add2DOverlay(const Overlay::Pointer& overlay) { diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index 5a5e845a66..6e88397967 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -728,7 +728,8 @@ private: static std::unordered_map _overlayToEntityTypes; QVariantMap convertEntityToOverlayProperties(const EntityItemProperties& entityProps); - EntityItemProperties convertOverlayToEntityProperties(QVariantMap& overlayProps, const QString& type, bool add, const QUuid& id = QUuid()); + EntityItemProperties convertOverlayToEntityProperties(QVariantMap& overlayProps, const QString& type, bool add, const QUuid& id); + EntityItemProperties convertOverlayToEntityProperties(QVariantMap& overlayProps, glm::quat& rotationToSave, const QString& type, bool add, const QUuid& id = QUuid()); private slots: void mousePressPointerEvent(const QUuid& id, const PointerEvent& event);