some stuff is working!

This commit is contained in:
SamGondelman 2019-01-25 22:57:00 -08:00
parent bb5c556657
commit abd7d6bddf
10 changed files with 94 additions and 52 deletions

View file

@ -5729,7 +5729,7 @@ void Application::setKeyboardFocusHighlight(const glm::vec3& position, const glm
properties.getPulse().setMax(1.0f); properties.getPulse().setMax(1.0f);
properties.getPulse().setColorMode(PulseMode::IN_PHASE); properties.getPulse().setColorMode(PulseMode::IN_PHASE);
properties.setIgnorePickIntersection(true); properties.setIgnorePickIntersection(true);
_keyboardFocusHighlightID = entityScriptingInterface->addEntity(properties, "local"); _keyboardFocusHighlightID = entityScriptingInterface->addEntity(properties, QString("local"));
} }
// Position focus // Position focus
@ -8760,7 +8760,7 @@ void Application::createLoginDialog() {
properties.setVisible(true); properties.setVisible(true);
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>(); auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
_loginDialogID = entityScriptingInterface->addEntity(properties, "local"); _loginDialogID = entityScriptingInterface->addEntity(properties, QString("local"));
auto keyboard = DependencyManager::get<Keyboard>().data(); auto keyboard = DependencyManager::get<Keyboard>().data();
if (!keyboard->getAnchorID().isNull() && !_loginDialogID.isNull()) { if (!keyboard->getAnchorID().isNull() && !_loginDialogID.isNull()) {

View file

@ -84,7 +84,7 @@ void OtherAvatar::createOrb() {
properties.setDimensions(glm::vec3(0.5f, 0.5f, 0.5f)); properties.setDimensions(glm::vec3(0.5f, 0.5f, 0.5f));
properties.setVisible(true); properties.setVisible(true);
_otherAvatarOrbMeshPlaceholderID = DependencyManager::get<EntityScriptingInterface>()->addEntity(properties, "local"); _otherAvatarOrbMeshPlaceholderID = DependencyManager::get<EntityScriptingInterface>()->addEntity(properties, QString("local"));
} }
} }

View file

@ -743,7 +743,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) {
properties.setRotation(quatFromVariant(anchorObject["rotation"].toVariant())); properties.setRotation(quatFromVariant(anchorObject["rotation"].toVariant()));
Anchor anchor; Anchor anchor;
anchor.entityID = entityScriptingInterface->addEntity(properties, "local"); anchor.entityID = entityScriptingInterface->addEntity(properties, QString("local"));
anchor.originalDimensions = dimensions; anchor.originalDimensions = dimensions;
_anchor = anchor; _anchor = anchor;
} }
@ -765,7 +765,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) {
properties.setParentID(_anchor.entityID); properties.setParentID(_anchor.entityID);
BackPlate backPlate; BackPlate backPlate;
backPlate.entityID = entityScriptingInterface->addEntity(properties, "local"); backPlate.entityID = entityScriptingInterface->addEntity(properties, QString("local"));
backPlate.dimensions = dimensions; backPlate.dimensions = dimensions;
EntityPropertyFlags desiredProperties; EntityPropertyFlags desiredProperties;
desiredProperties += PROP_LOCAL_POSITION; desiredProperties += PROP_LOCAL_POSITION;
@ -822,7 +822,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) {
properties.setTextures(QVariant(textureMap).toString()); properties.setTextures(QVariant(textureMap).toString());
properties.getGrab().setGrabbable(false); properties.getGrab().setGrabbable(false);
properties.setLocalRotation(quatFromVariant(keyboardKeyValue["localOrientation"].toVariant())); properties.setLocalRotation(quatFromVariant(keyboardKeyValue["localOrientation"].toVariant()));
QUuid id = entityScriptingInterface->addEntity(properties, "local"); QUuid id = entityScriptingInterface->addEntity(properties, QString("local"));
key.setID(id); key.setID(id);
key.setKeyString(keyString); key.setKeyString(keyString);
key.saveDimensionsAndLocalPosition(); key.saveDimensionsAndLocalPosition();
@ -859,7 +859,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) {
properties.setParentID(_anchor.entityID); properties.setParentID(_anchor.entityID);
TextDisplay textDisplay; TextDisplay textDisplay;
textDisplay.entityID = entityScriptingInterface->addEntity(properties, "local"); textDisplay.entityID = entityScriptingInterface->addEntity(properties, QString("local"));
textDisplay.localPosition = localPosition; textDisplay.localPosition = localPosition;
textDisplay.dimensions = dimensions; textDisplay.dimensions = dimensions;
textDisplay.lineHeight = lineHeight; textDisplay.lineHeight = lineHeight;

View file

@ -205,7 +205,7 @@ bool ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID&
properties.setImageURL(PathUtils::resourcesUrl() + "images/inspect-icon.png"); properties.setImageURL(PathUtils::resourcesUrl() + "images/inspect-icon.png");
properties.setBillboardMode(BillboardMode::FULL); properties.setBillboardMode(BillboardMode::FULL);
_contextOverlayID = entityScriptingInterface->addEntity(properties, "local"); _contextOverlayID = entityScriptingInterface->addEntity(properties, QString("local"));
} }
EntityItemProperties properties; EntityItemProperties properties;

View file

@ -52,7 +52,7 @@ Overlays::Overlays() {
ADD_TYPE_MAP(Box, cube); ADD_TYPE_MAP(Box, cube);
ADD_TYPE_MAP(Sphere, sphere); ADD_TYPE_MAP(Sphere, sphere);
_overlayToEntityTypes["rectangle"] = "Shape"; _overlayToEntityTypes["rectangle3d"] = "Shape";
ADD_TYPE_MAP(Shape, shape); ADD_TYPE_MAP(Shape, shape);
ADD_TYPE_MAP(Model, model); ADD_TYPE_MAP(Model, model);
ADD_TYPE_MAP(Text, text3d); ADD_TYPE_MAP(Text, text3d);
@ -172,8 +172,7 @@ QString Overlays::overlayToEntityType(const QString& type) {
#define SET_OVERLAY_PROP_DEFAULT(o, d) \ #define SET_OVERLAY_PROP_DEFAULT(o, d) \
{ \ { \
auto iter = overlayProps.find(#o); \ if (add && !overlayProps.contains(#o)) { \
if (iter == overlayProps.end()) { \
overlayProps[#o] = d; \ overlayProps[#o] = d; \
} \ } \
} }
@ -190,11 +189,12 @@ QString Overlays::overlayToEntityType(const QString& type) {
{ \ { \
auto iter = overlayProps.find(#o); \ auto iter = overlayProps.find(#o); \
if (iter != overlayProps.end()) { \ if (iter != overlayProps.end()) { \
auto iter2 = overlayProps.find(#g); \ if (!overlayProps.contains(#g)) { \
if (iter2 == overlayProps.end()) { \
overlayProps[#g] = QVariantMap(); \ 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); \ auto iter = overlayProps.find(#o); \
if (iter != overlayProps.end()) { \ if (iter != overlayProps.end()) { \
auto iter2 = overlayProps.find(#g); \ if (!overlayProps.contains(#g)) { \
if (iter2 == overlayProps.end()) { \
overlayProps[#g] = QVariantMap(); \ overlayProps[#g] = QVariantMap(); \
} \ } \
overlayProps[#g].toMap()[#e] = iter.value(); \ auto map = overlayProps[#g].toMap(); \
} else { \ map[#e] = iter.value(); \
auto iter2 = overlayProps.find(#g); \ overlayProps[#g] = map; \
if (iter2 == overlayProps.end()) { \ } else if (add) { \
if (!overlayProps.contains(#g)) { \
overlayProps[#g] = QVariantMap(); \ 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); \ auto iter = overlayProps.find(#o); \
if (iter != overlayProps.end()) { \ if (iter != overlayProps.end()) { \
overlayProps[#e] = C(iter.value()); \ overlayProps[#e] = C(iter.value()); \
} else { \ } else if (add) { \
overlayProps[#e] = C(d); \ overlayProps[#e] = C(d); \
} \ } \
} }
@ -238,17 +240,20 @@ QString Overlays::overlayToEntityType(const QString& type) {
{ \ { \
auto iter = overlayProps.find(#o); \ auto iter = overlayProps.find(#o); \
if (iter != overlayProps.end()) { \ if (iter != overlayProps.end()) { \
auto iter2 = overlayProps.find(#g); \ if (!overlayProps.contains(#g)) { \
if (iter2 == overlayProps.end()) { \
overlayProps[#g] = QVariantMap(); \ 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); SET_OVERLAY_PROP_DEFAULT(alpha, 0.7);
if (overlayProps["type"] != "PolyLine") { if (type != "PolyLine") {
OVERLAY_TO_ENTITY_PROP(p1, position); OVERLAY_TO_ENTITY_PROP(p1, position);
OVERLAY_TO_ENTITY_PROP(start, position); OVERLAY_TO_ENTITY_PROP(start, position);
} }
@ -296,18 +301,18 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
return "none"; return "none";
}); });
if (overlayProps["type"] == "Shape") { if (type == "Shape") {
SET_OVERLAY_PROP_DEFAULT(shape, "Hexagon"); 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(url, modelURL);
OVERLAY_TO_ENTITY_PROP(animationSettings, animation); OVERLAY_TO_ENTITY_PROP(animationSettings, animation);
} else if (overlayProps["type"] == "Image") { } else if (type == "Image") {
OVERLAY_TO_ENTITY_PROP(url, imageURL); 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(url, sourceUrl);
OVERLAY_TO_ENTITY_PROP_CONVERT(inputMode, inputMode, [](const QVariant& v) { return v.toString() == "Mouse" ? "mouse" : "touch"; }); 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; float ratio = 2.0f;
{ {
auto iter = overlayProps.find("outerRadius"); auto iter = overlayProps.find("outerRadius");
@ -315,16 +320,36 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
ratio = iter.value().toFloat() / 0.5f; 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"); auto iter = overlayProps.find("dimensions");
if (iter != overlayProps.end()) { if (iter != overlayProps.end()) {
dimensions = vec3FromVariant(iter.value()); dimensions = vec3FromVariant(iter.value());
} else if (!add) {
EntityPropertyFlags desiredProperties;
desiredProperties += PROP_DIMENSIONS;
dimensions = DependencyManager::get<EntityScriptingInterface>()->getEntityProperties(id, desiredProperties).getDimensions();
} }
} }
overlayProps["dimensions"] = vec3toVariant(ratio * dimensions); 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<EntityScriptingInterface>()->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, innerStartColor);
OVERLAY_TO_ENTITY_PROP(color, innerEndColor); 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(minorTickMarksLength, ring, minorTickMarksLength);
OVERLAY_TO_GROUP_ENTITY_PROP(majorTickMarksColor, ring, majorTickMarksColor); OVERLAY_TO_GROUP_ENTITY_PROP(majorTickMarksColor, ring, majorTickMarksColor);
OVERLAY_TO_GROUP_ENTITY_PROP(minorTickMarksColor, ring, minorTickMarksColor); 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(startPoint, start);
OVERLAY_TO_ENTITY_PROP(p1, start); OVERLAY_TO_ENTITY_PROP(p1, start);
OVERLAY_TO_ENTITY_PROP(localStart, start);
OVERLAY_TO_ENTITY_PROP(endPoint, end); OVERLAY_TO_ENTITY_PROP(endPoint, end);
OVERLAY_TO_ENTITY_PROP(p2, 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<EntityScriptingInterface>()->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); OVERLAY_TO_ENTITY_PROP(localEnd, end);
{ {
@ -417,17 +457,17 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
} }
} }
QScriptEngine scriptEngine;
QScriptValue props = variantMapToScriptValue(overlayProps, scriptEngine);
EntityItemProperties toReturn; EntityItemProperties toReturn;
EntityItemPropertiesFromScriptValueHonorReadOnly(variantMapToScriptValue(overlayProps, _scriptEngine), toReturn); EntityItemPropertiesFromScriptValueHonorReadOnly(props, toReturn);
return toReturn; return toReturn;
} }
QVariantMap Overlays::convertEntityToOverlayProperties(const EntityItemProperties& entityProps) { QVariantMap Overlays::convertEntityToOverlayProperties(const EntityItemProperties& entityProps) {
QScriptValue entityProperties; QScriptValue entityProperties;
EntityItemPropertiesToScriptValue(&_scriptEngine, entityProps);
QVariantMap props; QVariantMap props;
return props; return props;
} }
@ -467,11 +507,10 @@ QUuid Overlays::addOverlay(const QString& type, const QVariant& properties) {
} }
QVariantMap propertyMap = properties.toMap(); QVariantMap propertyMap = properties.toMap();
propertyMap["type"] = entityType; if (type == "rectangle3d") {
if (type == "rectangle") {
propertyMap["shape"] = "Quad"; propertyMap["shape"] = "Quad";
} }
return DependencyManager::get<EntityScriptingInterface>()->addEntity(convertOverlayToEntityProperties(propertyMap), "local"); return DependencyManager::get<EntityScriptingInterface>()->addEntity(convertOverlayToEntityProperties(propertyMap, entityType, true), QString("local"));
} }
QUuid Overlays::add2DOverlay(const Overlay::Pointer& overlay) { QUuid Overlays::add2DOverlay(const Overlay::Pointer& overlay) {
@ -530,8 +569,9 @@ bool Overlays::editOverlay(const QUuid& id, const QVariant& properties) {
return true; return true;
} }
EntityItemProperties entityProperties = convertOverlayToEntityProperties(properties.toMap()); auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
return !DependencyManager::get<EntityScriptingInterface>()->editEntity(id, entityProperties).isNull(); EntityItemProperties entityProperties = convertOverlayToEntityProperties(properties.toMap(), entityScriptingInterface->getEntityType(id), false, id);
return !entityScriptingInterface->editEntity(id, entityProperties).isNull();
} }
bool Overlays::editOverlays(const QVariant& propertiesById) { bool Overlays::editOverlays(const QVariant& propertiesById) {
@ -543,6 +583,7 @@ bool Overlays::editOverlays(const QVariant& propertiesById) {
QVariantMap deferred; QVariantMap deferred;
const QVariantMap map = propertiesById.toMap(); const QVariantMap map = propertiesById.toMap();
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
for (const auto& key : map.keys()) { for (const auto& key : map.keys()) {
QUuid id = QUuid(key); QUuid id = QUuid(key);
const QVariant& properties = map[key]; const QVariant& properties = map[key];
@ -555,8 +596,7 @@ bool Overlays::editOverlays(const QVariant& propertiesById) {
} }
overlay->setProperties(properties.toMap()); overlay->setProperties(properties.toMap());
} else { } else {
EntityItemProperties entityProperties = convertOverlayToEntityProperties(properties.toMap()); entityScriptingInterface->editEntity(id, convertOverlayToEntityProperties(properties.toMap(), entityScriptingInterface->getEntityType(id), false, id));
DependencyManager::get<EntityScriptingInterface>()->editEntity(id, entityProperties);
} }
} }

View file

@ -724,7 +724,7 @@ private:
static std::unordered_map<QString, QString> _overlayToEntityTypes; static std::unordered_map<QString, QString> _overlayToEntityTypes;
QVariantMap convertEntityToOverlayProperties(const EntityItemProperties& entityProps); QVariantMap convertEntityToOverlayProperties(const EntityItemProperties& entityProps);
EntityItemProperties convertOverlayToEntityProperties(QVariantMap& overlayProps); EntityItemProperties convertOverlayToEntityProperties(QVariantMap& overlayProps, const QString& type, bool add, const QUuid& id = QUuid());
private slots: private slots:
void mousePressPointerEvent(const QUuid& id, const PointerEvent& event); void mousePressPointerEvent(const QUuid& id, const PointerEvent& event);

View file

@ -279,10 +279,10 @@ void GizmoEntityRenderer::doRender(RenderArgs* args) {
// Ticks // Ticks
if (hasTickMarks) { if (hasTickMarks) {
if (tickProperties.x > 0.0f && tickProperties.y != 0.0f) { 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) { if (tickProperties.z > 0.0f && tickProperties.w != 0.0f) {
geometryCache->renderVertices(batch, gpu::LINE_STRIP, _minorTicksGeometryID); geometryCache->renderVertices(batch, gpu::LINES, _minorTicksGeometryID);
} }
} }
} }

View file

@ -361,7 +361,6 @@ void WebEntityRenderer::hoverEnterEntity(const PointerEvent& event) {
if (_inputMode == WebInputMode::MOUSE) { if (_inputMode == WebInputMode::MOUSE) {
handlePointerEvent(event); handlePointerEvent(event);
} else if (_webSurface) { } else if (_webSurface) {
qDebug() << "boop5" << this << _webSurface << _webSurface->getRootItem();
PointerEvent webEvent = event; PointerEvent webEvent = event;
webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi)); webEvent.setPos2D(event.getPos2D() * (METERS_TO_INCHES * _dpi));
_webSurface->hoverBeginEvent(webEvent, _touchDevice); _webSurface->hoverBeginEvent(webEvent, _touchDevice);

View file

@ -579,9 +579,9 @@ QUuid EntityScriptingInterface::cloneEntity(const QUuid& entityIDToClone) {
if (properties.getEntityHostType() == entity::HostType::LOCAL) { if (properties.getEntityHostType() == entity::HostType::LOCAL) {
// Local entities are only cloned locally // Local entities are only cloned locally
return addEntity(properties, "local"); return addEntity(properties, QString("local"));
} else if (cloneAvatarEntity) { } else if (cloneAvatarEntity) {
return addEntity(properties, "avatar"); return addEntity(properties, QString("avatar"));
} else { } else {
// setLastEdited timestamp to 0 to ensure this entity gets updated with the properties // 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 // from the server-created entity, don't change this unless you know what you are doing

View file

@ -41,6 +41,9 @@ QScriptValue variantToScriptValue(QVariant& qValue, QScriptEngine& scriptEngine)
break; break;
} }
default: default:
if (qValue.canConvert<float>()) {
return qValue.toFloat();
}
qCDebug(shared) << "unhandled QScript type" << qValue.type(); qCDebug(shared) << "unhandled QScript type" << qValue.type();
break; break;
} }