pointerevents are working!

This commit is contained in:
SamGondelman 2019-01-26 21:53:46 -08:00
parent abd7d6bddf
commit 8f0bd2449b
9 changed files with 120 additions and 132 deletions

View file

@ -1884,6 +1884,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
}
}
});
connect(&_overlays, &Overlays::mousePressOnOverlay, [this](const QUuid& id, const PointerEvent& event) {
if (event.shouldFocus()) {
if (getEntities()->wantsKeyboardFocus(id)) {
setKeyboardFocusLocalEntity(id);
setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
} else {
setKeyboardFocusLocalEntity(UNKNOWN_ENTITY_ID);
}
}
});
connect(entityScriptingInterface.data(), &EntityScriptingInterface::deletingEntity, [this](const EntityItemID& entityItemID) {
if (entityItemID == _keyboardFocusedEntity.get()) {
@ -5729,7 +5739,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, QString("local"));
_keyboardFocusHighlightID = entityScriptingInterface->addEntityInternal(properties, entity::HostType::LOCAL);
}
// Position focus
@ -8760,7 +8770,7 @@ void Application::createLoginDialog() {
properties.setVisible(true);
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
_loginDialogID = entityScriptingInterface->addEntity(properties, QString("local"));
_loginDialogID = entityScriptingInterface->addEntityInternal(properties, entity::HostType::LOCAL);
auto keyboard = DependencyManager::get<Keyboard>().data();
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.setVisible(true);
_otherAvatarOrbMeshPlaceholderID = DependencyManager::get<EntityScriptingInterface>()->addEntity(properties, QString("local"));
_otherAvatarOrbMeshPlaceholderID = DependencyManager::get<EntityScriptingInterface>()->addEntityInternal(properties, entity::HostType::LOCAL);
}
}

View file

@ -743,7 +743,7 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) {
properties.setRotation(quatFromVariant(anchorObject["rotation"].toVariant()));
Anchor anchor;
anchor.entityID = entityScriptingInterface->addEntity(properties, QString("local"));
anchor.entityID = entityScriptingInterface->addEntityInternal(properties, entity::HostType::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, QString("local"));
backPlate.entityID = entityScriptingInterface->addEntityInternal(properties, entity::HostType::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, QString("local"));
QUuid id = entityScriptingInterface->addEntityInternal(properties, entity::HostType::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, QString("local"));
textDisplay.entityID = entityScriptingInterface->addEntityInternal(properties, entity::HostType::LOCAL);
textDisplay.localPosition = localPosition;
textDisplay.dimensions = dimensions;
textDisplay.lineHeight = lineHeight;

View file

@ -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, QString("local"));
_contextOverlayID = entityScriptingInterface->addEntityInternal(properties, entity::HostType::LOCAL);
}
EntityItemProperties properties;

View file

@ -28,6 +28,8 @@
#include <raypick/RayPick.h>
#include <PointerManager.h>
#include <raypick/MouseTransformNode.h>
#include <PickManager.h>
#include <RenderableWebEntityItem.h>
#include "VariantMapToScriptValue.h"
@ -35,7 +37,6 @@
#include "ui/Keyboard.h"
#include <QtQuick/QQuickWindow>
Q_LOGGING_CATEGORY(trace_render_overlays, "trace.render.overlays")
std::unordered_map<QString, QString> Overlays::_entityToOverlayTypes;
@ -62,6 +63,13 @@ Overlays::Overlays() {
ADD_TYPE_MAP(PolyLine, line3d);
ADD_TYPE_MAP(Grid, grid);
ADD_TYPE_MAP(Gizmo, circle3d);
auto mouseRayPick = std::make_shared<RayPick>(Vectors::ZERO, Vectors::UP,
PickFilter(PickFilter::getBitMask(PickFilter::FlagBit::LOCAL_ENTITIES) |
PickFilter::getBitMask(PickFilter::FlagBit::VISIBLE)), 0.0f, true);
mouseRayPick->parentTransform = std::make_shared<MouseTransformNode>();
mouseRayPick->setJointState(PickQuery::JOINT_STATE_MOUSE);
_mouseRayPickID = DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, mouseRayPick);
}
void Overlays::cleanupAllOverlays() {
@ -79,6 +87,13 @@ void Overlays::cleanupAllOverlays() {
}
void Overlays::init() {
auto entityScriptingInterface = DependencyManager::get<EntityScriptingInterface>();
connect(this, &Overlays::hoverEnterOverlay, entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity);
connect(this, &Overlays::hoverOverOverlay, entityScriptingInterface.data(), &EntityScriptingInterface::hoverOverEntity);
connect(this, &Overlays::hoverLeaveOverlay, entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity);
connect(this, &Overlays::mousePressOnOverlay, entityScriptingInterface.data(), &EntityScriptingInterface::mousePressOnEntity);
connect(this, &Overlays::mouseMoveOnOverlay, entityScriptingInterface.data(), &EntityScriptingInterface::mouseMoveOnEntity);
connect(this, &Overlays::mouseReleaseOnOverlay, entityScriptingInterface.data(), &EntityScriptingInterface::mouseReleaseOnEntity);
}
void Overlays::update(float deltatime) {
@ -320,7 +335,7 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
ratio = iter.value().toFloat() / 0.5f;
}
}
glm::vec3 dimensions = ENTITY_ITEM_DEFAULT_DIMENSIONS;
glm::vec3 dimensions = glm::vec3(1.0f);
{
auto iter = overlayProps.find("dimensions");
if (iter != overlayProps.end()) {
@ -347,7 +362,7 @@ EntityItemProperties Overlays::convertOverlayToEntityProperties(QVariantMap& ove
}
}
// FIXME:
overlayProps["rotation"] = quatToVariant(glm::angleAxis((float)M_PI_2, Vectors::RIGHT) * rotation);
//overlayProps["rotation"] = quatToVariant(glm::angleAxis((float)M_PI_2, Vectors::RIGHT) * rotation);
}
{
@ -510,7 +525,7 @@ QUuid Overlays::addOverlay(const QString& type, const QVariant& properties) {
if (type == "rectangle3d") {
propertyMap["shape"] = "Quad";
}
return DependencyManager::get<EntityScriptingInterface>()->addEntity(convertOverlayToEntityProperties(propertyMap, entityType, true), QString("local"));
return DependencyManager::get<EntityScriptingInterface>()->addEntityInternal(convertOverlayToEntityProperties(propertyMap, entityType, true), entity::HostType::LOCAL);
}
QUuid Overlays::add2DOverlay(const Overlay::Pointer& overlay) {
@ -950,21 +965,63 @@ static PointerEvent::Button toPointerButton(const QMouseEvent& event) {
}
}
PointerEvent Overlays::calculateOverlayPointerEvent(const QUuid& id, const PickRay& ray,
const RayToOverlayIntersectionResult& rayPickResult, QMouseEvent* event,
PointerEvent::EventType eventType) {
glm::vec2 pos2D = RayPick::projectOntoEntityXYPlane(id, rayPickResult.intersection);
PointerEvent pointerEvent(eventType, PointerManager::MOUSE_POINTER_ID, pos2D, rayPickResult.intersection, rayPickResult.surfaceNormal,
ray.direction, toPointerButton(*event), toPointerButtons(*event), event->modifiers());
RayToOverlayIntersectionResult getPrevPickResult(unsigned int mouseRayPickID) {
RayToOverlayIntersectionResult overlayResult;
overlayResult.intersects = false;
auto pickResult = DependencyManager::get<PickManager>()->getPrevPickResultTyped<RayPickResult>(mouseRayPickID);
if (pickResult) {
overlayResult.intersects = pickResult->type != IntersectionType::NONE;
if (overlayResult.intersects) {
overlayResult.intersection = pickResult->intersection;
overlayResult.distance = pickResult->distance;
overlayResult.surfaceNormal = pickResult->surfaceNormal;
overlayResult.overlayID = pickResult->objectID;
overlayResult.extraInfo = pickResult->extraInfo;
}
}
return overlayResult;
}
return pointerEvent;
PointerEvent Overlays::calculateOverlayPointerEvent(const QUuid& id, const PickRay& ray,
const RayToOverlayIntersectionResult& rayPickResult, QMouseEvent* event,
PointerEvent::EventType eventType) {
glm::vec2 pos2D = RayPick::projectOntoEntityXYPlane(id, rayPickResult.intersection);
return PointerEvent(eventType, PointerManager::MOUSE_POINTER_ID, pos2D, rayPickResult.intersection, rayPickResult.surfaceNormal,
ray.direction, toPointerButton(*event), toPointerButtons(*event), event->modifiers());
}
void Overlays::hoverEnterPointerEvent(const QUuid& id, const PointerEvent& event) {
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
// emit to scripts
emit hoverEnterOverlay(id, event);
}
}
void Overlays::hoverOverPointerEvent(const QUuid& id, const PointerEvent& event) {
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
// emit to scripts
emit hoverOverOverlay(id, event);
}
}
void Overlays::hoverLeavePointerEvent(const QUuid& id, const PointerEvent& event) {
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
// emit to scripts
emit hoverLeaveOverlay(id, event);
}
}
bool Overlays::mousePressEvent(QMouseEvent* event) {
PerformanceTimer perfTimer("Overlays::mousePressEvent");
PickRay ray = qApp->computePickRay(event->x(), event->y());
RayToOverlayIntersectionResult rayPickResult = findRayIntersectionVector(ray, true, QVector<EntityItemID>(), QVector<EntityItemID>());
RayToOverlayIntersectionResult rayPickResult = getPrevPickResult(_mouseRayPickID);
if (rayPickResult.intersects) {
_currentClickingOnOverlayID = rayPickResult.overlayID;
@ -974,27 +1031,11 @@ bool Overlays::mousePressEvent(QMouseEvent* event) {
}
// if we didn't press on an overlay, disable overlay keyboard focus
setKeyboardFocusOverlay(UNKNOWN_ENTITY_ID);
// emit to scripts
emit mousePressOffOverlay();
return false;
}
void Overlays::mousePressPointerEvent(const QUuid& id, const PointerEvent& event) {
// TODO: generalize this to allow any object to recieve events
auto renderable = qApp->getEntities()->renderableForEntityId(id);
if (renderable) {
auto web = std::dynamic_pointer_cast<render::entities::WebEntityRenderer>(renderable);
if (web) {
if (event.shouldFocus()) {
// Focus keyboard on web overlays
DependencyManager::get<EntityScriptingInterface>()->setKeyboardFocusEntity(UNKNOWN_ENTITY_ID);
setKeyboardFocusOverlay(id);
}
web->handlePointerEvent(event);
}
}
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
@ -1007,79 +1048,23 @@ bool Overlays::mouseDoublePressEvent(QMouseEvent* event) {
PerformanceTimer perfTimer("Overlays::mouseDoublePressEvent");
PickRay ray = qApp->computePickRay(event->x(), event->y());
RayToOverlayIntersectionResult rayPickResult = findRayIntersectionVector(ray, true, QVector<EntityItemID>(), QVector<EntityItemID>());
RayToOverlayIntersectionResult rayPickResult = getPrevPickResult(_mouseRayPickID);
if (rayPickResult.intersects) {
_currentClickingOnOverlayID = rayPickResult.overlayID;
auto pointerEvent = calculateOverlayPointerEvent(_currentClickingOnOverlayID, ray, rayPickResult, event, PointerEvent::Press);
// emit to scripts
emit mouseDoublePressOnOverlay(_currentClickingOnOverlayID, pointerEvent);
return true;
}
// emit to scripts
emit mouseDoublePressOffOverlay();
return false;
}
void Overlays::hoverEnterPointerEvent(const QUuid& id, const PointerEvent& event) {
// TODO: generalize this to allow any object to recieve events
auto renderable = qApp->getEntities()->renderableForEntityId(id);
if (renderable) {
auto web = std::dynamic_pointer_cast<render::entities::WebEntityRenderer>(renderable);
if (web) {
web->hoverEnterEntity(event);
}
}
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
// emit to scripts
emit hoverEnterOverlay(id, event);
}
}
void Overlays::hoverOverPointerEvent(const QUuid& id, const PointerEvent& event) {
// TODO: generalize this to allow any overlay to recieve events
auto renderable = qApp->getEntities()->renderableForEntityId(id);
if (renderable) {
auto web = std::dynamic_pointer_cast<render::entities::WebEntityRenderer>(renderable);
if (web) {
web->handlePointerEvent(event);
}
}
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
// emit to scripts
emit hoverOverOverlay(id, event);
}
}
void Overlays::hoverLeavePointerEvent(const QUuid& id, const PointerEvent& event) {
// TODO: generalize this to allow any overlay to recieve events
auto renderable = qApp->getEntities()->renderableForEntityId(id);
if (renderable) {
auto web = std::dynamic_pointer_cast<render::entities::WebEntityRenderer>(renderable);
if (web) {
web->hoverLeaveEntity(event);
}
}
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
// emit to scripts
emit hoverLeaveOverlay(id, event);
}
}
bool Overlays::mouseReleaseEvent(QMouseEvent* event) {
PerformanceTimer perfTimer("Overlays::mouseReleaseEvent");
PickRay ray = qApp->computePickRay(event->x(), event->y());
RayToOverlayIntersectionResult rayPickResult = findRayIntersectionVector(ray, true, QVector<EntityItemID>(), QVector<EntityItemID>());
RayToOverlayIntersectionResult rayPickResult = getPrevPickResult(_mouseRayPickID);
if (rayPickResult.intersects) {
auto pointerEvent = calculateOverlayPointerEvent(rayPickResult.overlayID, ray, rayPickResult, event, PointerEvent::Release);
mouseReleasePointerEvent(rayPickResult.overlayID, pointerEvent);
@ -1090,19 +1075,9 @@ bool Overlays::mouseReleaseEvent(QMouseEvent* event) {
}
void Overlays::mouseReleasePointerEvent(const QUuid& id, const PointerEvent& event) {
// TODO: generalize this to allow any overlay to recieve events
auto renderable = qApp->getEntities()->renderableForEntityId(id);
if (renderable) {
auto web = std::dynamic_pointer_cast<render::entities::WebEntityRenderer>(renderable);
if (web) {
web->handlePointerEvent(event);
}
}
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
// emit to scripts
emit mouseReleaseOnOverlay(id, event);
}
}
@ -1111,7 +1086,7 @@ bool Overlays::mouseMoveEvent(QMouseEvent* event) {
PerformanceTimer perfTimer("Overlays::mouseMoveEvent");
PickRay ray = qApp->computePickRay(event->x(), event->y());
RayToOverlayIntersectionResult rayPickResult = findRayIntersectionVector(ray, true, QVector<EntityItemID>(), QVector<EntityItemID>());
RayToOverlayIntersectionResult rayPickResult = getPrevPickResult(_mouseRayPickID);
if (rayPickResult.intersects) {
auto pointerEvent = calculateOverlayPointerEvent(rayPickResult.overlayID, ray, rayPickResult, event, PointerEvent::Move);
mouseMovePointerEvent(rayPickResult.overlayID, pointerEvent);
@ -1144,15 +1119,6 @@ bool Overlays::mouseMoveEvent(QMouseEvent* event) {
}
void Overlays::mouseMovePointerEvent(const QUuid& id, const PointerEvent& event) {
// TODO: generalize this to allow any overlay to recieve events
auto renderable = qApp->getEntities()->renderableForEntityId(id);
if (renderable) {
auto web = std::dynamic_pointer_cast<render::entities::WebEntityRenderer>(renderable);
if (web) {
web->handlePointerEvent(event);
}
}
auto keyboard = DependencyManager::get<Keyboard>();
// Do not send keyboard key event to scripts to prevent malignant scripts from gathering what you typed
if (!keyboard->getKeysID().contains(id)) {
@ -1175,8 +1141,6 @@ QVector<QUuid> Overlays::findOverlays(const glm::vec3& center, float radius) {
return result;
}
/**jsdoc
* <p>An overlay may be one of the following types:</p>
* <table>

View file

@ -715,6 +715,7 @@ private:
PointerEvent calculateOverlayPointerEvent(const QUuid& id, const PickRay& ray, const RayToOverlayIntersectionResult& rayPickResult,
QMouseEvent* event, PointerEvent::EventType eventType);
unsigned int _mouseRayPickID;
QUuid _currentClickingOnOverlayID;
QUuid _currentHoverOverOverlayID;

View file

@ -84,38 +84,38 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf
connect(pointerManager.data(), &PointerManager::triggerEndEntity, entityScriptingInterface.data(), &EntityScriptingInterface::mouseReleaseOnEntity);
// Forward mouse events to web entities
auto handlePointerEvent = [&](const EntityItemID& entityID, const PointerEvent& event) {
auto handlePointerEvent = [&](const QUuid& entityID, const PointerEvent& event) {
std::shared_ptr<render::entities::WebEntityRenderer> thisEntity;
auto entity = getEntity(entityID);
if (entity && entity->getType() == EntityTypes::Web) {
thisEntity = std::static_pointer_cast<render::entities::WebEntityRenderer>(renderableForEntityId(entityID));
}
if (thisEntity) {
QMetaObject::invokeMethod(thisEntity.get(), "handlePointerEvent", Q_ARG(PointerEvent, event));
QMetaObject::invokeMethod(thisEntity.get(), "handlePointerEvent", Q_ARG(const PointerEvent&, event));
}
};
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mousePressOnEntity, this, handlePointerEvent);
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseReleaseOnEntity, this, handlePointerEvent);
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseMoveOnEntity, this, handlePointerEvent);
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity, this, [&](const EntityItemID& entityID, const PointerEvent& event) {
connect(entityScriptingInterface.data(), &EntityScriptingInterface::mouseReleaseOnEntity, this, handlePointerEvent);
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverEnterEntity, this, [&](const QUuid& entityID, const PointerEvent& event) {
std::shared_ptr<render::entities::WebEntityRenderer> thisEntity;
auto entity = getEntity(entityID);
if (entity && entity->getType() == EntityTypes::Web) {
thisEntity = std::static_pointer_cast<render::entities::WebEntityRenderer>(renderableForEntityId(entityID));
}
if (thisEntity) {
QMetaObject::invokeMethod(thisEntity.get(), "hoverEnterEntity", Q_ARG(PointerEvent, event));
QMetaObject::invokeMethod(thisEntity.get(), "hoverEnterEntity", Q_ARG(const PointerEvent&, event));
}
});
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverOverEntity, this, handlePointerEvent);
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, this, [&](const EntityItemID& entityID, const PointerEvent& event) {
connect(entityScriptingInterface.data(), &EntityScriptingInterface::hoverLeaveEntity, this, [&](const QUuid& entityID, const PointerEvent& event) {
std::shared_ptr<render::entities::WebEntityRenderer> thisEntity;
auto entity = getEntity(entityID);
if (entity && entity->getType() == EntityTypes::Web) {
thisEntity = std::static_pointer_cast<render::entities::WebEntityRenderer>(renderableForEntityId(entityID));
}
if (thisEntity) {
QMetaObject::invokeMethod(thisEntity.get(), "hoverLeaveEntity", Q_ARG(PointerEvent, event));
QMetaObject::invokeMethod(thisEntity.get(), "hoverLeaveEntity", Q_ARG(const PointerEvent&, event));
}
});
}

View file

@ -474,7 +474,7 @@ void synchronizeEditedGrabProperties(EntityItemProperties& properties, const QSt
}
QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties, const QString& entityHostTypeString) {
QUuid EntityScriptingInterface::addEntityInternal(const EntityItemProperties& properties, entity::HostType entityHostType) {
PROFILE_RANGE(script_entities, __FUNCTION__);
_activityTracking.addedEntityCount++;
@ -483,10 +483,10 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
const auto sessionID = nodeList->getSessionUUID();
EntityItemProperties propertiesWithSimID = properties;
propertiesWithSimID.setEntityHostTypeFromString(entityHostTypeString);
if (propertiesWithSimID.getEntityHostType() == entity::HostType::AVATAR) {
propertiesWithSimID.setEntityHostType(entityHostType);
if (entityHostType == entity::HostType::AVATAR) {
propertiesWithSimID.setOwningAvatarID(sessionID);
} else if (propertiesWithSimID.getEntityHostType() == entity::HostType::LOCAL) {
} else if (entityHostType == entity::HostType::LOCAL) {
// For now, local entities are always collisionless
// TODO: create a separate, local physics simulation that just handles local entities (and MyAvatar?)
propertiesWithSimID.setCollisionless(true);
@ -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, QString("local"));
return addEntityInternal(properties, entity::HostType::LOCAL);
} else if (cloneAvatarEntity) {
return addEntity(properties, QString("avatar"));
return addEntityInternal(properties, entity::HostType::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

View file

@ -167,6 +167,9 @@ public:
*/
static QScriptValue getMultipleEntityProperties(QScriptContext* context, QScriptEngine* engine);
QScriptValue getMultipleEntityPropertiesInternal(QScriptEngine* engine, QVector<QUuid> entityIDs, const QScriptValue& extendedDesiredProperties);
QUuid addEntityInternal(const EntityItemProperties& properties, entity::HostType entityHostType);
public slots:
/**jsdoc
@ -269,7 +272,17 @@ public slots:
* });
* print("Entity created: " + entityID);
*/
Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, const QString& entityHostTypeString);
Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, const QString& entityHostTypeString) {
entity::HostType entityHostType;
if (entityHostTypeString == "domain") {
entityHostType = entity::HostType::DOMAIN;
} else if (entityHostTypeString == "avatar") {
entityHostType = entity::HostType::AVATAR;
} else if (entityHostTypeString == "local") {
entityHostType = entity::HostType::LOCAL;
}
return addEntityInternal(properties, entityHostType);
}
/**jsdoc
* Add a new entity with specified properties.
@ -279,8 +292,8 @@ public slots:
* @returns {Uuid} The ID of the entity if successfully created, otherwise {@link Uuid|Uuid.NULL}.
*/
Q_INVOKABLE QUuid addEntity(const EntityItemProperties& properties, bool avatarEntity = false) {
QString entityHostType = avatarEntity ? "avatar" : "domain";
return addEntity(properties, entityHostType);
entity::HostType entityHostType = avatarEntity ? entity::HostType::AVATAR : entity::HostType::DOMAIN;
return addEntityInternal(properties, entityHostType);
}
/// temporary method until addEntity can be used from QJSEngine