From abd7d6bddf057237fa6fdfbe9b0976a698d4944f Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 25 Jan 2019 22:57:00 -0800 Subject: [PATCH] some stuff is working! --- interface/src/Application.cpp | 4 +- interface/src/avatar/OtherAvatar.cpp | 2 +- interface/src/ui/Keyboard.cpp | 8 +- .../ui/overlays/ContextOverlayInterface.cpp | 2 +- interface/src/ui/overlays/Overlays.cpp | 116 ++++++++++++------ interface/src/ui/overlays/Overlays.h | 2 +- .../src/RenderableGizmoEntityItem.cpp | 4 +- .../src/RenderableWebEntityItem.cpp | 1 - .../entities/src/EntityScriptingInterface.cpp | 4 +- .../shared/src/VariantMapToScriptValue.cpp | 3 + 10 files changed, 94 insertions(+), 52 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 285b9f140b..c1f0f1fbd8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5729,7 +5729,7 @@ void Application::setKeyboardFocusHighlight(const glm::vec3& position, const glm properties.getPulse().setMax(1.0f); properties.getPulse().setColorMode(PulseMode::IN_PHASE); properties.setIgnorePickIntersection(true); - _keyboardFocusHighlightID = entityScriptingInterface->addEntity(properties, "local"); + _keyboardFocusHighlightID = entityScriptingInterface->addEntity(properties, QString("local")); } // Position focus @@ -8760,7 +8760,7 @@ void Application::createLoginDialog() { properties.setVisible(true); auto entityScriptingInterface = DependencyManager::get(); - _loginDialogID = entityScriptingInterface->addEntity(properties, "local"); + _loginDialogID = entityScriptingInterface->addEntity(properties, QString("local")); auto keyboard = DependencyManager::get().data(); if (!keyboard->getAnchorID().isNull() && !_loginDialogID.isNull()) { diff --git a/interface/src/avatar/OtherAvatar.cpp b/interface/src/avatar/OtherAvatar.cpp index 409fa51388..0bbdb697de 100644 --- a/interface/src/avatar/OtherAvatar.cpp +++ b/interface/src/avatar/OtherAvatar.cpp @@ -84,7 +84,7 @@ void OtherAvatar::createOrb() { properties.setDimensions(glm::vec3(0.5f, 0.5f, 0.5f)); properties.setVisible(true); - _otherAvatarOrbMeshPlaceholderID = DependencyManager::get()->addEntity(properties, "local"); + _otherAvatarOrbMeshPlaceholderID = DependencyManager::get()->addEntity(properties, QString("local")); } } diff --git a/interface/src/ui/Keyboard.cpp b/interface/src/ui/Keyboard.cpp index 01d21a211a..be42853f08 100644 --- a/interface/src/ui/Keyboard.cpp +++ b/interface/src/ui/Keyboard.cpp @@ -743,7 +743,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { properties.setRotation(quatFromVariant(anchorObject["rotation"].toVariant())); Anchor anchor; - anchor.entityID = entityScriptingInterface->addEntity(properties, "local"); + anchor.entityID = entityScriptingInterface->addEntity(properties, QString("local")); anchor.originalDimensions = dimensions; _anchor = anchor; } @@ -765,7 +765,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { properties.setParentID(_anchor.entityID); BackPlate backPlate; - backPlate.entityID = entityScriptingInterface->addEntity(properties, "local"); + backPlate.entityID = entityScriptingInterface->addEntity(properties, QString("local")); backPlate.dimensions = dimensions; EntityPropertyFlags desiredProperties; desiredProperties += PROP_LOCAL_POSITION; @@ -822,7 +822,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { properties.setTextures(QVariant(textureMap).toString()); properties.getGrab().setGrabbable(false); properties.setLocalRotation(quatFromVariant(keyboardKeyValue["localOrientation"].toVariant())); - QUuid id = entityScriptingInterface->addEntity(properties, "local"); + QUuid id = entityScriptingInterface->addEntity(properties, QString("local")); key.setID(id); key.setKeyString(keyString); key.saveDimensionsAndLocalPosition(); @@ -859,7 +859,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { properties.setParentID(_anchor.entityID); TextDisplay textDisplay; - textDisplay.entityID = entityScriptingInterface->addEntity(properties, "local"); + textDisplay.entityID = entityScriptingInterface->addEntity(properties, QString("local")); textDisplay.localPosition = localPosition; textDisplay.dimensions = dimensions; textDisplay.lineHeight = lineHeight; diff --git a/interface/src/ui/overlays/ContextOverlayInterface.cpp b/interface/src/ui/overlays/ContextOverlayInterface.cpp index 9eb9a75432..3e0bd0479f 100644 --- a/interface/src/ui/overlays/ContextOverlayInterface.cpp +++ b/interface/src/ui/overlays/ContextOverlayInterface.cpp @@ -205,7 +205,7 @@ bool ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID& properties.setImageURL(PathUtils::resourcesUrl() + "images/inspect-icon.png"); properties.setBillboardMode(BillboardMode::FULL); - _contextOverlayID = entityScriptingInterface->addEntity(properties, "local"); + _contextOverlayID = entityScriptingInterface->addEntity(properties, QString("local")); } EntityItemProperties properties; diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 9dd85db43f..d9a4bad026 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -52,7 +52,7 @@ Overlays::Overlays() { ADD_TYPE_MAP(Box, cube); ADD_TYPE_MAP(Sphere, sphere); - _overlayToEntityTypes["rectangle"] = "Shape"; + _overlayToEntityTypes["rectangle3d"] = "Shape"; ADD_TYPE_MAP(Shape, shape); ADD_TYPE_MAP(Model, model); ADD_TYPE_MAP(Text, text3d); @@ -172,8 +172,7 @@ QString Overlays::overlayToEntityType(const QString& type) { #define SET_OVERLAY_PROP_DEFAULT(o, d) \ { \ - auto iter = overlayProps.find(#o); \ - if (iter == overlayProps.end()) { \ + if (add && !overlayProps.contains(#o)) { \ overlayProps[#o] = d; \ } \ } @@ -190,11 +189,12 @@ QString Overlays::overlayToEntityType(const QString& type) { { \ auto iter = overlayProps.find(#o); \ if (iter != overlayProps.end()) { \ - auto iter2 = overlayProps.find(#g); \ - if (iter2 == overlayProps.end()) { \ + if (!overlayProps.contains(#g)) { \ overlayProps[#g] = QVariantMap(); \ } \ - overlayProps[#g].toMap()[#e] = iter.value(); \ + auto map = overlayProps[#g].toMap(); \ + map[#e] = iter.value(); \ + overlayProps[#g] = map; \ } \ } @@ -202,17 +202,19 @@ QString Overlays::overlayToEntityType(const QString& type) { { \ auto iter = overlayProps.find(#o); \ if (iter != overlayProps.end()) { \ - auto iter2 = overlayProps.find(#g); \ - if (iter2 == overlayProps.end()) { \ + if (!overlayProps.contains(#g)) { \ overlayProps[#g] = QVariantMap(); \ } \ - overlayProps[#g].toMap()[#e] = iter.value(); \ - } else { \ - auto iter2 = overlayProps.find(#g); \ - if (iter2 == overlayProps.end()) { \ + auto map = overlayProps[#g].toMap(); \ + map[#e] = iter.value(); \ + overlayProps[#g] = map; \ + } else if (add) { \ + if (!overlayProps.contains(#g)) { \ overlayProps[#g] = QVariantMap(); \ } \ - overlayProps[#g].toMap()[#e] = d; \ + auto map = overlayProps[#g].toMap(); \ + map[#e] = d; \ + overlayProps[#g] = map; \ } \ } @@ -229,7 +231,7 @@ QString Overlays::overlayToEntityType(const QString& type) { auto iter = overlayProps.find(#o); \ if (iter != overlayProps.end()) { \ overlayProps[#e] = C(iter.value()); \ - } else { \ + } else if (add) { \ overlayProps[#e] = C(d); \ } \ } @@ -238,17 +240,20 @@ QString Overlays::overlayToEntityType(const QString& type) { { \ auto iter = overlayProps.find(#o); \ if (iter != overlayProps.end()) { \ - auto iter2 = overlayProps.find(#g); \ - if (iter2 == overlayProps.end()) { \ + if (!overlayProps.contains(#g)) { \ overlayProps[#g] = QVariantMap(); \ } \ - overlayProps[#g].toMap()[#e] = C(iter.value()); \ + auto map = overlayProps[#g].toMap(); \ + map[#e] = C(iter.value()); \ + overlayProps[#g] = map; \ } \ } -EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& overlayProps) { +EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& overlayProps, const QString& type, bool add, const QUuid& id) { + overlayProps["type"] = type; + SET_OVERLAY_PROP_DEFAULT(alpha, 0.7); - if (overlayProps["type"] != "PolyLine") { + if (type != "PolyLine") { OVERLAY_TO_ENTITY_PROP(p1, position); OVERLAY_TO_ENTITY_PROP(start, position); } @@ -296,18 +301,18 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove return "none"; }); - if (overlayProps["type"] == "Shape") { + if (type == "Shape") { SET_OVERLAY_PROP_DEFAULT(shape, "Hexagon"); - } else if (overlayProps["type"] == "Model") { + } else if (type == "Model") { OVERLAY_TO_ENTITY_PROP(url, modelURL); OVERLAY_TO_ENTITY_PROP(animationSettings, animation); - } else if (overlayProps["type"] == "Image") { + } else if (type == "Image") { OVERLAY_TO_ENTITY_PROP(url, imageURL); - } else if (overlayProps["type"] == "Web") { + } else if (type == "Web") { OVERLAY_TO_ENTITY_PROP(url, sourceUrl); OVERLAY_TO_ENTITY_PROP_CONVERT(inputMode, inputMode, [](const QVariant& v) { return v.toString() == "Mouse" ? "mouse" : "touch"; }); - } else if (overlayProps["type"] == "Gizmo") { - { + } else if (type == "Gizmo") { + if (add || overlayProps.contains("outerRadius")) { float ratio = 2.0f; { auto iter = overlayProps.find("outerRadius"); @@ -315,16 +320,36 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove ratio = iter.value().toFloat() / 0.5f; } } - glm::vec3 dimensions = glm::vec3(1.0f); + glm::vec3 dimensions = ENTITY_ITEM_DEFAULT_DIMENSIONS; { auto iter = overlayProps.find("dimensions"); if (iter != overlayProps.end()) { dimensions = vec3FromVariant(iter.value()); + } else if (!add) { + EntityPropertyFlags desiredProperties; + desiredProperties += PROP_DIMENSIONS; + dimensions = DependencyManager::get()->getEntityProperties(id, desiredProperties).getDimensions(); } } overlayProps["dimensions"] = vec3toVariant(ratio * dimensions); } + if (add || overlayProps.contains("rotation")) { + glm::quat rotation; + { + auto iter = overlayProps.find("rotation"); + if (iter != overlayProps.end()) { + rotation = vec3FromVariant(iter.value()); + } else if (!add) { + EntityPropertyFlags desiredProperties; + desiredProperties += PROP_ROTATION; + rotation = DependencyManager::get()->getEntityProperties(id, desiredProperties).getRotation(); + } + } + // FIXME: + overlayProps["rotation"] = quatToVariant(glm::angleAxis((float)M_PI_2, Vectors::RIGHT) * rotation); + } + { OVERLAY_TO_ENTITY_PROP(color, innerStartColor); OVERLAY_TO_ENTITY_PROP(color, innerEndColor); @@ -383,12 +408,27 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove OVERLAY_TO_GROUP_ENTITY_PROP(minorTickMarksLength, ring, minorTickMarksLength); OVERLAY_TO_GROUP_ENTITY_PROP(majorTickMarksColor, ring, majorTickMarksColor); OVERLAY_TO_GROUP_ENTITY_PROP(minorTickMarksColor, ring, minorTickMarksColor); - } else if (overlayProps["type"] == "PolyLine") { + } else if (type == "PolyLine") { OVERLAY_TO_ENTITY_PROP(startPoint, start); OVERLAY_TO_ENTITY_PROP(p1, start); - OVERLAY_TO_ENTITY_PROP(localStart, start); OVERLAY_TO_ENTITY_PROP(endPoint, end); OVERLAY_TO_ENTITY_PROP(p2, end); + + if (overlayProps.contains("start") || overlayProps.contains("end")) { + glm::vec3 position; + auto iter = overlayProps.find("position"); + if (iter != overlayProps.end()) { + position = vec3FromVariant(iter.value()); + } else if (!add) { + EntityPropertyFlags desiredProperties; + desiredProperties += PROP_POSITION; + position = DependencyManager::get()->getEntityProperties(id, desiredProperties).getPosition(); + } + OVERLAY_TO_ENTITY_PROP_CONVERT(start, start, [position](const QVariant& v) { return vec3toVariant(vec3FromVariant(v) - position); }) + OVERLAY_TO_ENTITY_PROP_CONVERT(end, end, [position](const QVariant& v) { return vec3toVariant(vec3FromVariant(v) - position); }) + } + + OVERLAY_TO_ENTITY_PROP(localStart, start); OVERLAY_TO_ENTITY_PROP(localEnd, end); { @@ -417,17 +457,17 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove } } + QScriptEngine scriptEngine; + QScriptValue props = variantMapToScriptValue(overlayProps, scriptEngine); EntityItemProperties toReturn; - EntityItemPropertiesFromScriptValueHonorReadOnly(variantMapToScriptValue(overlayProps, _scriptEngine), toReturn); + EntityItemPropertiesFromScriptValueHonorReadOnly(props, toReturn); return toReturn; } QVariantMap Overlays::convertEntityToOverlayProperties(const EntityItemProperties& entityProps) { QScriptValue entityProperties; - EntityItemPropertiesToScriptValue(&_scriptEngine, entityProps); QVariantMap props; - return props; } @@ -467,11 +507,10 @@ QUuid Overlays::addOverlay(const QString& type, const QVariant& properties) { } QVariantMap propertyMap = properties.toMap(); - propertyMap["type"] = entityType; - if (type == "rectangle") { + if (type == "rectangle3d") { propertyMap["shape"] = "Quad"; } - return DependencyManager::get()->addEntity(convertOverlayToEntityProperties(propertyMap), "local"); + return DependencyManager::get()->addEntity(convertOverlayToEntityProperties(propertyMap, entityType, true), QString("local")); } QUuid Overlays::add2DOverlay(const Overlay::Pointer& overlay) { @@ -530,8 +569,9 @@ bool Overlays::editOverlay(const QUuid& id, const QVariant& properties) { return true; } - EntityItemProperties entityProperties = convertOverlayToEntityProperties(properties.toMap()); - return !DependencyManager::get()->editEntity(id, entityProperties).isNull(); + auto entityScriptingInterface = DependencyManager::get(); + EntityItemProperties entityProperties = convertOverlayToEntityProperties(properties.toMap(), entityScriptingInterface->getEntityType(id), false, id); + return !entityScriptingInterface->editEntity(id, entityProperties).isNull(); } bool Overlays::editOverlays(const QVariant& propertiesById) { @@ -543,6 +583,7 @@ bool Overlays::editOverlays(const QVariant& propertiesById) { QVariantMap deferred; const QVariantMap map = propertiesById.toMap(); + auto entityScriptingInterface = DependencyManager::get(); for (const auto& key : map.keys()) { QUuid id = QUuid(key); const QVariant& properties = map[key]; @@ -555,8 +596,7 @@ bool Overlays::editOverlays(const QVariant& propertiesById) { } overlay->setProperties(properties.toMap()); } else { - EntityItemProperties entityProperties = convertOverlayToEntityProperties(properties.toMap()); - DependencyManager::get()->editEntity(id, entityProperties); + entityScriptingInterface->editEntity(id, convertOverlayToEntityProperties(properties.toMap(), entityScriptingInterface->getEntityType(id), false, id)); } } diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index fb6fb024aa..acd7f1bcbd 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -724,7 +724,7 @@ private: static std::unordered_map _overlayToEntityTypes; QVariantMap convertEntityToOverlayProperties(const EntityItemProperties& entityProps); - EntityItemProperties convertOverlayToEntityProperties(QVariantMap& overlayProps); + EntityItemProperties convertOverlayToEntityProperties(QVariantMap& overlayProps, const QString& type, bool add, const QUuid& id = QUuid()); private slots: void mousePressPointerEvent(const QUuid& id, const PointerEvent& event); diff --git a/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp b/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp index f2e95c2159..814a4d8ab3 100644 --- a/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp @@ -279,10 +279,10 @@ void GizmoEntityRenderer::doRender(RenderArgs* args) { // Ticks if (hasTickMarks) { if (tickProperties.x > 0.0f && tickProperties.y != 0.0f) { - geometryCache->renderVertices(batch, gpu::LINE_STRIP, _majorTicksGeometryID); + geometryCache->renderVertices(batch, gpu::LINES, _majorTicksGeometryID); } if (tickProperties.z > 0.0f && tickProperties.w != 0.0f) { - geometryCache->renderVertices(batch, gpu::LINE_STRIP, _minorTicksGeometryID); + geometryCache->renderVertices(batch, gpu::LINES, _minorTicksGeometryID); } } } diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 2510e41780..31ca189311 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -361,7 +361,6 @@ void WebEntityRenderer::hoverEnterEntity(const PointerEvent& event) { if (_inputMode == WebInputMode::MOUSE) { handlePointerEvent(event); } else if (_webSurface) { - qDebug() << "boop5" << this << _webSurface << _webSurface->getRootItem(); PointerEvent webEvent = event; webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi)); _webSurface->hoverBeginEvent(webEvent, _touchDevice); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 20af206162..381de7d5d9 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -579,9 +579,9 @@ QUuid EntityScriptingInterface::cloneEntity(const QUuid& entityIDToClone) { if (properties.getEntityHostType() == entity::HostType::LOCAL) { // Local entities are only cloned locally - return addEntity(properties, "local"); + return addEntity(properties, QString("local")); } else if (cloneAvatarEntity) { - return addEntity(properties, "avatar"); + return addEntity(properties, QString("avatar")); } else { // setLastEdited timestamp to 0 to ensure this entity gets updated with the properties // from the server-created entity, don't change this unless you know what you are doing diff --git a/libraries/shared/src/VariantMapToScriptValue.cpp b/libraries/shared/src/VariantMapToScriptValue.cpp index 008c3a5d9b..1a747a4e5b 100644 --- a/libraries/shared/src/VariantMapToScriptValue.cpp +++ b/libraries/shared/src/VariantMapToScriptValue.cpp @@ -41,6 +41,9 @@ QScriptValue variantToScriptValue(QVariant& qValue, QScriptEngine& scriptEngine) break; } default: + if (qValue.canConvert()) { + return qValue.toFloat(); + } qCDebug(shared) << "unhandled QScript type" << qValue.type(); break; }