//// EntityItemProperties.cpp// libraries/entities/src//// Created by Brad Hefta-Gaub on 12/4/13.// Copyright 2013 High Fidelity, Inc.// Copyright 2020 Vircadia contributors.// Copyright 2022-2023 Overte e.V.//// Distributed under the Apache License, Version 2.0.// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html// SPDX-License-Identifier: Apache-2.0// #include "EntityItemProperties.h" #include <openssl/err.h>#include <openssl/pem.h>#include <openssl/x509.h>#include <openssl/ecdsa.h> #include <QDebug>#include <QHash>#include <QObject>#include <QtCore/QJsonDocument>#include <QtNetwork/QNetworkReply>#include <QtNetwork/QNetworkRequest> #include <NetworkAccessManager.h>#include <ByteCountCoding.h>#include <GLMHelpers.h>#include <RegisteredMetaTypes.h>#include <Extents.h>#include <VariantMapToScriptValue.h>#include <ScriptValue.h>#include <PhysicsHelpers.h> #include "EntitiesLogging.h"#include "WarningsSuppression.h" @ENTITY_ITEM_PROPERTY_STATIC_GROUPS@ EntityPropertyList PROP_LAST_ITEM = (EntityPropertyList)(PROP_AFTER_LAST_ITEM - 1); EntityItemProperties::EntityItemProperties(EntityPropertyFlags desiredProperties) : _id(UNKNOWN_ENTITY_ID), _idSet(false), _lastEdited(0), _type(EntityTypes::Unknown), _defaultSettings(true), _naturalDimensions(1.0f, 1.0f, 1.0f), _naturalPosition(0.0f, 0.0f, 0.0f), _desiredProperties(desiredProperties){ } void EntityItemProperties::calculateNaturalPosition(const vec3& min, const vec3& max) { vec3 halfDimension = (max - min) / 2.0f; _naturalPosition = max - halfDimension;} void EntityItemProperties::debugDump() const { qCDebug(entities) << "EntityItemProperties..."; qCDebug(entities) << " _type=" << EntityTypes::getEntityTypeName(_type); qCDebug(entities) << " _id=" << _id; qCDebug(entities) << " _idSet=" << _idSet; qCDebug(entities) << " _position=" << _position.x << "," << _position.y << "," << _position.z; qCDebug(entities) << " _dimensions=" << getDimensions(); qCDebug(entities) << " _modelURL=" << _modelURL; qCDebug(entities) << " _compoundShapeURL=" << _compoundShapeURL; @ENTITY_ITEM_PROPERTY_DEBUG_DUMP_GROUPS@ qCDebug(entities) << " changed properties..."; EntityPropertyFlags props = getChangedProperties(); props.debugDumpBits();} void EntityItemProperties::setLastEdited(quint64 usecTime) { _lastEdited = usecTime > _created ? usecTime : _created;} bool EntityItemProperties::constructFromBuffer(const unsigned char* data, int dataLength) { ReadBitstreamToTreeParams args; EntityItemPointer tempEntity = EntityTypes::constructEntityItem(data, dataLength); if (!tempEntity) { return false; } tempEntity->readEntityDataFromBuffer(data, dataLength, args); (*this) = tempEntity->getProperties(); return true;} inline void addEntityShape(QHash<QString, EntityShape>& lookup, EntityShape type) { lookup[EntityShapeHelpers::getNameForEntityShape(type)] = type; }QHash<QString, EntityShape> stringToEntityShapeLookup = [] { QHash<QString, EntityShape> toReturn; addEntityShape(toReturn, EntityShape::Triangle); addEntityShape(toReturn, EntityShape::Quad); addEntityShape(toReturn, EntityShape::Hexagon); addEntityShape(toReturn, EntityShape::Octagon); addEntityShape(toReturn, EntityShape::Circle); addEntityShape(toReturn, EntityShape::Cube); addEntityShape(toReturn, EntityShape::Sphere); addEntityShape(toReturn, EntityShape::Tetrahedron); addEntityShape(toReturn, EntityShape::Octahedron); addEntityShape(toReturn, EntityShape::Dodecahedron); addEntityShape(toReturn, EntityShape::Icosahedron); addEntityShape(toReturn, EntityShape::Torus); addEntityShape(toReturn, EntityShape::Cone); addEntityShape(toReturn, EntityShape::Cylinder); return toReturn;}();QString EntityItemProperties::getShapeAsString() const { return EntityShapeHelpers::getNameForEntityShape(_shape); }void EntityItemProperties::setShapeFromString(const QString& shapeName) { auto shapeItr = stringToEntityShapeLookup.find(shapeName); if (shapeItr != stringToEntityShapeLookup.end()) { _shape = shapeItr.value(); _shapeChanged = true; }} inline void addShapeType(QHash<QString, ShapeType>& lookup, ShapeType type) { lookup[ShapeInfo::getNameForShapeType(type)] = type; }QHash<QString, ShapeType> stringToShapeTypeLookup = [] { QHash<QString, ShapeType> toReturn; addShapeType(toReturn, SHAPE_TYPE_NONE); addShapeType(toReturn, SHAPE_TYPE_BOX); addShapeType(toReturn, SHAPE_TYPE_SPHERE); addShapeType(toReturn, SHAPE_TYPE_CAPSULE_X); addShapeType(toReturn, SHAPE_TYPE_CAPSULE_Y); addShapeType(toReturn, SHAPE_TYPE_CAPSULE_Z); addShapeType(toReturn, SHAPE_TYPE_CYLINDER_X); addShapeType(toReturn, SHAPE_TYPE_CYLINDER_Y); addShapeType(toReturn, SHAPE_TYPE_CYLINDER_Z); addShapeType(toReturn, SHAPE_TYPE_HULL); addShapeType(toReturn, SHAPE_TYPE_PLANE); addShapeType(toReturn, SHAPE_TYPE_COMPOUND); addShapeType(toReturn, SHAPE_TYPE_SIMPLE_HULL); addShapeType(toReturn, SHAPE_TYPE_SIMPLE_COMPOUND); addShapeType(toReturn, SHAPE_TYPE_STATIC_MESH); addShapeType(toReturn, SHAPE_TYPE_ELLIPSOID); addShapeType(toReturn, SHAPE_TYPE_CIRCLE); return toReturn;}();QString EntityItemProperties::getShapeTypeAsString() const { return ShapeInfo::getNameForShapeType(_shapeType); }void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) { auto shapeTypeItr = stringToShapeTypeLookup.find(shapeName.toLower()); if (shapeTypeItr != stringToShapeTypeLookup.end()) { _shapeType = shapeTypeItr.value(); _shapeTypeChanged = true; }} inline void addMaterialMappingMode(QHash<QString, MaterialMappingMode>& lookup, MaterialMappingMode mode) { lookup[MaterialMappingModeHelpers::getNameForMaterialMappingMode(mode)] = mode; }const QHash<QString, MaterialMappingMode> stringToMaterialMappingModeLookup = [] { QHash<QString, MaterialMappingMode> toReturn; addMaterialMappingMode(toReturn, UV); addMaterialMappingMode(toReturn, PROJECTED); addMaterialMappingMode(toReturn, TRIPLANAR); return toReturn;}();QString EntityItemProperties::getMaterialMappingModeAsString() const { return MaterialMappingModeHelpers::getNameForMaterialMappingMode(_materialMappingMode); }void EntityItemProperties::setMaterialMappingModeFromString(const QString& materialMappingMode) { auto materialMappingModeItr = stringToMaterialMappingModeLookup.find(materialMappingMode.toLower()); if (materialMappingModeItr != stringToMaterialMappingModeLookup.end()) { _materialMappingMode = materialMappingModeItr.value(); _materialMappingModeChanged = true; }} inline void addBillboardMode(QHash<QString, BillboardMode>& lookup, BillboardMode mode) { lookup[BillboardModeHelpers::getNameForBillboardMode(mode)] = mode; }const QHash<QString, BillboardMode> stringToBillboardModeLookup = [] { QHash<QString, BillboardMode> toReturn; addBillboardMode(toReturn, BillboardMode::NONE); addBillboardMode(toReturn, BillboardMode::YAW); addBillboardMode(toReturn, BillboardMode::FULL); return toReturn;}();QString EntityItemProperties::getBillboardModeAsString() const { return BillboardModeHelpers::getNameForBillboardMode(_billboardMode); }void EntityItemProperties::setBillboardModeFromString(const QString& billboardMode) { auto billboardModeItr = stringToBillboardModeLookup.find(billboardMode.toLower()); if (billboardModeItr != stringToBillboardModeLookup.end()) { _billboardMode = billboardModeItr.value(); _billboardModeChanged = true; }} inline void addRenderLayer(QHash<QString, RenderLayer>& lookup, RenderLayer mode) { lookup[RenderLayerHelpers::getNameForRenderLayer(mode)] = mode; }const QHash<QString, RenderLayer> stringToRenderLayerLookup = [] { QHash<QString, RenderLayer> toReturn; addRenderLayer(toReturn, RenderLayer::WORLD); addRenderLayer(toReturn, RenderLayer::FRONT); addRenderLayer(toReturn, RenderLayer::HUD); return toReturn;}();QString EntityItemProperties::getRenderLayerAsString() const { return RenderLayerHelpers::getNameForRenderLayer(_renderLayer); }void EntityItemProperties::setRenderLayerFromString(const QString& renderLayer) { auto renderLayerItr = stringToRenderLayerLookup.find(renderLayer.toLower()); if (renderLayerItr != stringToRenderLayerLookup.end()) { _renderLayer = renderLayerItr.value(); _renderLayerChanged = true; }} inline void addPrimitiveMode(QHash<QString, PrimitiveMode>& lookup, PrimitiveMode mode) { lookup[PrimitiveModeHelpers::getNameForPrimitiveMode(mode)] = mode; }const QHash<QString, PrimitiveMode> stringToPrimitiveModeLookup = [] { QHash<QString, PrimitiveMode> toReturn; addPrimitiveMode(toReturn, PrimitiveMode::SOLID); addPrimitiveMode(toReturn, PrimitiveMode::LINES); return toReturn;}();QString EntityItemProperties::getPrimitiveModeAsString() const { return PrimitiveModeHelpers::getNameForPrimitiveMode(_primitiveMode); }void EntityItemProperties::setPrimitiveModeFromString(const QString& primitiveMode) { auto primitiveModeItr = stringToPrimitiveModeLookup.find(primitiveMode.toLower()); if (primitiveModeItr != stringToPrimitiveModeLookup.end()) { _primitiveMode = primitiveModeItr.value(); _primitiveModeChanged = true; }} inline void addWebInputMode(QHash<QString, WebInputMode>& lookup, WebInputMode mode) { lookup[WebInputModeHelpers::getNameForWebInputMode(mode)] = mode; }const QHash<QString, WebInputMode> stringToWebInputModeLookup = [] { QHash<QString, WebInputMode> toReturn; addWebInputMode(toReturn, WebInputMode::TOUCH); addWebInputMode(toReturn, WebInputMode::MOUSE); return toReturn;}();QString EntityItemProperties::getInputModeAsString() const { return WebInputModeHelpers::getNameForWebInputMode(_inputMode); }void EntityItemProperties::setInputModeFromString(const QString& webInputMode) { auto webInputModeItr = stringToWebInputModeLookup.find(webInputMode.toLower()); if (webInputModeItr != stringToWebInputModeLookup.end()) { _inputMode = webInputModeItr.value(); _inputModeChanged = true; }} inline void addGizmoType(QHash<QString, GizmoType>& lookup, GizmoType mode) { lookup[GizmoTypeHelpers::getNameForGizmoType(mode)] = mode; }const QHash<QString, GizmoType> stringToGizmoTypeLookup = [] { QHash<QString, GizmoType> toReturn; addGizmoType(toReturn, GizmoType::RING); return toReturn;}();QString EntityItemProperties::getGizmoTypeAsString() const { return GizmoTypeHelpers::getNameForGizmoType(_gizmoType); }void EntityItemProperties::setGizmoTypeFromString(const QString& gizmoType) { auto gizmoTypeItr = stringToGizmoTypeLookup.find(gizmoType.toLower()); if (gizmoTypeItr != stringToGizmoTypeLookup.end()) { _gizmoType = gizmoTypeItr.value(); _gizmoTypeChanged = true; }} inline void addComponentMode(QHash<QString, ComponentMode>& lookup, ComponentMode mode) { lookup[ComponentModeHelpers::getNameForComponentMode(mode)] = mode; }const QHash<QString, ComponentMode> stringToComponentMode = [] { QHash<QString, ComponentMode> toReturn; addComponentMode(toReturn, ComponentMode::COMPONENT_MODE_INHERIT); addComponentMode(toReturn, ComponentMode::COMPONENT_MODE_DISABLED); addComponentMode(toReturn, ComponentMode::COMPONENT_MODE_ENABLED); return toReturn;}();QString EntityItemProperties::getComponentModeAsString(uint8_t mode) { return ComponentModeHelpers::getNameForComponentMode((ComponentMode)mode); }QString EntityItemProperties::getSkyboxModeAsString() const { return getComponentModeAsString(_skyboxMode); }QString EntityItemProperties::getFadeInModeAsString() const { return getComponentModeAsString(_fadeInMode); }QString EntityItemProperties::getFadeOutModeAsString() const { return getComponentModeAsString(_fadeOutMode); }QString EntityItemProperties::getAvatarFadeInModeAsString() const { return getComponentModeAsString(_avatarFadeInMode); }QString EntityItemProperties::getAvatarFadeOutModeAsString() const { return getComponentModeAsString(_avatarFadeOutMode); }QString EntityItemProperties::getKeyLightModeAsString() const { return getComponentModeAsString(_keyLightMode); }QString EntityItemProperties::getAmbientLightModeAsString() const { return getComponentModeAsString(_ambientLightMode); }QString EntityItemProperties::getHazeModeAsString() const { return getComponentModeAsString(_hazeMode); }QString EntityItemProperties::getBloomModeAsString() const { return getComponentModeAsString(_bloomMode); }QString EntityItemProperties::getTonemappingModeAsString() const { return getComponentModeAsString(_tonemappingMode); }QString EntityItemProperties::getAmbientOcclusionModeAsString() const { return getComponentModeAsString(_ambientOcclusionMode); }QString EntityItemProperties::getNormalMapAttenuationModeAsString() const { return getComponentModeAsString(_normalMapAttenuationMode); }void EntityItemProperties::setFadeInModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _fadeInMode = modeItr.value(); _fadeInModeChanged = true; }}void EntityItemProperties::setFadeOutModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _fadeOutMode = modeItr.value(); _fadeOutModeChanged = true; }}void EntityItemProperties::setAvatarFadeInModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _avatarFadeInMode = modeItr.value(); _avatarFadeInModeChanged = true; }}void EntityItemProperties::setAvatarFadeOutModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _avatarFadeOutMode = modeItr.value(); _avatarFadeOutModeChanged = true; }}void EntityItemProperties::setSkyboxModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _skyboxMode = modeItr.value(); _skyboxModeChanged = true; }}void EntityItemProperties::setKeyLightModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _keyLightMode = modeItr.value(); _keyLightModeChanged = true; }}void EntityItemProperties::setAmbientLightModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _ambientLightMode = modeItr.value(); _ambientLightModeChanged = true; }}void EntityItemProperties::setHazeModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _hazeMode = modeItr.value(); _hazeModeChanged = true; }}void EntityItemProperties::setBloomModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _bloomMode = modeItr.value(); _bloomModeChanged = true; }}void EntityItemProperties::setTonemappingModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _tonemappingMode = modeItr.value(); _tonemappingModeChanged = true; }}void EntityItemProperties::setAmbientOcclusionModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _ambientOcclusionMode = modeItr.value(); _ambientOcclusionModeChanged = true; }}void EntityItemProperties::setNormalMapAttenuationModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _normalMapAttenuationMode = modeItr.value(); _normalMapAttenuationModeChanged = true; }} inline void addAvatarPriorityMode(QHash<QString, AvatarPriorityMode>& lookup, AvatarPriorityMode mode) { lookup[AvatarPriorityModeHelpers::getNameForAvatarPriorityMode(mode)] = mode; }const QHash<QString, AvatarPriorityMode> stringToAvatarPriority = [] { QHash<QString, AvatarPriorityMode> toReturn; addAvatarPriorityMode(toReturn, AvatarPriorityMode::AVATAR_PRIORITY_INHERIT); addAvatarPriorityMode(toReturn, AvatarPriorityMode::AVATAR_PRIORITY_CROWD); addAvatarPriorityMode(toReturn, AvatarPriorityMode::AVATAR_PRIORITY_HERO); return toReturn;}();QString EntityItemProperties::getAvatarPriorityAsString() const { return AvatarPriorityModeHelpers::getNameForAvatarPriorityMode((AvatarPriorityMode)_avatarPriority); }void EntityItemProperties::setAvatarPriorityFromString(const QString& mode) { auto modeItr = stringToAvatarPriority.find(mode.toLower()); if (modeItr != stringToAvatarPriority.end()) { _avatarPriority = modeItr.value(); _avatarPriorityChanged = true; }} inline void addTextEffect(QHash<QString, TextEffect>& lookup, TextEffect effect) { lookup[TextEffectHelpers::getNameForTextEffect(effect)] = effect; }const QHash<QString, TextEffect> stringToTextEffectLookup = [] { QHash<QString, TextEffect> toReturn; addTextEffect(toReturn, TextEffect::NO_EFFECT); addTextEffect(toReturn, TextEffect::OUTLINE_EFFECT); addTextEffect(toReturn, TextEffect::OUTLINE_WITH_FILL_EFFECT); addTextEffect(toReturn, TextEffect::SHADOW_EFFECT); return toReturn;}();QString EntityItemProperties::getTextEffectAsString() const { return TextEffectHelpers::getNameForTextEffect(_textEffect); }void EntityItemProperties::setTextEffectFromString(const QString& effect) { auto textEffectItr = stringToTextEffectLookup.find(effect.toLower()); if (textEffectItr != stringToTextEffectLookup.end()) { _textEffect = textEffectItr.value(); _textEffectChanged = true; }} inline void addTextAlignment(QHash<QString, TextAlignment>& lookup, TextAlignment alignment) { lookup[TextAlignmentHelpers::getNameForTextAlignment(alignment)] = alignment; }const QHash<QString, TextAlignment> stringToTextAlignmentLookup = [] { QHash<QString, TextAlignment> toReturn; addTextAlignment(toReturn, TextAlignment::LEFT); addTextAlignment(toReturn, TextAlignment::CENTER); addTextAlignment(toReturn, TextAlignment::RIGHT); return toReturn;}();QString EntityItemProperties::getAlignmentAsString() const { return TextAlignmentHelpers::getNameForTextAlignment(_alignment); }void EntityItemProperties::setAlignmentFromString(const QString& alignment) { auto textAlignmentItr = stringToTextAlignmentLookup.find(alignment.toLower()); if (textAlignmentItr != stringToTextAlignmentLookup.end()) { _alignment = textAlignmentItr.value(); _alignmentChanged = true; }} inline void addTextVerticalAlignment(QHash<QString, TextVerticalAlignment>& lookup, TextVerticalAlignment verticalAlignment) { lookup[TextVerticalAlignmentHelpers::getNameForTextVerticalAlignment(verticalAlignment)] = verticalAlignment; }const QHash<QString, TextVerticalAlignment> stringToTextVerticalAlignmentLookup = [] { QHash<QString, TextVerticalAlignment> toReturn; addTextVerticalAlignment(toReturn, TextVerticalAlignment::TOP); addTextVerticalAlignment(toReturn, TextVerticalAlignment::BOTTOM); addTextVerticalAlignment(toReturn, TextVerticalAlignment::CENTER); return toReturn;}();QString EntityItemProperties::getVerticalAlignmentAsString() const { return TextVerticalAlignmentHelpers::getNameForTextVerticalAlignment(_verticalAlignment); }void EntityItemProperties::setVerticalAlignmentFromString(const QString& verticalAlignment) { auto textVerticalAlignmentItr = stringToTextVerticalAlignmentLookup.find(verticalAlignment.toLower()); if (textVerticalAlignmentItr != stringToTextVerticalAlignmentLookup.end()) { _verticalAlignment = textVerticalAlignmentItr.value(); _verticalAlignmentChanged = true; }} QString getCollisionGroupAsString(uint16_t group) { switch (group) { case USER_COLLISION_GROUP_DYNAMIC: return "dynamic"; case USER_COLLISION_GROUP_STATIC: return "static"; case USER_COLLISION_GROUP_KINEMATIC: return "kinematic"; case USER_COLLISION_GROUP_MY_AVATAR: return "myAvatar"; case USER_COLLISION_GROUP_OTHER_AVATAR: return "otherAvatar"; }; return "";} uint16_t getCollisionGroupAsBitMask(const QStringRef& name) { if (0 == name.compare(QString("dynamic"))) { return USER_COLLISION_GROUP_DYNAMIC; } else if (0 == name.compare(QString("static"))) { return USER_COLLISION_GROUP_STATIC; } else if (0 == name.compare(QString("kinematic"))) { return USER_COLLISION_GROUP_KINEMATIC; } else if (0 == name.compare(QString("myAvatar"))) { return USER_COLLISION_GROUP_MY_AVATAR; } else if (0 == name.compare(QString("otherAvatar"))) { return USER_COLLISION_GROUP_OTHER_AVATAR; } return 0;} QString EntityItemProperties::getCollisionMaskAsString() const { QString maskString(""); for (int i = 0; i < NUM_USER_COLLISION_GROUPS; ++i) { uint16_t group = 0x0001 << i; if (group & _collisionMask) { maskString.append(getCollisionGroupAsString(group)); maskString.append(','); } } return maskString;} void EntityItemProperties::setCollisionMaskFromString(const QString& maskString) { QVector<QStringRef> groups = maskString.splitRef(','); uint16_t mask = 0x0000; for (auto groupName : groups) { mask |= getCollisionGroupAsBitMask(groupName); } _collisionMask = mask; _collisionMaskChanged = true;} QString EntityItemProperties::getEntityHostTypeAsString() const { switch (_entityHostType) { case entity::HostType::DOMAIN: return "domain"; case entity::HostType::AVATAR: return "avatar"; case entity::HostType::LOCAL: return "local"; default: return ""; }} void EntityItemProperties::setEntityHostTypeFromString(const QString& entityHostType) { if (entityHostType == "domain") { _entityHostType = entity::HostType::DOMAIN; } else if (entityHostType == "avatar") { _entityHostType = entity::HostType::AVATAR; } else if (entityHostType == "local") { _entityHostType = entity::HostType::LOCAL;Lines 1–500 of 1495. Load more
// // EntityItemProperties.cpp // libraries/entities/src // // Created by Brad Hefta-Gaub on 12/4/13. // Copyright 2013 High Fidelity, Inc. // Copyright 2020 Vircadia contributors. // Copyright 2022-2023 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // SPDX-License-Identifier: Apache-2.0 // #include "EntityItemProperties.h" #include <openssl/err.h> #include <openssl/pem.h> #include <openssl/x509.h> #include <openssl/ecdsa.h> #include <QDebug> #include <QHash> #include <QObject> #include <QtCore/QJsonDocument> #include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkRequest> #include <NetworkAccessManager.h> #include <ByteCountCoding.h> #include <GLMHelpers.h> #include <RegisteredMetaTypes.h> #include <Extents.h> #include <VariantMapToScriptValue.h> #include <ScriptValue.h> #include <PhysicsHelpers.h> #include "EntitiesLogging.h" #include "WarningsSuppression.h" @ENTITY_ITEM_PROPERTY_STATIC_GROUPS@ EntityPropertyList PROP_LAST_ITEM = (EntityPropertyList)(PROP_AFTER_LAST_ITEM - 1); EntityItemProperties::EntityItemProperties(EntityPropertyFlags desiredProperties) : _id(UNKNOWN_ENTITY_ID), _idSet(false), _lastEdited(0), _type(EntityTypes::Unknown), _defaultSettings(true), _naturalDimensions(1.0f, 1.0f, 1.0f), _naturalPosition(0.0f, 0.0f, 0.0f), _desiredProperties(desiredProperties) { } void EntityItemProperties::calculateNaturalPosition(const vec3& min, const vec3& max) { vec3 halfDimension = (max - min) / 2.0f; _naturalPosition = max - halfDimension; } void EntityItemProperties::debugDump() const { qCDebug(entities) << "EntityItemProperties..."; qCDebug(entities) << " _type=" << EntityTypes::getEntityTypeName(_type); qCDebug(entities) << " _id=" << _id; qCDebug(entities) << " _idSet=" << _idSet; qCDebug(entities) << " _position=" << _position.x << "," << _position.y << "," << _position.z; qCDebug(entities) << " _dimensions=" << getDimensions(); qCDebug(entities) << " _modelURL=" << _modelURL; qCDebug(entities) << " _compoundShapeURL=" << _compoundShapeURL; @ENTITY_ITEM_PROPERTY_DEBUG_DUMP_GROUPS@ qCDebug(entities) << " changed properties..."; EntityPropertyFlags props = getChangedProperties(); props.debugDumpBits(); } void EntityItemProperties::setLastEdited(quint64 usecTime) { _lastEdited = usecTime > _created ? usecTime : _created; } bool EntityItemProperties::constructFromBuffer(const unsigned char* data, int dataLength) { ReadBitstreamToTreeParams args; EntityItemPointer tempEntity = EntityTypes::constructEntityItem(data, dataLength); if (!tempEntity) { return false; } tempEntity->readEntityDataFromBuffer(data, dataLength, args); (*this) = tempEntity->getProperties(); return true; } inline void addEntityShape(QHash<QString, EntityShape>& lookup, EntityShape type) { lookup[EntityShapeHelpers::getNameForEntityShape(type)] = type; } QHash<QString, EntityShape> stringToEntityShapeLookup = [] { QHash<QString, EntityShape> toReturn; addEntityShape(toReturn, EntityShape::Triangle); addEntityShape(toReturn, EntityShape::Quad); addEntityShape(toReturn, EntityShape::Hexagon); addEntityShape(toReturn, EntityShape::Octagon); addEntityShape(toReturn, EntityShape::Circle); addEntityShape(toReturn, EntityShape::Cube); addEntityShape(toReturn, EntityShape::Sphere); addEntityShape(toReturn, EntityShape::Tetrahedron); addEntityShape(toReturn, EntityShape::Octahedron); addEntityShape(toReturn, EntityShape::Dodecahedron); addEntityShape(toReturn, EntityShape::Icosahedron); addEntityShape(toReturn, EntityShape::Torus); addEntityShape(toReturn, EntityShape::Cone); addEntityShape(toReturn, EntityShape::Cylinder); return toReturn; }(); QString EntityItemProperties::getShapeAsString() const { return EntityShapeHelpers::getNameForEntityShape(_shape); } void EntityItemProperties::setShapeFromString(const QString& shapeName) { auto shapeItr = stringToEntityShapeLookup.find(shapeName); if (shapeItr != stringToEntityShapeLookup.end()) { _shape = shapeItr.value(); _shapeChanged = true; } } inline void addShapeType(QHash<QString, ShapeType>& lookup, ShapeType type) { lookup[ShapeInfo::getNameForShapeType(type)] = type; } QHash<QString, ShapeType> stringToShapeTypeLookup = [] { QHash<QString, ShapeType> toReturn; addShapeType(toReturn, SHAPE_TYPE_NONE); addShapeType(toReturn, SHAPE_TYPE_BOX); addShapeType(toReturn, SHAPE_TYPE_SPHERE); addShapeType(toReturn, SHAPE_TYPE_CAPSULE_X); addShapeType(toReturn, SHAPE_TYPE_CAPSULE_Y); addShapeType(toReturn, SHAPE_TYPE_CAPSULE_Z); addShapeType(toReturn, SHAPE_TYPE_CYLINDER_X); addShapeType(toReturn, SHAPE_TYPE_CYLINDER_Y); addShapeType(toReturn, SHAPE_TYPE_CYLINDER_Z); addShapeType(toReturn, SHAPE_TYPE_HULL); addShapeType(toReturn, SHAPE_TYPE_PLANE); addShapeType(toReturn, SHAPE_TYPE_COMPOUND); addShapeType(toReturn, SHAPE_TYPE_SIMPLE_HULL); addShapeType(toReturn, SHAPE_TYPE_SIMPLE_COMPOUND); addShapeType(toReturn, SHAPE_TYPE_STATIC_MESH); addShapeType(toReturn, SHAPE_TYPE_ELLIPSOID); addShapeType(toReturn, SHAPE_TYPE_CIRCLE); return toReturn; }(); QString EntityItemProperties::getShapeTypeAsString() const { return ShapeInfo::getNameForShapeType(_shapeType); } void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) { auto shapeTypeItr = stringToShapeTypeLookup.find(shapeName.toLower()); if (shapeTypeItr != stringToShapeTypeLookup.end()) { _shapeType = shapeTypeItr.value(); _shapeTypeChanged = true; } } inline void addMaterialMappingMode(QHash<QString, MaterialMappingMode>& lookup, MaterialMappingMode mode) { lookup[MaterialMappingModeHelpers::getNameForMaterialMappingMode(mode)] = mode; } const QHash<QString, MaterialMappingMode> stringToMaterialMappingModeLookup = [] { QHash<QString, MaterialMappingMode> toReturn; addMaterialMappingMode(toReturn, UV); addMaterialMappingMode(toReturn, PROJECTED); addMaterialMappingMode(toReturn, TRIPLANAR); return toReturn; }(); QString EntityItemProperties::getMaterialMappingModeAsString() const { return MaterialMappingModeHelpers::getNameForMaterialMappingMode(_materialMappingMode); } void EntityItemProperties::setMaterialMappingModeFromString(const QString& materialMappingMode) { auto materialMappingModeItr = stringToMaterialMappingModeLookup.find(materialMappingMode.toLower()); if (materialMappingModeItr != stringToMaterialMappingModeLookup.end()) { _materialMappingMode = materialMappingModeItr.value(); _materialMappingModeChanged = true; } } inline void addBillboardMode(QHash<QString, BillboardMode>& lookup, BillboardMode mode) { lookup[BillboardModeHelpers::getNameForBillboardMode(mode)] = mode; } const QHash<QString, BillboardMode> stringToBillboardModeLookup = [] { QHash<QString, BillboardMode> toReturn; addBillboardMode(toReturn, BillboardMode::NONE); addBillboardMode(toReturn, BillboardMode::YAW); addBillboardMode(toReturn, BillboardMode::FULL); return toReturn; }(); QString EntityItemProperties::getBillboardModeAsString() const { return BillboardModeHelpers::getNameForBillboardMode(_billboardMode); } void EntityItemProperties::setBillboardModeFromString(const QString& billboardMode) { auto billboardModeItr = stringToBillboardModeLookup.find(billboardMode.toLower()); if (billboardModeItr != stringToBillboardModeLookup.end()) { _billboardMode = billboardModeItr.value(); _billboardModeChanged = true; } } inline void addRenderLayer(QHash<QString, RenderLayer>& lookup, RenderLayer mode) { lookup[RenderLayerHelpers::getNameForRenderLayer(mode)] = mode; } const QHash<QString, RenderLayer> stringToRenderLayerLookup = [] { QHash<QString, RenderLayer> toReturn; addRenderLayer(toReturn, RenderLayer::WORLD); addRenderLayer(toReturn, RenderLayer::FRONT); addRenderLayer(toReturn, RenderLayer::HUD); return toReturn; }(); QString EntityItemProperties::getRenderLayerAsString() const { return RenderLayerHelpers::getNameForRenderLayer(_renderLayer); } void EntityItemProperties::setRenderLayerFromString(const QString& renderLayer) { auto renderLayerItr = stringToRenderLayerLookup.find(renderLayer.toLower()); if (renderLayerItr != stringToRenderLayerLookup.end()) { _renderLayer = renderLayerItr.value(); _renderLayerChanged = true; } } inline void addPrimitiveMode(QHash<QString, PrimitiveMode>& lookup, PrimitiveMode mode) { lookup[PrimitiveModeHelpers::getNameForPrimitiveMode(mode)] = mode; } const QHash<QString, PrimitiveMode> stringToPrimitiveModeLookup = [] { QHash<QString, PrimitiveMode> toReturn; addPrimitiveMode(toReturn, PrimitiveMode::SOLID); addPrimitiveMode(toReturn, PrimitiveMode::LINES); return toReturn; }(); QString EntityItemProperties::getPrimitiveModeAsString() const { return PrimitiveModeHelpers::getNameForPrimitiveMode(_primitiveMode); } void EntityItemProperties::setPrimitiveModeFromString(const QString& primitiveMode) { auto primitiveModeItr = stringToPrimitiveModeLookup.find(primitiveMode.toLower()); if (primitiveModeItr != stringToPrimitiveModeLookup.end()) { _primitiveMode = primitiveModeItr.value(); _primitiveModeChanged = true; } } inline void addWebInputMode(QHash<QString, WebInputMode>& lookup, WebInputMode mode) { lookup[WebInputModeHelpers::getNameForWebInputMode(mode)] = mode; } const QHash<QString, WebInputMode> stringToWebInputModeLookup = [] { QHash<QString, WebInputMode> toReturn; addWebInputMode(toReturn, WebInputMode::TOUCH); addWebInputMode(toReturn, WebInputMode::MOUSE); return toReturn; }(); QString EntityItemProperties::getInputModeAsString() const { return WebInputModeHelpers::getNameForWebInputMode(_inputMode); } void EntityItemProperties::setInputModeFromString(const QString& webInputMode) { auto webInputModeItr = stringToWebInputModeLookup.find(webInputMode.toLower()); if (webInputModeItr != stringToWebInputModeLookup.end()) { _inputMode = webInputModeItr.value(); _inputModeChanged = true; } } inline void addGizmoType(QHash<QString, GizmoType>& lookup, GizmoType mode) { lookup[GizmoTypeHelpers::getNameForGizmoType(mode)] = mode; } const QHash<QString, GizmoType> stringToGizmoTypeLookup = [] { QHash<QString, GizmoType> toReturn; addGizmoType(toReturn, GizmoType::RING); return toReturn; }(); QString EntityItemProperties::getGizmoTypeAsString() const { return GizmoTypeHelpers::getNameForGizmoType(_gizmoType); } void EntityItemProperties::setGizmoTypeFromString(const QString& gizmoType) { auto gizmoTypeItr = stringToGizmoTypeLookup.find(gizmoType.toLower()); if (gizmoTypeItr != stringToGizmoTypeLookup.end()) { _gizmoType = gizmoTypeItr.value(); _gizmoTypeChanged = true; } } inline void addComponentMode(QHash<QString, ComponentMode>& lookup, ComponentMode mode) { lookup[ComponentModeHelpers::getNameForComponentMode(mode)] = mode; } const QHash<QString, ComponentMode> stringToComponentMode = [] { QHash<QString, ComponentMode> toReturn; addComponentMode(toReturn, ComponentMode::COMPONENT_MODE_INHERIT); addComponentMode(toReturn, ComponentMode::COMPONENT_MODE_DISABLED); addComponentMode(toReturn, ComponentMode::COMPONENT_MODE_ENABLED); return toReturn; }(); QString EntityItemProperties::getComponentModeAsString(uint8_t mode) { return ComponentModeHelpers::getNameForComponentMode((ComponentMode)mode); } QString EntityItemProperties::getSkyboxModeAsString() const { return getComponentModeAsString(_skyboxMode); } QString EntityItemProperties::getFadeInModeAsString() const { return getComponentModeAsString(_fadeInMode); } QString EntityItemProperties::getFadeOutModeAsString() const { return getComponentModeAsString(_fadeOutMode); } QString EntityItemProperties::getAvatarFadeInModeAsString() const { return getComponentModeAsString(_avatarFadeInMode); } QString EntityItemProperties::getAvatarFadeOutModeAsString() const { return getComponentModeAsString(_avatarFadeOutMode); } QString EntityItemProperties::getKeyLightModeAsString() const { return getComponentModeAsString(_keyLightMode); } QString EntityItemProperties::getAmbientLightModeAsString() const { return getComponentModeAsString(_ambientLightMode); } QString EntityItemProperties::getHazeModeAsString() const { return getComponentModeAsString(_hazeMode); } QString EntityItemProperties::getBloomModeAsString() const { return getComponentModeAsString(_bloomMode); } QString EntityItemProperties::getTonemappingModeAsString() const { return getComponentModeAsString(_tonemappingMode); } QString EntityItemProperties::getAmbientOcclusionModeAsString() const { return getComponentModeAsString(_ambientOcclusionMode); } QString EntityItemProperties::getNormalMapAttenuationModeAsString() const { return getComponentModeAsString(_normalMapAttenuationMode); } void EntityItemProperties::setFadeInModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _fadeInMode = modeItr.value(); _fadeInModeChanged = true; } } void EntityItemProperties::setFadeOutModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _fadeOutMode = modeItr.value(); _fadeOutModeChanged = true; } } void EntityItemProperties::setAvatarFadeInModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _avatarFadeInMode = modeItr.value(); _avatarFadeInModeChanged = true; } } void EntityItemProperties::setAvatarFadeOutModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _avatarFadeOutMode = modeItr.value(); _avatarFadeOutModeChanged = true; } } void EntityItemProperties::setSkyboxModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _skyboxMode = modeItr.value(); _skyboxModeChanged = true; } } void EntityItemProperties::setKeyLightModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _keyLightMode = modeItr.value(); _keyLightModeChanged = true; } } void EntityItemProperties::setAmbientLightModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _ambientLightMode = modeItr.value(); _ambientLightModeChanged = true; } } void EntityItemProperties::setHazeModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _hazeMode = modeItr.value(); _hazeModeChanged = true; } } void EntityItemProperties::setBloomModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _bloomMode = modeItr.value(); _bloomModeChanged = true; } } void EntityItemProperties::setTonemappingModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _tonemappingMode = modeItr.value(); _tonemappingModeChanged = true; } } void EntityItemProperties::setAmbientOcclusionModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _ambientOcclusionMode = modeItr.value(); _ambientOcclusionModeChanged = true; } } void EntityItemProperties::setNormalMapAttenuationModeFromString(const QString& mode) { auto modeItr = stringToComponentMode.find(mode.toLower()); if (modeItr != stringToComponentMode.end()) { _normalMapAttenuationMode = modeItr.value(); _normalMapAttenuationModeChanged = true; } } inline void addAvatarPriorityMode(QHash<QString, AvatarPriorityMode>& lookup, AvatarPriorityMode mode) { lookup[AvatarPriorityModeHelpers::getNameForAvatarPriorityMode(mode)] = mode; } const QHash<QString, AvatarPriorityMode> stringToAvatarPriority = [] { QHash<QString, AvatarPriorityMode> toReturn; addAvatarPriorityMode(toReturn, AvatarPriorityMode::AVATAR_PRIORITY_INHERIT); addAvatarPriorityMode(toReturn, AvatarPriorityMode::AVATAR_PRIORITY_CROWD); addAvatarPriorityMode(toReturn, AvatarPriorityMode::AVATAR_PRIORITY_HERO); return toReturn; }(); QString EntityItemProperties::getAvatarPriorityAsString() const { return AvatarPriorityModeHelpers::getNameForAvatarPriorityMode((AvatarPriorityMode)_avatarPriority); } void EntityItemProperties::setAvatarPriorityFromString(const QString& mode) { auto modeItr = stringToAvatarPriority.find(mode.toLower()); if (modeItr != stringToAvatarPriority.end()) { _avatarPriority = modeItr.value(); _avatarPriorityChanged = true; } } inline void addTextEffect(QHash<QString, TextEffect>& lookup, TextEffect effect) { lookup[TextEffectHelpers::getNameForTextEffect(effect)] = effect; } const QHash<QString, TextEffect> stringToTextEffectLookup = [] { QHash<QString, TextEffect> toReturn; addTextEffect(toReturn, TextEffect::NO_EFFECT); addTextEffect(toReturn, TextEffect::OUTLINE_EFFECT); addTextEffect(toReturn, TextEffect::OUTLINE_WITH_FILL_EFFECT); addTextEffect(toReturn, TextEffect::SHADOW_EFFECT); return toReturn; }(); QString EntityItemProperties::getTextEffectAsString() const { return TextEffectHelpers::getNameForTextEffect(_textEffect); } void EntityItemProperties::setTextEffectFromString(const QString& effect) { auto textEffectItr = stringToTextEffectLookup.find(effect.toLower()); if (textEffectItr != stringToTextEffectLookup.end()) { _textEffect = textEffectItr.value(); _textEffectChanged = true; } } inline void addTextAlignment(QHash<QString, TextAlignment>& lookup, TextAlignment alignment) { lookup[TextAlignmentHelpers::getNameForTextAlignment(alignment)] = alignment; } const QHash<QString, TextAlignment> stringToTextAlignmentLookup = [] { QHash<QString, TextAlignment> toReturn; addTextAlignment(toReturn, TextAlignment::LEFT); addTextAlignment(toReturn, TextAlignment::CENTER); addTextAlignment(toReturn, TextAlignment::RIGHT); return toReturn; }(); QString EntityItemProperties::getAlignmentAsString() const { return TextAlignmentHelpers::getNameForTextAlignment(_alignment); } void EntityItemProperties::setAlignmentFromString(const QString& alignment) { auto textAlignmentItr = stringToTextAlignmentLookup.find(alignment.toLower()); if (textAlignmentItr != stringToTextAlignmentLookup.end()) { _alignment = textAlignmentItr.value(); _alignmentChanged = true; } } inline void addTextVerticalAlignment(QHash<QString, TextVerticalAlignment>& lookup, TextVerticalAlignment verticalAlignment) { lookup[TextVerticalAlignmentHelpers::getNameForTextVerticalAlignment(verticalAlignment)] = verticalAlignment; } const QHash<QString, TextVerticalAlignment> stringToTextVerticalAlignmentLookup = [] { QHash<QString, TextVerticalAlignment> toReturn; addTextVerticalAlignment(toReturn, TextVerticalAlignment::TOP); addTextVerticalAlignment(toReturn, TextVerticalAlignment::BOTTOM); addTextVerticalAlignment(toReturn, TextVerticalAlignment::CENTER); return toReturn; }(); QString EntityItemProperties::getVerticalAlignmentAsString() const { return TextVerticalAlignmentHelpers::getNameForTextVerticalAlignment(_verticalAlignment); } void EntityItemProperties::setVerticalAlignmentFromString(const QString& verticalAlignment) { auto textVerticalAlignmentItr = stringToTextVerticalAlignmentLookup.find(verticalAlignment.toLower()); if (textVerticalAlignmentItr != stringToTextVerticalAlignmentLookup.end()) { _verticalAlignment = textVerticalAlignmentItr.value(); _verticalAlignmentChanged = true; } } QString getCollisionGroupAsString(uint16_t group) { switch (group) { case USER_COLLISION_GROUP_DYNAMIC: return "dynamic"; case USER_COLLISION_GROUP_STATIC: return "static"; case USER_COLLISION_GROUP_KINEMATIC: return "kinematic"; case USER_COLLISION_GROUP_MY_AVATAR: return "myAvatar"; case USER_COLLISION_GROUP_OTHER_AVATAR: return "otherAvatar"; }; return ""; } uint16_t getCollisionGroupAsBitMask(const QStringRef& name) { if (0 == name.compare(QString("dynamic"))) { return USER_COLLISION_GROUP_DYNAMIC; } else if (0 == name.compare(QString("static"))) { return USER_COLLISION_GROUP_STATIC; } else if (0 == name.compare(QString("kinematic"))) { return USER_COLLISION_GROUP_KINEMATIC; } else if (0 == name.compare(QString("myAvatar"))) { return USER_COLLISION_GROUP_MY_AVATAR; } else if (0 == name.compare(QString("otherAvatar"))) { return USER_COLLISION_GROUP_OTHER_AVATAR; } return 0; } QString EntityItemProperties::getCollisionMaskAsString() const { QString maskString(""); for (int i = 0; i < NUM_USER_COLLISION_GROUPS; ++i) { uint16_t group = 0x0001 << i; if (group & _collisionMask) { maskString.append(getCollisionGroupAsString(group)); maskString.append(','); } } return maskString; } void EntityItemProperties::setCollisionMaskFromString(const QString& maskString) { QVector<QStringRef> groups = maskString.splitRef(','); uint16_t mask = 0x0000; for (auto groupName : groups) { mask |= getCollisionGroupAsBitMask(groupName); } _collisionMask = mask; _collisionMaskChanged = true; } QString EntityItemProperties::getEntityHostTypeAsString() const { switch (_entityHostType) { case entity::HostType::DOMAIN: return "domain"; case entity::HostType::AVATAR: return "avatar"; case entity::HostType::LOCAL: return "local"; default: return ""; } } void EntityItemProperties::setEntityHostTypeFromString(const QString& entityHostType) { if (entityHostType == "domain") { _entityHostType = entity::HostType::DOMAIN; } else if (entityHostType == "avatar") { _entityHostType = entity::HostType::AVATAR; } else if (entityHostType == "local") { _entityHostType = entity::HostType::LOCAL;