From 6fa62ce26ffc843bd8edd0d1e52338ff1b310246 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Sat, 7 May 2016 18:42:43 -0700 Subject: [PATCH 01/45] Working on OSX Rift functionality --- .../display-plugins/OpenGLDisplayPlugin.cpp | 18 +-- .../src/display-plugins/OpenGLDisplayPlugin.h | 1 + .../display-plugins/hmd/HmdDisplayPlugin.cpp | 21 ++-- libraries/gl/src/gl/QOpenGLContextWrapper.cpp | 13 ++- libraries/gl/src/gl/QOpenGLContextWrapper.h | 3 + plugins/oculusLegacy/CMakeLists.txt | 8 +- .../src/OculusLegacyDisplayPlugin.cpp | 104 ++++++++++++++---- .../src/OculusLegacyDisplayPlugin.h | 31 +++--- 8 files changed, 144 insertions(+), 55 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 7d4eebb7a2..a0b6ae3939 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -237,12 +237,6 @@ bool OpenGLDisplayPlugin::activate() { _vsyncSupported = _container->getPrimaryWidget()->isVsyncSupported(); - // Child classes may override this in order to do things like initialize - // libraries, etc - if (!internalActivate()) { - return false; - } - #if THREADED_PRESENT // Start the present thread if necessary @@ -258,8 +252,18 @@ bool OpenGLDisplayPlugin::activate() { // Start execution presentThread->start(); } + _presentThread = presentThread.data(); +#endif + + // Child classes may override this in order to do things like initialize + // libraries, etc + if (!internalActivate()) { + return false; + } - // This should not return until the new context has been customized +#if THREADED_PRESENT + + // This should not return until the new context has been customized // and the old context (if any) has been uncustomized presentThread->setNewDisplayPlugin(this); #else diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index defa57fc58..c87ff1bc93 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -103,6 +103,7 @@ protected: virtual void updateFrameData(); + QThread* _presentThread{ nullptr }; ProgramPtr _program; int32_t _mvpUniform { -1 }; int32_t _alphaUniform { -1 }; diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 79b50a7f88..372337ae4d 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -63,7 +63,7 @@ bool HmdDisplayPlugin::internalActivate() { } -static const char * REPROJECTION_VS = R"VS(#version 450 core +static const char * REPROJECTION_VS = R"VS(#version 410 core in vec3 Position; in vec2 TexCoord; @@ -78,15 +78,15 @@ void main() { )VS"; -static const GLint REPROJECTION_MATRIX_LOCATION = 0; -static const GLint INVERSE_PROJECTION_MATRIX_LOCATION = 4; -static const GLint PROJECTION_MATRIX_LOCATION = 12; -static const char * REPROJECTION_FS = R"FS(#version 450 core +static GLint REPROJECTION_MATRIX_LOCATION = -1; +static GLint INVERSE_PROJECTION_MATRIX_LOCATION = -1; +static GLint PROJECTION_MATRIX_LOCATION = -1; +static const char * REPROJECTION_FS = R"FS(#version 410 core uniform sampler2D sampler; -layout (location = 0) uniform mat3 reprojection = mat3(1); -layout (location = 4) uniform mat4 inverseProjections[2]; -layout (location = 12) uniform mat4 projections[2]; +uniform mat3 reprojection = mat3(1); +uniform mat4 inverseProjections[2]; +uniform mat4 projections[2]; in vec2 vTexCoord; in vec3 vPosition; @@ -205,6 +205,11 @@ void HmdDisplayPlugin::customizeContext() { _enablePreview = !isVsyncEnabled(); _sphereSection = loadSphereSection(_program, CompositorHelper::VIRTUAL_UI_TARGET_FOV.y, CompositorHelper::VIRTUAL_UI_ASPECT_RATIO); compileProgram(_reprojectionProgram, REPROJECTION_VS, REPROJECTION_FS); + + using namespace oglplus; + REPROJECTION_MATRIX_LOCATION = Uniform(*_reprojectionProgram, "reprojection").Location(); + INVERSE_PROJECTION_MATRIX_LOCATION = Uniform(*_reprojectionProgram, "inverseProjections").Location(); + PROJECTION_MATRIX_LOCATION = Uniform(*_reprojectionProgram, "projections").Location(); } void HmdDisplayPlugin::uncustomizeContext() { diff --git a/libraries/gl/src/gl/QOpenGLContextWrapper.cpp b/libraries/gl/src/gl/QOpenGLContextWrapper.cpp index 185fdaf7f4..8c9a1ba113 100644 --- a/libraries/gl/src/gl/QOpenGLContextWrapper.cpp +++ b/libraries/gl/src/gl/QOpenGLContextWrapper.cpp @@ -17,8 +17,15 @@ QOpenGLContext* QOpenGLContextWrapper::currentContext() { return QOpenGLContext::currentContext(); } + QOpenGLContextWrapper::QOpenGLContextWrapper() : - _context(new QOpenGLContext) +_context(new QOpenGLContext) +{ +} + + +QOpenGLContextWrapper::QOpenGLContextWrapper(QOpenGLContext* context) : + _context(context) { } @@ -50,3 +57,7 @@ bool isCurrentContext(QOpenGLContext* context) { return QOpenGLContext::currentContext() == context; } +void QOpenGLContextWrapper::moveToThread(QThread* thread) { + _context->moveToThread(thread); +} + diff --git a/libraries/gl/src/gl/QOpenGLContextWrapper.h b/libraries/gl/src/gl/QOpenGLContextWrapper.h index 09f1d67280..33cc0b25e9 100644 --- a/libraries/gl/src/gl/QOpenGLContextWrapper.h +++ b/libraries/gl/src/gl/QOpenGLContextWrapper.h @@ -15,16 +15,19 @@ class QOpenGLContext; class QSurface; class QSurfaceFormat; +class QThread; class QOpenGLContextWrapper { public: QOpenGLContextWrapper(); + QOpenGLContextWrapper(QOpenGLContext* context); void setFormat(const QSurfaceFormat& format); bool create(); void swapBuffers(QSurface* surface); bool makeCurrent(QSurface* surface); void doneCurrent(); void setShareContext(QOpenGLContext* otherContext); + void moveToThread(QThread* thread); static QOpenGLContext* currentContext(); diff --git a/plugins/oculusLegacy/CMakeLists.txt b/plugins/oculusLegacy/CMakeLists.txt index 9e97b3791c..a4e00013f1 100644 --- a/plugins/oculusLegacy/CMakeLists.txt +++ b/plugins/oculusLegacy/CMakeLists.txt @@ -12,13 +12,17 @@ if (APPLE) set(TARGET_NAME oculusLegacy) setup_hifi_plugin() - link_hifi_libraries(shared gl gpu plugins display-plugins input-plugins) + link_hifi_libraries(shared gl gpu plugins ui display-plugins input-plugins) include_hifi_library_headers(octree) add_dependency_external_projects(LibOVR) find_package(LibOVR REQUIRED) target_include_directories(${TARGET_NAME} PRIVATE ${LIBOVR_INCLUDE_DIRS}) - target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES}) + find_library(COCOA_LIBRARY Cocoa) + find_library(IOKIT_LIBRARY IOKit) + target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES} ${COCOA_LIBRARY} ${IOKIT_LIBRARY}) + + endif() diff --git a/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp b/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp index 34e36d6a6b..6ceddec11b 100644 --- a/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp +++ b/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.cpp @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -16,7 +17,12 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include @@ -39,7 +45,7 @@ void OculusLegacyDisplayPlugin::beginFrameRender(uint32_t frameIndex) { _currentRenderFrameInfo = FrameInfo(); _currentRenderFrameInfo.predictedDisplayTime = _currentRenderFrameInfo.sensorSampleTime = ovr_GetTimeInSeconds(); _trackingState = ovrHmd_GetTrackingState(_hmd, _currentRenderFrameInfo.predictedDisplayTime); - _currentRenderFrameInfo.renderPose = toGlm(_trackingState.HeadPose.ThePose); + _currentRenderFrameInfo.rawRenderPose = _currentRenderFrameInfo.renderPose = toGlm(_trackingState.HeadPose.ThePose); Lock lock(_mutex); _frameInfos[frameIndex] = _currentRenderFrameInfo; } @@ -72,14 +78,34 @@ bool OculusLegacyDisplayPlugin::isSupported() const { } bool OculusLegacyDisplayPlugin::internalActivate() { - Parent::internalActivate(); - + if (!Parent::internalActivate()) { + return false; + } + if (!(ovr_Initialize(nullptr))) { Q_ASSERT(false); qFatal("Failed to Initialize SDK"); return false; } + + _hmdWindow = new GLWindow(); + _hmdWindow->create(); + _hmdWindow->createContext(_container->getPrimaryContext()); + auto hmdScreen = qApp->screens()[_hmdScreen]; + auto hmdGeometry = hmdScreen->geometry(); + _hmdWindow->setGeometry(hmdGeometry); + _hmdWindow->showFullScreen(); + + _hmdWindow->makeCurrent(); + glClearColor(1, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + _hmdWindow->swapBuffers(); + + _container->makeRenderingContextCurrent(); + + QOpenGLContextWrapper(_hmdWindow->context()).moveToThread(_presentThread); + _hswDismissed = false; _hmd = ovrHmd_Create(0); if (!_hmd) { @@ -96,7 +122,8 @@ bool OculusLegacyDisplayPlugin::internalActivate() { ovrMatrix4f ovrPerspectiveProjection = ovrMatrix4f_Projection(erd.Fov, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP, ovrProjection_RightHanded); _eyeProjections[eye] = toGlm(ovrPerspectiveProjection); - _eyeOffsets[eye] = glm::translate(mat4(), toGlm(erd.HmdToEyeViewOffset)); + _ovrEyeOffsets[eye] = erd.HmdToEyeViewOffset; + _eyeOffsets[eye] = glm::translate(mat4(), -1.0f * toGlm(_ovrEyeOffsets[eye])); eyeSizes[eye] = toGlm(ovrHmd_GetFovTextureSize(_hmd, eye, erd.Fov, 1.0f)); }); @@ -121,6 +148,11 @@ void OculusLegacyDisplayPlugin::internalDeactivate() { ovrHmd_Destroy(_hmd); _hmd = nullptr; ovr_Shutdown(); + _hmdWindow->showNormal(); + _hmdWindow->destroy(); + _hmdWindow->deleteLater(); + _hmdWindow = nullptr; + _container->makeRenderingContextCurrent(); } // DLL based display plugins MUST initialize GLEW inside the DLL code. @@ -131,20 +163,21 @@ void OculusLegacyDisplayPlugin::customizeContext() { glewInit(); glGetError(); }); + _hmdWindow->requestActivate(); + QThread::msleep(1000); Parent::customizeContext(); -#if 0 ovrGLConfig config; memset(&config, 0, sizeof(ovrRenderAPIConfig)); auto& header = config.Config.Header; header.API = ovrRenderAPI_OpenGL; header.BackBufferSize = _hmd->Resolution; header.Multisample = 1; - int distortionCaps = ovrDistortionCap_TimeWarp; + int distortionCaps = ovrDistortionCap_TimeWarp | ovrDistortionCap_Vignette; memset(_eyeTextures, 0, sizeof(ovrTexture) * 2); ovr_for_each_eye([&](ovrEyeType eye) { auto& header = _eyeTextures[eye].Header; header.API = ovrRenderAPI_OpenGL; - header.TextureSize = { (int)_desiredFramebufferSize.x, (int)_desiredFramebufferSize.y }; + header.TextureSize = { (int)_renderTargetSize.x, (int)_renderTargetSize.y }; header.RenderViewport.Size = header.TextureSize; header.RenderViewport.Size.w /= 2; if (eye == ovrEye_Right) { @@ -152,29 +185,57 @@ void OculusLegacyDisplayPlugin::customizeContext() { } }); + if (_hmdWindow->makeCurrent()) { #ifndef NDEBUG - ovrBool result = -#endif - ovrHmd_ConfigureRendering(_hmd, &config.Config, distortionCaps, _eyeFovs, _eyeRenderDescs); - assert(result); + ovrBool result = #endif + ovrHmd_ConfigureRendering(_hmd, &config.Config, distortionCaps, _eyeFovs, _eyeRenderDescs); + assert(result); + _hmdWindow->doneCurrent(); + } + } -#if 0 void OculusLegacyDisplayPlugin::uncustomizeContext() { - HmdDisplayPlugin::uncustomizeContext(); + _hmdWindow->doneCurrent(); + QOpenGLContextWrapper(_hmdWindow->context()).moveToThread(qApp->thread()); + Parent::uncustomizeContext(); } -void OculusLegacyDisplayPlugin::internalPresent() { - ovrHmd_BeginFrame(_hmd, 0); - ovr_for_each_eye([&](ovrEyeType eye) { - reinterpret_cast(_eyeTextures[eye]).OGL.TexId = _currentSceneTexture; - }); - ovrHmd_EndFrame(_hmd, _eyePoses, _eyeTextures); -} +void OculusLegacyDisplayPlugin::hmdPresent() { + if (!_hswDismissed) { + ovrHSWDisplayState hswState; + ovrHmd_GetHSWDisplayState(_hmd, &hswState); + if (hswState.Displayed) { + ovrHmd_DismissHSWDisplay(_hmd); + } -#endif + } + auto r = glm::quat_cast(_currentPresentFrameInfo.presentPose); + ovrQuatf ovrRotation = { r.x, r.y, r.z, r.w }; + ovrPosef eyePoses[2]; + memset(eyePoses, 0, sizeof(ovrPosef) * 2); + eyePoses[0].Orientation = eyePoses[1].Orientation = ovrRotation; + + GLint texture = oglplus::GetName(_compositeFramebuffer->color); + auto sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + glFlush(); + if (_hmdWindow->makeCurrent()) { + glClearColor(0, 0.4, 0.8, 1); + glClear(GL_COLOR_BUFFER_BIT); + ovrHmd_BeginFrame(_hmd, _currentPresentFrameIndex); + glWaitSync(sync, 0, GL_TIMEOUT_IGNORED); + glDeleteSync(sync); + ovr_for_each_eye([&](ovrEyeType eye) { + reinterpret_cast(_eyeTextures[eye]).OGL.TexId = texture; + }); + ovrHmd_EndFrame(_hmd, eyePoses, _eyeTextures); + _hmdWindow->doneCurrent(); + } + static auto widget = _container->getPrimaryWidget(); + widget->makeCurrent(); +} int OculusLegacyDisplayPlugin::getHmdScreen() const { return _hmdScreen; @@ -184,4 +245,3 @@ float OculusLegacyDisplayPlugin::getTargetFrameRate() const { return TARGET_RATE_OculusLegacy; } - diff --git a/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.h b/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.h index bebf3fa2c7..5900ad4c58 100644 --- a/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.h +++ b/plugins/oculusLegacy/src/OculusLegacyDisplayPlugin.h @@ -14,42 +14,43 @@ #include const float TARGET_RATE_OculusLegacy = 75.0f; +class GLWindow; class OculusLegacyDisplayPlugin : public HmdDisplayPlugin { using Parent = HmdDisplayPlugin; public: OculusLegacyDisplayPlugin(); - virtual bool isSupported() const override; - virtual const QString& getName() const override { return NAME; } + bool isSupported() const override; + const QString& getName() const override { return NAME; } - virtual int getHmdScreen() const override; + int getHmdScreen() const override; // Stereo specific methods - virtual void resetSensors() override; - virtual void beginFrameRender(uint32_t frameIndex) override; + void resetSensors() override; + void beginFrameRender(uint32_t frameIndex) override; - virtual float getTargetFrameRate() const override; + float getTargetFrameRate() const override; protected: - virtual bool internalActivate() override; - virtual void internalDeactivate() override; + bool internalActivate() override; + void internalDeactivate() override; - virtual void customizeContext() override; - void hmdPresent() override {} + void customizeContext() override; + void uncustomizeContext() override; + void hmdPresent() override; bool isHmdMounted() const override { return true; } -#if 0 - virtual void uncustomizeContext() override; - virtual void internalPresent() override; -#endif private: static const QString NAME; + GLWindow* _hmdWindow{ nullptr }; ovrHmd _hmd; mutable ovrTrackingState _trackingState; ovrEyeRenderDesc _eyeRenderDescs[2]; + ovrVector3f _ovrEyeOffsets[2]; + ovrFovPort _eyeFovs[2]; - //ovrTexture _eyeTextures[2]; // FIXME - not currently in use + ovrTexture _eyeTextures[2]; // FIXME - not currently in use mutable int _hmdScreen { -1 }; bool _hswDismissed { false }; }; From 38bf1edf1cd4fd2fd3ce52bd6efca2d63df6d1fe Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 8 May 2016 23:35:18 -0700 Subject: [PATCH 02/45] Fix plugin loading on OSX --- libraries/plugins/src/plugins/PluginManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/plugins/src/plugins/PluginManager.cpp b/libraries/plugins/src/plugins/PluginManager.cpp index 4429f49346..936cb8a7ee 100644 --- a/libraries/plugins/src/plugins/PluginManager.cpp +++ b/libraries/plugins/src/plugins/PluginManager.cpp @@ -32,7 +32,11 @@ const LoaderList& getLoadedPlugins() { static std::once_flag once; static LoaderList loadedPlugins; std::call_once(once, [&] { +#ifdef Q_OS_MAC + QString pluginPath = QCoreApplication::applicationDirPath() + "/../PlugIns/"; +#else QString pluginPath = QCoreApplication::applicationDirPath() + "/plugins/"; +#endif QDir pluginDir(pluginPath); pluginDir.setFilter(QDir::Files); if (pluginDir.exists()) { From 0f440835584634627ea2b24ea2105d6945be1e05 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 17 May 2016 11:13:34 -0700 Subject: [PATCH 03/45] FIx bad roughness value read from the deferred buffer --- libraries/render-utils/src/DeferredBufferRead.slh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index fa166300ae..569063955d 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -101,7 +101,7 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { // Unpack the normal from the map frag.normal = normalize(frag.normalVal.xyz * 2.0 - vec3(1.0)); - frag.roughness = 2.0 * frag.normalVal.a; + frag.roughness = frag.normalVal.a; // Diffuse color and unpack the mode and the metallicness frag.diffuse = frag.diffuseVal.xyz; From 3bee4b1f9f07e933c4a5e5a8d46e4503b96315ba Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Fri, 27 May 2016 16:59:42 -0700 Subject: [PATCH 04/45] fix shapes to property polymorph and persist --- .../entities/src/EntityItemProperties.cpp | 19 ++++++-- .../networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 1 + scripts/system/html/entityProperties.html | 48 ++++++------------- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index f273507d0d..ba39727ff9 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -314,6 +314,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_CLIENT_ONLY, clientOnly); CHECK_PROPERTY_CHANGE(PROP_OWNING_AVATAR_ID, owningAvatarID); + CHECK_PROPERTY_CHANGE(PROP_SHAPE, shape); + changedProperties += _animation.getChangedProperties(); changedProperties += _keyLight.getChangedProperties(); changedProperties += _skybox.getChangedProperties(); @@ -435,6 +437,9 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool if (_type == EntityTypes::Sphere) { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_SHAPE_TYPE, shapeType, QString("Sphere")); } + if (_type == EntityTypes::Box || _type == EntityTypes::Sphere || _type == EntityTypes::Shape) { + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_SHAPE, shape); + } // FIXME - it seems like ParticleEffect should also support this if (_type == EntityTypes::Model || _type == EntityTypes::Zone) { @@ -1144,7 +1149,11 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, properties.getStrokeWidths()); APPEND_ENTITY_PROPERTY(PROP_TEXTURES, properties.getTextures()); } - if (properties.getType() == EntityTypes::Shape) { + // NOTE: Spheres and Boxes are just special cases of Shape, and they need to include their PROP_SHAPE + // when encoding/decoding edits because otherwise they can't polymorph to other shape types + if (properties.getType() == EntityTypes::Shape || + properties.getType() == EntityTypes::Box || + properties.getType() == EntityTypes::Sphere) { APPEND_ENTITY_PROPERTY(PROP_SHAPE, properties.getShape()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); @@ -1211,7 +1220,6 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem } else { packetData->discardSubTree(); } - return success; } @@ -1434,7 +1442,12 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_TEXTURES, QString, setTextures); } - if (properties.getType() == EntityTypes::Shape) { + + // NOTE: Spheres and Boxes are just special cases of Shape, and they need to include their PROP_SHAPE + // when encoding/decoding edits because otherwise they can't polymorph to other shape types + if (properties.getType() == EntityTypes::Shape || + properties.getType() == EntityTypes::Box || + properties.getType() == EntityTypes::Sphere) { READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SHAPE, QString, setShape); } diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 92e5b52f75..db743f81e4 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -49,7 +49,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityAdd: case PacketType::EntityEdit: case PacketType::EntityData: - return VERSION_ENTITIES_MORE_SHAPES; + return VERSION_ENTITIES_PROPERLY_ENCODE_SHAPE_EDITS; case PacketType::AvatarIdentity: case PacketType::AvatarData: case PacketType::BulkAvatarData: diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 97398c6744..320635379d 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -179,6 +179,7 @@ const PacketVersion VERSION_ATMOSPHERE_REMOVED = 56; const PacketVersion VERSION_LIGHT_HAS_FALLOFF_RADIUS = 57; const PacketVersion VERSION_ENTITIES_NO_FLY_ZONES = 58; const PacketVersion VERSION_ENTITIES_MORE_SHAPES = 59; +const PacketVersion VERSION_ENTITIES_PROPERLY_ENCODE_SHAPE_EDITS = 60; enum class AvatarMixerPacketVersion : PacketVersion { TranslationSupport = 17, diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 5c87f753d9..2a82d8fa74 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -557,7 +557,6 @@ } properties = data.selections[0].properties; - elID.innerHTML = properties.id; elType.innerHTML = properties.type; @@ -675,6 +674,9 @@ for (var i = 0; i < elShapeSections.length; i++) { elShapeSections[i].style.display = 'table'; } + elShape.value = properties.shape; + setDropdownText(elShape); + } else { for (var i = 0; i < elShapeSections.length; i++) { console.log("Hiding shape section " + elShapeSections[i]) @@ -1349,6 +1351,17 @@
+
@@ -1362,39 +1375,6 @@
-
- M -
- -
- - -
-
- - -
- - From 1624146fc2ecf6abf508b03769f81ff2220158ae Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 31 May 2016 20:39:16 -0700 Subject: [PATCH 05/45] Revert "refresh API info during re-connect - case 570" This reverts commit e8d7f9614aed57bad25f940c82282c25b91ed92e. --- libraries/networking/src/AddressManager.cpp | 44 +++------------------ libraries/networking/src/AddressManager.h | 9 +---- libraries/networking/src/DomainHandler.cpp | 18 ++++++--- libraries/networking/src/DomainHandler.h | 10 ++--- libraries/networking/src/NodeList.cpp | 14 ++----- 5 files changed, 28 insertions(+), 67 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 80989acd2c..1a452999e4 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -144,21 +144,12 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { // 4. domain network address (IP or dns resolvable hostname) // use our regex'ed helpers to figure out what we're supposed to do with this - if (handleUsername(lookupUrl.authority())) { - // handled a username for lookup - - // in case we're failing to connect to where we thought this user was - // store their username as previous lookup so we can refresh their location via API - _previousLookup = lookupUrl; - } else { + if (!handleUsername(lookupUrl.authority())) { // we're assuming this is either a network address or global place name // check if it is a network address first bool hostChanged; if (handleNetworkAddress(lookupUrl.host() - + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())), trigger, hostChanged)) { - - // a network address lookup clears the previous lookup since we don't expect to re-attempt it - _previousLookup.clear(); + + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())), trigger, hostChanged)) { // If the host changed then we have already saved to history if (hostChanged) { @@ -174,16 +165,10 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { // we may have a path that defines a relative viewpoint - if so we should jump to that now handlePath(path, trigger); } else if (handleDomainID(lookupUrl.host())){ - // store this domain ID as the previous lookup in case we're failing to connect and want to refresh API info - _previousLookup = lookupUrl; - // no place name - this is probably a domain ID // try to look up the domain ID on the metaverse API attemptDomainIDLookup(lookupUrl.host(), lookupUrl.path(), trigger); } else { - // store this place name as the previous lookup in case we fail to connect and want to refresh API info - _previousLookup = lookupUrl; - // wasn't an address - lookup the place name // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path(), trigger); @@ -195,13 +180,9 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { } else if (lookupUrl.toString().startsWith('/')) { qCDebug(networking) << "Going to relative path" << lookupUrl.path(); - // a path lookup clears the previous lookup since we don't expect to re-attempt it - _previousLookup.clear(); - // if this is a relative path then handle it as a relative viewpoint handlePath(lookupUrl.path(), trigger, true); emit lookupResultsFinished(); - return true; } @@ -295,7 +276,7 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const qCDebug(networking) << "Possible domain change required to connect to" << domainHostname << "on" << domainPort; - emit possibleDomainChangeRequired(domainHostname, domainPort, domainID); + emit possibleDomainChangeRequired(domainHostname, domainPort); } else { QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString(); @@ -334,10 +315,7 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const QString overridePath = reply.property(OVERRIDE_PATH_KEY).toString(); if (!overridePath.isEmpty()) { - // make sure we don't re-handle an overriden path if this was a refresh of info from API - if (trigger != LookupTrigger::AttemptedRefresh) { - handlePath(overridePath, trigger); - } + handlePath(overridePath, trigger); } else { // take the path that came back const QString PLACE_PATH_KEY = "path"; @@ -620,7 +598,7 @@ bool AddressManager::setDomainInfo(const QString& hostname, quint16 port, Lookup DependencyManager::get()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress); - emit possibleDomainChangeRequired(hostname, port, QUuid()); + emit possibleDomainChangeRequired(hostname, port); return hostChanged; } @@ -640,13 +618,6 @@ void AddressManager::goToUser(const QString& username) { QByteArray(), nullptr, requestParams); } -void AddressManager::refreshPreviousLookup() { - // if we have a non-empty previous lookup, fire it again now (but don't re-store it in the history) - if (!_previousLookup.isEmpty()) { - handleUrl(_previousLookup, LookupTrigger::AttemptedRefresh); - } -} - void AddressManager::copyAddress() { QApplication::clipboard()->setText(currentAddress().toString()); } @@ -658,10 +629,7 @@ void AddressManager::copyPath() { void AddressManager::addCurrentAddressToHistory(LookupTrigger trigger) { // if we're cold starting and this is called for the first address (from settings) we don't do anything - if (trigger != LookupTrigger::StartupFromSettings - && trigger != LookupTrigger::DomainPathResponse - && trigger != LookupTrigger::AttemptedRefresh) { - + if (trigger != LookupTrigger::StartupFromSettings && trigger != LookupTrigger::DomainPathResponse) { if (trigger == LookupTrigger::Back) { // we're about to push to the forward stack // if it's currently empty emit our signal to say that going forward is now possible diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index a3aaee3ba2..643924ff5c 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -48,8 +48,7 @@ public: Forward, StartupFromSettings, DomainPathResponse, - Internal, - AttemptedRefresh + Internal }; bool isConnected(); @@ -90,8 +89,6 @@ public slots: void goToUser(const QString& username); - void refreshPreviousLookup(); - void storeCurrentAddress(); void copyAddress(); @@ -102,7 +99,7 @@ signals: void lookupResultIsOffline(); void lookupResultIsNotFound(); - void possibleDomainChangeRequired(const QString& newHostname, quint16 newPort, const QUuid& domainID); + void possibleDomainChangeRequired(const QString& newHostname, quint16 newPort); void possibleDomainChangeRequiredViaICEForID(const QString& iceServerHostname, const QUuid& domainID); void locationChangeRequired(const glm::vec3& newPosition, @@ -155,8 +152,6 @@ private: quint64 _lastBackPush = 0; QString _newHostLookupPath; - - QUrl _previousLookup; }; #endif // hifi_AddressManager_h diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 1efcfc7f27..4f85296f03 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -28,8 +28,16 @@ DomainHandler::DomainHandler(QObject* parent) : QObject(parent), + _uuid(), _sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)), + _assignmentUUID(), + _connectionToken(), + _iceDomainID(), + _iceClientID(), + _iceServerSockAddr(), _icePeer(this), + _isConnected(false), + _settingsObject(), _settingsTimer(this) { _sockAddr.setObjectName("DomainServer"); @@ -97,7 +105,7 @@ void DomainHandler::hardReset() { softReset(); qCDebug(networking) << "Hard reset in NodeList DomainHandler."; - _pendingDomainID = QUuid(); + _iceDomainID = QUuid(); _iceServerSockAddr = HifiSockAddr(); _hostname = QString(); _sockAddr.clear(); @@ -131,7 +139,7 @@ void DomainHandler::setUUID(const QUuid& uuid) { } } -void DomainHandler::setSocketAndID(const QString& hostname, quint16 port, const QUuid& domainID) { +void DomainHandler::setHostnameAndPort(const QString& hostname, quint16 port) { if (hostname != _hostname || _sockAddr.getPort() != port) { // re-set the domain info so that auth information is reloaded @@ -163,8 +171,6 @@ void DomainHandler::setSocketAndID(const QString& hostname, quint16 port, const // grab the port by reading the string after the colon _sockAddr.setPort(port); } - - _pendingDomainID = domainID; } void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id) { @@ -175,7 +181,7 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, // refresh our ICE client UUID to something new _iceClientID = QUuid::createUuid(); - _pendingDomainID = id; + _iceDomainID = id; HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr; replaceableSockAddr->~HifiSockAddr(); @@ -337,7 +343,7 @@ void DomainHandler::processICEResponsePacket(QSharedPointer mes DependencyManager::get()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::ReceiveDSPeerInformation); - if (_icePeer.getUUID() != _pendingDomainID) { + if (_icePeer.getUUID() != _iceDomainID) { qCDebug(networking) << "Received a network peer with ID that does not match current domain. Will not attempt connection."; _icePeer.reset(); } else { diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index 226186f1d0..bcee7668d1 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -58,8 +58,8 @@ public: const QUuid& getAssignmentUUID() const { return _assignmentUUID; } void setAssignmentUUID(const QUuid& assignmentUUID) { _assignmentUUID = assignmentUUID; } - - const QUuid& getPendingDomainID() const { return _pendingDomainID; } + + const QUuid& getICEDomainID() const { return _iceDomainID; } const QUuid& getICEClientID() const { return _iceClientID; } @@ -94,7 +94,7 @@ public: }; public slots: - void setSocketAndID(const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT, const QUuid& id = QUuid()); + void setHostnameAndPort(const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT); void setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id); void processSettingsPacketList(QSharedPointer packetList); @@ -136,11 +136,11 @@ private: HifiSockAddr _sockAddr; QUuid _assignmentUUID; QUuid _connectionToken; - QUuid _pendingDomainID; // ID of domain being connected to, via ICE or direct connection + QUuid _iceDomainID; QUuid _iceClientID; HifiSockAddr _iceServerSockAddr; NetworkPeer _icePeer; - bool _isConnected { false }; + bool _isConnected; QJsonObject _settingsObject; QString _pendingPath; QTimer _settingsTimer; diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 082200fccc..16a4083b08 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -50,7 +50,7 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned // handle domain change signals from AddressManager connect(addressManager.data(), &AddressManager::possibleDomainChangeRequired, - &_domainHandler, &DomainHandler::setSocketAndID); + &_domainHandler, &DomainHandler::setHostnameAndPort); connect(addressManager.data(), &AddressManager::possibleDomainChangeRequiredViaICEForID, &_domainHandler, &DomainHandler::setIceServerHostnameAndID); @@ -355,14 +355,6 @@ void NodeList::sendDomainServerCheckIn() { // increment the count of un-replied check-ins _numNoReplyDomainCheckIns++; } - - if (!_publicSockAddr.isNull() && !_domainHandler.isConnected() && !_domainHandler.getPendingDomainID().isNull()) { - // if we aren't connected to the domain-server, and we have an ID - // (that we presume belongs to a domain in the HF Metaverse) - // we request connection information for the domain every so often to make sure what we have is up to date - - DependencyManager::get()->refreshPreviousLookup(); - } } void NodeList::handleDSPathQuery(const QString& newPath) { @@ -470,7 +462,7 @@ void NodeList::handleICEConnectionToDomainServer() { LimitedNodeList::sendPeerQueryToIceServer(_domainHandler.getICEServerSockAddr(), _domainHandler.getICEClientID(), - _domainHandler.getPendingDomainID()); + _domainHandler.getICEDomainID()); } } @@ -483,7 +475,7 @@ void NodeList::pingPunchForDomainServer() { if (_domainHandler.getICEPeer().getConnectionAttempts() == 0) { qCDebug(networking) << "Sending ping packets to establish connectivity with domain-server with ID" - << uuidStringWithoutCurlyBraces(_domainHandler.getPendingDomainID()); + << uuidStringWithoutCurlyBraces(_domainHandler.getICEDomainID()); } else { if (_domainHandler.getICEPeer().getConnectionAttempts() % NUM_DOMAIN_SERVER_PINGS_BEFORE_RESET == 0) { // if we have then nullify the domain handler's network peer and send a fresh ICE heartbeat From 8586e91a3b78e37f54384721990b979caff96c3e Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 31 May 2016 20:50:12 -0700 Subject: [PATCH 06/45] additional revert related change --- libraries/networking/src/AddressManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 1a452999e4..1b7ed11cce 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -362,7 +362,7 @@ void AddressManager::handleAPIError(QNetworkReply& errorReply) { if (errorReply.error() == QNetworkReply::ContentNotFoundError) { // if this is a lookup that has no result, don't keep re-trying it - _previousLookup.clear(); + //_previousLookup.clear(); emit lookupResultIsNotFound(); } From f9d6a7ba8d57cccb8e0feb16ecc9f4c344dbcdb5 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 8 Jun 2016 14:02:27 +1200 Subject: [PATCH 07/45] Fix image2d overlay color property --- interface/resources/qml/hifi/overlays/ImageOverlay.qml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interface/resources/qml/hifi/overlays/ImageOverlay.qml b/interface/resources/qml/hifi/overlays/ImageOverlay.qml index b10b66f07c..b509f0ce3a 100644 --- a/interface/resources/qml/hifi/overlays/ImageOverlay.qml +++ b/interface/resources/qml/hifi/overlays/ImageOverlay.qml @@ -1,5 +1,6 @@ import QtQuick 2.3 import QtQuick.Controls 1.2 +import QtGraphicalEffects 1.0 import "." @@ -44,6 +45,12 @@ Overlay { } } + ColorOverlay { + id: color + anchors.fill: image + source: image + } + function updateSubImage(subImage) { var keys = Object.keys(subImage); for (var i = 0; i < keys.length; ++i) { @@ -70,6 +77,7 @@ Overlay { case "alpha": root.opacity = value; break; case "imageURL": image.source = value; break; case "subImage": updateSubImage(value); break; + case "color": color.color = Qt.rgba(value.red / 255, value.green / 255, value.blue / 255, root.opacity); break; default: console.log("OVERLAY Unhandled image property " + key); } } From 1b4b38c85bb3d6aaa410ad29e834a7b40ad50310 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 8 Jun 2016 11:28:49 -0700 Subject: [PATCH 08/45] when parent is an avatar, set velocity to zero (still incorrect, but avoids server-side problems) rather than the world-frame velocity --- libraries/shared/src/SpatiallyNestable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 2a3cb4af47..ddc82e2169 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -422,7 +422,7 @@ void SpatiallyNestable::setVelocity(const glm::vec3& velocity, bool& success) { // causes EntityItem::stepKinematicMotion to have an effect on the equipped entity, // which causes it to drift from the hand. if (hasAncestorOfType(NestableType::Avatar)) { - _velocity = velocity; + _velocity = glm::vec3(0.0f); } else { // TODO: take parent angularVelocity into account. _velocity = glm::inverse(parentTransform.getRotation()) * (velocity - parentVelocity); From 5cbaf05e45cb708402adc1bf1a7c44c0f5cadc7e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 8 Jun 2016 11:55:17 -0700 Subject: [PATCH 09/45] also zero angular velocity for child of avatar --- libraries/shared/src/SpatiallyNestable.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index ddc82e2169..02a8d60fba 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -479,7 +479,12 @@ void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity, boo glm::vec3 parentAngularVelocity = getParentAngularVelocity(success); Transform parentTransform = getParentTransform(success); _angularVelocityLock.withWriteLock([&] { - _angularVelocity = glm::inverse(parentTransform.getRotation()) * (angularVelocity - parentAngularVelocity); + if (hasAncestorOfType(NestableType::Avatar)) { + // TODO: this is done to keep entity-server from doing extrapolation, and isn't right. + _angularVelocity = glm::vec3(0.0f); + } else { + _angularVelocity = glm::inverse(parentTransform.getRotation()) * (angularVelocity - parentAngularVelocity); + } }); } From 201d7a7d3b616d26e0f5b4a6f23c2a3ad5ef520d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 8 Jun 2016 12:11:08 -0700 Subject: [PATCH 10/45] when parent is an avatar, set velocity to zero (still incorrect, but avoids server-side problems) rather than the world-frame velocity --- libraries/shared/src/SpatiallyNestable.cpp | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 02a8d60fba..6872b1d197 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -415,12 +415,8 @@ void SpatiallyNestable::setVelocity(const glm::vec3& velocity, bool& success) { glm::vec3 parentVelocity = getParentVelocity(success); Transform parentTransform = getParentTransform(success); _velocityLock.withWriteLock([&] { - // HACK: until we are treating _velocity the same way we treat _position (meaning, - // _velocity is a vs parent value and any request for a world-frame velocity must - // be computed), do this to avoid equipped (parenting-grabbed) things from drifting. - // turning a zero velocity into a non-zero _velocity (because the avatar is moving) - // causes EntityItem::stepKinematicMotion to have an effect on the equipped entity, - // which causes it to drift from the hand. + // HACK: The entity-server doesn't know where avatars are. In order to avoid having the server + // try to do simple extrapolation, set relative velocities to zero if this is a child of an avatar. if (hasAncestorOfType(NestableType::Avatar)) { _velocity = glm::vec3(0.0f); } else { @@ -898,13 +894,21 @@ void SpatiallyNestable::setLocalTransformAndVelocities( _transformLock.withWriteLock([&] { _transform = localTransform; }); - // linear velocity - _velocityLock.withWriteLock([&] { - _velocity = localVelocity; - }); - // angular velocity - _angularVelocityLock.withWriteLock([&] { - _angularVelocity = localAngularVelocity; - }); + // linear and angular velocity + if (hasAncestorOfType(NestableType::Avatar)) { + _velocityLock.withWriteLock([&] { + _velocity = glm::vec3(0.0f); + }); + _angularVelocityLock.withWriteLock([&] { + _angularVelocity = glm::vec3(0.0f); + }); + } else { + _velocityLock.withWriteLock([&] { + _velocity = localVelocity; + }); + _angularVelocityLock.withWriteLock([&] { + _angularVelocity = localAngularVelocity; + }); + } locationChanged(false); } From a1766539f402a249758f87640163e6ea2edded26 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 8 Jun 2016 12:17:07 -0700 Subject: [PATCH 11/45] don't do simple simulation on children of avatars --- libraries/entities/src/EntitySimulation.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index 893ae83cc5..b99ab76b7a 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -261,7 +261,11 @@ void EntitySimulation::moveSimpleKinematics(const quint64& now) { SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin(); while (itemItr != _simpleKinematicEntities.end()) { EntityItemPointer entity = *itemItr; - if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo()) { + if (entity->isMovingRelativeToParent() && + !entity->getPhysicsInfo() && + // The entity-server doesn't know where avatars are, so don't attempt to do simple extrapolation for + // children of avatars. + !entity->hasAncestorOfType(NestableType::Avatar)) { entity->simulate(now); _entitiesToSort.insert(entity); ++itemItr; From d7fc789ea705df7de5c601e48a2c041e9705445d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 8 Jun 2016 13:47:52 -0700 Subject: [PATCH 12/45] try harder to not do simple-simulation on things that have an avatar ancestor --- libraries/entities/src/EntitySimulation.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index b99ab76b7a..8419e4ac6a 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -261,11 +261,14 @@ void EntitySimulation::moveSimpleKinematics(const quint64& now) { SetOfEntities::iterator itemItr = _simpleKinematicEntities.begin(); while (itemItr != _simpleKinematicEntities.end()) { EntityItemPointer entity = *itemItr; - if (entity->isMovingRelativeToParent() && - !entity->getPhysicsInfo() && - // The entity-server doesn't know where avatars are, so don't attempt to do simple extrapolation for - // children of avatars. - !entity->hasAncestorOfType(NestableType::Avatar)) { + + // The entity-server doesn't know where avatars are, so don't attempt to do simple extrapolation for + // children of avatars. + bool ancestryIsKnown; + entity->getMaximumAACube(ancestryIsKnown); + bool hasAvatarAncestor = entity->hasAncestorOfType(NestableType::Avatar); + + if (entity->isMovingRelativeToParent() && !entity->getPhysicsInfo() && ancestryIsKnown && !hasAvatarAncestor) { entity->simulate(now); _entitiesToSort.insert(entity); ++itemItr; From a312218722c6be133d303421c917f82dfa92a77d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 8 Jun 2016 14:07:16 -0700 Subject: [PATCH 13/45] back out some changes --- libraries/shared/src/SpatiallyNestable.cpp | 41 +++++++++------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 6872b1d197..2a3cb4af47 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -415,10 +415,14 @@ void SpatiallyNestable::setVelocity(const glm::vec3& velocity, bool& success) { glm::vec3 parentVelocity = getParentVelocity(success); Transform parentTransform = getParentTransform(success); _velocityLock.withWriteLock([&] { - // HACK: The entity-server doesn't know where avatars are. In order to avoid having the server - // try to do simple extrapolation, set relative velocities to zero if this is a child of an avatar. + // HACK: until we are treating _velocity the same way we treat _position (meaning, + // _velocity is a vs parent value and any request for a world-frame velocity must + // be computed), do this to avoid equipped (parenting-grabbed) things from drifting. + // turning a zero velocity into a non-zero _velocity (because the avatar is moving) + // causes EntityItem::stepKinematicMotion to have an effect on the equipped entity, + // which causes it to drift from the hand. if (hasAncestorOfType(NestableType::Avatar)) { - _velocity = glm::vec3(0.0f); + _velocity = velocity; } else { // TODO: take parent angularVelocity into account. _velocity = glm::inverse(parentTransform.getRotation()) * (velocity - parentVelocity); @@ -475,12 +479,7 @@ void SpatiallyNestable::setAngularVelocity(const glm::vec3& angularVelocity, boo glm::vec3 parentAngularVelocity = getParentAngularVelocity(success); Transform parentTransform = getParentTransform(success); _angularVelocityLock.withWriteLock([&] { - if (hasAncestorOfType(NestableType::Avatar)) { - // TODO: this is done to keep entity-server from doing extrapolation, and isn't right. - _angularVelocity = glm::vec3(0.0f); - } else { - _angularVelocity = glm::inverse(parentTransform.getRotation()) * (angularVelocity - parentAngularVelocity); - } + _angularVelocity = glm::inverse(parentTransform.getRotation()) * (angularVelocity - parentAngularVelocity); }); } @@ -894,21 +893,13 @@ void SpatiallyNestable::setLocalTransformAndVelocities( _transformLock.withWriteLock([&] { _transform = localTransform; }); - // linear and angular velocity - if (hasAncestorOfType(NestableType::Avatar)) { - _velocityLock.withWriteLock([&] { - _velocity = glm::vec3(0.0f); - }); - _angularVelocityLock.withWriteLock([&] { - _angularVelocity = glm::vec3(0.0f); - }); - } else { - _velocityLock.withWriteLock([&] { - _velocity = localVelocity; - }); - _angularVelocityLock.withWriteLock([&] { - _angularVelocity = localAngularVelocity; - }); - } + // linear velocity + _velocityLock.withWriteLock([&] { + _velocity = localVelocity; + }); + // angular velocity + _angularVelocityLock.withWriteLock([&] { + _angularVelocity = localAngularVelocity; + }); locationChanged(false); } From f070708b4a49c299967c78b7881df36bfa909cdc Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 8 Jun 2016 15:53:54 -0700 Subject: [PATCH 14/45] _avatarEntityData is accessed by more than one thread. --- interface/src/avatar/Avatar.cpp | 10 ++-- interface/src/avatar/MyAvatar.cpp | 14 ++--- libraries/avatars/src/AvatarData.cpp | 79 ++++++++++++++++++---------- libraries/avatars/src/AvatarData.h | 1 + 4 files changed, 65 insertions(+), 39 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 3e22448386..b5ac8ba77d 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -240,11 +240,13 @@ void Avatar::updateAvatarEntities() { } AvatarEntityIDs recentlyDettachedAvatarEntities = getAndClearRecentlyDetachedIDs(); - foreach (auto entityID, recentlyDettachedAvatarEntities) { - if (!_avatarEntityData.contains(entityID)) { - entityTree->deleteEntity(entityID, true, true); + _avatarEntitiesLock.withReadLock([&] { + foreach (auto entityID, recentlyDettachedAvatarEntities) { + if (!_avatarEntityData.contains(entityID)) { + entityTree->deleteEntity(entityID, true, true); + } } - } + }); }); if (success) { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 62772c6933..324ff1534f 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -723,12 +723,14 @@ void MyAvatar::saveData() { settings.beginWriteArray("avatarEntityData"); int avatarEntityIndex = 0; - for (auto entityID : _avatarEntityData.keys()) { - settings.setArrayIndex(avatarEntityIndex); - settings.setValue("id", entityID); - settings.setValue("properties", _avatarEntityData.value(entityID)); - avatarEntityIndex++; - } + _avatarEntitiesLock.withReadLock([&] { + for (auto entityID : _avatarEntityData.keys()) { + settings.setArrayIndex(avatarEntityIndex); + settings.setValue("id", entityID); + settings.setValue("properties", _avatarEntityData.value(entityID)); + avatarEntityIndex++; + } + }); settings.endArray(); settings.setValue("displayName", _displayName); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index ff7438bb17..6d99d6ad81 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -900,7 +900,11 @@ bool AvatarData::processAvatarIdentity(const Identity& identity) { hasIdentityChanged = true; } - if (identity.avatarEntityData != _avatarEntityData) { + bool avatarEntityDataChanged = false; + _avatarEntitiesLock.withReadLock([&] { + avatarEntityDataChanged = (identity.avatarEntityData != _avatarEntityData); + }); + if (avatarEntityDataChanged) { setAvatarEntityData(identity.avatarEntityData); hasIdentityChanged = true; } @@ -914,7 +918,9 @@ QByteArray AvatarData::identityByteArray() { QUrl emptyURL(""); const QUrl& urlToSend = _skeletonModelURL.scheme() == "file" ? emptyURL : _skeletonModelURL; - identityStream << getSessionUUID() << urlToSend << _attachmentData << _displayName << _avatarEntityData; + _avatarEntitiesLock.withReadLock([&] { + identityStream << getSessionUUID() << urlToSend << _attachmentData << _displayName << _avatarEntityData; + }); return identityData; } @@ -1306,16 +1312,18 @@ QJsonObject AvatarData::toJson() const { root[JSON_AVATAR_ATTACHEMENTS] = attachmentsJson; } - if (!_avatarEntityData.empty()) { - QJsonArray avatarEntityJson; - for (auto entityID : _avatarEntityData.keys()) { - QVariantMap entityData; - entityData.insert("id", entityID); - entityData.insert("properties", _avatarEntityData.value(entityID)); - avatarEntityJson.push_back(QVariant(entityData).toJsonObject()); + _avatarEntitiesLock.withReadLock([&] { + if (!_avatarEntityData.empty()) { + QJsonArray avatarEntityJson; + for (auto entityID : _avatarEntityData.keys()) { + QVariantMap entityData; + entityData.insert("id", entityID); + entityData.insert("properties", _avatarEntityData.value(entityID)); + avatarEntityJson.push_back(QVariant(entityData).toJsonObject()); + } + root[JSON_AVATAR_ENTITIES] = avatarEntityJson; } - root[JSON_AVATAR_ENTITIES] = avatarEntityJson; - } + }); auto recordingBasis = getRecordingBasis(); bool success; @@ -1604,8 +1612,10 @@ void AvatarData::updateAvatarEntity(const QUuid& entityID, const QByteArray& ent QMetaObject::invokeMethod(this, "updateAvatarEntity", Q_ARG(const QUuid&, entityID), Q_ARG(QByteArray, entityData)); return; } - _avatarEntityData.insert(entityID, entityData); - _avatarEntityDataLocallyEdited = true; + _avatarEntitiesLock.withWriteLock([&] { + _avatarEntityData.insert(entityID, entityData); + _avatarEntityDataLocallyEdited = true; + }); } void AvatarData::clearAvatarEntity(const QUuid& entityID) { @@ -1613,18 +1623,25 @@ void AvatarData::clearAvatarEntity(const QUuid& entityID) { QMetaObject::invokeMethod(this, "clearAvatarEntity", Q_ARG(const QUuid&, entityID)); return; } - _avatarEntityData.remove(entityID); - _avatarEntityDataLocallyEdited = true; + + _avatarEntitiesLock.withWriteLock([&] { + _avatarEntityData.remove(entityID); + _avatarEntityDataLocallyEdited = true; + }); } AvatarEntityMap AvatarData::getAvatarEntityData() const { + AvatarEntityMap result; if (QThread::currentThread() != thread()) { - AvatarEntityMap result; QMetaObject::invokeMethod(const_cast(this), "getAvatarEntityData", Qt::BlockingQueuedConnection, Q_RETURN_ARG(AvatarEntityMap, result)); return result; } - return _avatarEntityData; + + _avatarEntitiesLock.withReadLock([&] { + result = _avatarEntityData; + }); + return result; } void AvatarData::setAvatarEntityData(const AvatarEntityMap& avatarEntityData) { @@ -1632,29 +1649,33 @@ void AvatarData::setAvatarEntityData(const AvatarEntityMap& avatarEntityData) { QMetaObject::invokeMethod(this, "setAvatarEntityData", Q_ARG(const AvatarEntityMap&, avatarEntityData)); return; } - if (_avatarEntityData != avatarEntityData) { - // keep track of entities that were attached to this avatar but no longer are - AvatarEntityIDs previousAvatarEntityIDs = QSet::fromList(_avatarEntityData.keys()); + _avatarEntitiesLock.withWriteLock([&] { + if (_avatarEntityData != avatarEntityData) { + // keep track of entities that were attached to this avatar but no longer are + AvatarEntityIDs previousAvatarEntityIDs = QSet::fromList(_avatarEntityData.keys()); - _avatarEntityData = avatarEntityData; - setAvatarEntityDataChanged(true); + _avatarEntityData = avatarEntityData; + setAvatarEntityDataChanged(true); - foreach (auto entityID, previousAvatarEntityIDs) { - if (!_avatarEntityData.contains(entityID)) { - _avatarEntityDetached.insert(entityID); + foreach (auto entityID, previousAvatarEntityIDs) { + if (!_avatarEntityData.contains(entityID)) { + _avatarEntityDetached.insert(entityID); + } } } - } + }); } AvatarEntityIDs AvatarData::getAndClearRecentlyDetachedIDs() { + AvatarEntityIDs result; if (QThread::currentThread() != thread()) { - AvatarEntityIDs result; QMetaObject::invokeMethod(const_cast(this), "getRecentlyDetachedIDs", Qt::BlockingQueuedConnection, Q_RETURN_ARG(AvatarEntityIDs, result)); return result; } - AvatarEntityIDs result = _avatarEntityDetached; - _avatarEntityDetached.clear(); + _avatarEntitiesLock.withWriteLock([&] { + result = _avatarEntityDetached; + _avatarEntityDetached.clear(); + }); return result; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 61ee649273..2dd1079b49 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -418,6 +418,7 @@ protected: // updates about one avatar to another. glm::vec3 _globalPosition; + mutable ReadWriteLockable _avatarEntitiesLock; AvatarEntityIDs _avatarEntityDetached; // recently detached from this avatar AvatarEntityMap _avatarEntityData; bool _avatarEntityDataLocallyEdited { false }; From 24e5000aebee67e7ccd00a7fe8773c2362615cbe Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 8 Jun 2016 18:26:54 -0700 Subject: [PATCH 15/45] exposed orientation and eye position to procedural entity shaders --- .../src/RenderableProceduralItemShader.h | 2 ++ .../src/RenderableShapeEntityItem.cpp | 2 +- libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 17 +++++++++++++++++ libraries/gpu-gl/src/gpu/gl/GLBackend.h | 1 + libraries/gpu/src/gpu/Batch.cpp | 10 ++++++++++ libraries/gpu/src/gpu/Batch.h | 6 ++++++ .../procedural/src/procedural/Procedural.cpp | 18 +++++++++++++++--- .../procedural/src/procedural/Procedural.h | 6 +++++- .../src/procedural/ProceduralShaders.h | 2 ++ .../src/procedural/ProceduralSkybox.cpp | 2 +- 10 files changed, 60 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableProceduralItemShader.h b/libraries/entities-renderer/src/RenderableProceduralItemShader.h index 4762f619bf..d7df43de14 100644 --- a/libraries/entities-renderer/src/RenderableProceduralItemShader.h +++ b/libraries/entities-renderer/src/RenderableProceduralItemShader.h @@ -314,6 +314,8 @@ in vec4 _position; // TODO add more uniforms uniform float iGlobalTime; // shader playback time (in seconds) uniform vec3 iWorldScale; // the dimensions of the object being rendered +uniform mat3 iWorldOrientation; // the orientation of the object being rendered +uniform vec3 iWorldEyePosition; // the world position of the eye // TODO add support for textures // TODO document available inputs other than the uniforms diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index c93ae252e3..2b04478831 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -98,7 +98,7 @@ void RenderableShapeEntityItem::render(RenderArgs* args) { } batch.setModelTransform(modelTransform); // use a transform with scale, rotation, registration point and translation if (_procedural->ready()) { - _procedural->prepare(batch, getPosition(), getDimensions()); + _procedural->prepare(batch, getPosition(), getDimensions(), getOrientation(), args->getViewFrustum().getPosition()); auto outColor = _procedural->getColor(color); batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a); DependencyManager::get()->renderShape(batch, MAPPING[_shape]); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index ece1ee730c..e18b784018 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -114,6 +114,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::gl::GLBackend::do_glUniform3fv), (&::gpu::gl::GLBackend::do_glUniform4fv), (&::gpu::gl::GLBackend::do_glUniform4iv), + (&::gpu::gl::GLBackend::do_glUniformMatrix3fv), (&::gpu::gl::GLBackend::do_glUniformMatrix4fv), (&::gpu::gl::GLBackend::do_glColor4f), @@ -515,6 +516,22 @@ void GLBackend::do_glUniform4iv(Batch& batch, size_t paramOffset) { (void)CHECK_GL_ERROR(); } +void GLBackend::do_glUniformMatrix3fv(Batch& batch, size_t paramOffset) { + if (_pipeline._program == 0) { + // We should call updatePipeline() to bind the program but we are not doing that + // because these uniform setters are deprecated and we don;t want to create side effect + return; + } + updatePipeline(); + + glUniformMatrix3fv( + GET_UNIFORM_LOCATION(batch._params[paramOffset + 3]._int), + batch._params[paramOffset + 2]._uint, + batch._params[paramOffset + 1]._uint, + (const GLfloat*)batch.editData(batch._params[paramOffset + 0]._uint)); + (void)CHECK_GL_ERROR(); +} + void GLBackend::do_glUniformMatrix4fv(Batch& batch, size_t paramOffset) { if (_pipeline._program == 0) { // We should call updatePipeline() to bind the program but we are not doing that diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.h b/libraries/gpu-gl/src/gpu/gl/GLBackend.h index 610672f44f..5255a6cb25 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.h @@ -136,6 +136,7 @@ public: virtual void do_glUniform3fv(Batch& batch, size_t paramOffset) final; virtual void do_glUniform4fv(Batch& batch, size_t paramOffset) final; virtual void do_glUniform4iv(Batch& batch, size_t paramOffset) final; + virtual void do_glUniformMatrix3fv(Batch& batch, size_t paramOffset) final; virtual void do_glUniformMatrix4fv(Batch& batch, size_t paramOffset) final; virtual void do_glColor4f(Batch& batch, size_t paramOffset) final; diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 9126f11acf..6dc1d63ca8 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -567,6 +567,16 @@ void Batch::_glUniform4iv(int32 location, int count, const int32* value) { _params.push_back(location); } +void Batch::_glUniformMatrix3fv(int32 location, int count, uint8 transpose, const float* value) { + ADD_COMMAND(glUniformMatrix3fv); + + const int MATRIX3_SIZE = 9 * sizeof(float); + _params.push_back(cacheData(count * MATRIX3_SIZE, value)); + _params.push_back(transpose); + _params.push_back(count); + _params.push_back(location); +} + void Batch::_glUniformMatrix4fv(int32 location, int count, uint8 transpose, const float* value) { ADD_COMMAND(glUniformMatrix4fv); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index a2ee57759f..f8b447975c 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -269,6 +269,7 @@ public: void _glUniform3fv(int location, int count, const float* value); void _glUniform4fv(int location, int count, const float* value); void _glUniform4iv(int location, int count, const int* value); + void _glUniformMatrix3fv(int location, int count, unsigned char transpose, const float* value); void _glUniformMatrix4fv(int location, int count, unsigned char transpose, const float* value); void _glUniform(int location, int v0) { @@ -291,6 +292,10 @@ public: _glUniform4f(location, v.x, v.y, v.z, v.w); } + void _glUniform(int location, const glm::quat& v) { + _glUniformMatrix3fv(location, 1, false, reinterpret_cast< const float* >(&glm::mat3_cast(v))); + } + void _glColor4f(float red, float green, float blue, float alpha); enum Command { @@ -348,6 +353,7 @@ public: COMMAND_glUniform3fv, COMMAND_glUniform4fv, COMMAND_glUniform4iv, + COMMAND_glUniformMatrix3fv, COMMAND_glUniformMatrix4fv, COMMAND_glColor4f, diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 781b508bc7..4f308e0812 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -39,6 +39,8 @@ static const std::string STANDARD_UNIFORM_NAMES[Procedural::NUM_STANDARD_UNIFORM "iFrameCount", "iWorldScale", "iWorldPosition", + "iWorldOrientation", + "iWorldEyePosition", "iChannelResolution" }; @@ -202,9 +204,11 @@ bool Procedural::ready() { return true; } -void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size) { +void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation, const glm::vec3& eyePos) { _entityDimensions = size; _entityPosition = position; + _entityOrientation = orientation; + _eyePos = eyePos; if (_shaderUrl.isLocalFile()) { auto lastModified = (quint64)QFileInfo(_shaderPath).lastModified().toMSecsSinceEpoch(); if (lastModified > _shaderModified) { @@ -404,10 +408,10 @@ void Procedural::setupUniforms() { }); } - if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[SCALE]) { + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[ORIENTATION]) { // FIXME move into the 'set once' section, since this doesn't change over time _uniforms.push_back([=](gpu::Batch& batch) { - batch._glUniform(_standardUniformSlots[SCALE], _entityDimensions); + batch._glUniform(_standardUniformSlots[ORIENTATION], _entityOrientation); }); } @@ -417,6 +421,14 @@ void Procedural::setupUniforms() { batch._glUniform(_standardUniformSlots[POSITION], _entityPosition); }); } + + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[EYE_POSITION]) { + // FIXME move into the 'set once' section, since this doesn't change over time + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform(_standardUniformSlots[EYE_POSITION], _eyePos); + }); + } + } void Procedural::setupChannels(bool shouldCreate) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index f928d0e594..e27f8ade44 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -38,7 +38,7 @@ public: void parse(const QString& userDataJson); bool ready(); - void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size); + void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation, const glm::vec3& eyePos); const gpu::ShaderPointer& getShader() const { return _shader; } glm::vec4 getColor(const glm::vec4& entityColor); @@ -56,6 +56,8 @@ public: FRAME_COUNT, SCALE, POSITION, + ORIENTATION, + EYE_POSITION, CHANNEL_RESOLUTION, NUM_STANDARD_UNIFORMS }; @@ -93,6 +95,8 @@ protected: // Entity metadata glm::vec3 _entityDimensions; glm::vec3 _entityPosition; + glm::quat _entityOrientation; + glm::vec3 _eyePos; private: // This should only be called from the render thread, as it shares data with Procedural::prepare diff --git a/libraries/procedural/src/procedural/ProceduralShaders.h b/libraries/procedural/src/procedural/ProceduralShaders.h index eddf53cb09..00571c3a94 100644 --- a/libraries/procedural/src/procedural/ProceduralShaders.h +++ b/libraries/procedural/src/procedural/ProceduralShaders.h @@ -289,6 +289,8 @@ const vec4 iChannelTime = vec4(0.0); uniform vec4 iDate; uniform int iFrameCount; uniform vec3 iWorldPosition; +uniform mat3 iWorldOrientation; +uniform vec3 iWorldEyePosition; uniform vec3 iChannelResolution[4]; uniform sampler2D iChannel0; uniform sampler2D iChannel1; diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 1aa59c90d7..5905bfb017 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -52,7 +52,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setModelTransform(Transform()); // only for Mac auto& procedural = skybox._procedural; - procedural.prepare(batch, glm::vec3(0), glm::vec3(1)); + procedural.prepare(batch, glm::vec3(0), glm::vec3(1), glm::quat(1, 0, 0, 0), glm::vec3(0)); auto textureSlot = procedural.getShader()->getTextures().findLocation("cubeMap"); auto bufferSlot = procedural.getShader()->getBuffers().findLocation("skyboxBuffer"); skybox.prepare(batch, textureSlot, bufferSlot); From 5650ef9d52b46d486639731747eb2acb154dcfba Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 9 Jun 2016 14:35:17 -0700 Subject: [PATCH 16/45] have code where physics guesses at server values also avoid doing simple simulation of children of avatars --- libraries/entities/src/EntitySimulation.cpp | 2 +- libraries/physics/src/EntityMotionState.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index 8419e4ac6a..a29ea8e2c8 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -263,7 +263,7 @@ void EntitySimulation::moveSimpleKinematics(const quint64& now) { EntityItemPointer entity = *itemItr; // The entity-server doesn't know where avatars are, so don't attempt to do simple extrapolation for - // children of avatars. + // children of avatars. See related code in EntityMotionState::remoteSimulationOutOfSync. bool ancestryIsKnown; entity->getMaximumAACube(ancestryIsKnown); bool hasAvatarAncestor = entity->hasAncestorOfType(NestableType::Avatar); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 053bfcbd85..be7862ade3 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -317,9 +317,19 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { if (glm::length2(_serverVelocity) > 0.0f) { _serverVelocity += _serverAcceleration * dt; _serverVelocity *= powf(1.0f - _body->getLinearDamping(), dt); - // NOTE: we ignore the second-order acceleration term when integrating - // the position forward because Bullet also does this. - _serverPosition += dt * _serverVelocity; + + // the entity-server doesn't know where avatars are, so it doesn't do simple extrapolation for children of + // avatars. We are trying to guess what values the entity server has, so we don't do it here, either. See + // related code in EntitySimulation::moveSimpleKinematics. + bool ancestryIsKnown; + _entity->getMaximumAACube(ancestryIsKnown); + bool hasAvatarAncestor = _entity->hasAncestorOfType(NestableType::Avatar); + + if (ancestryIsKnown && !hasAvatarAncestor) { + // NOTE: we ignore the second-order acceleration term when integrating + // the position forward because Bullet also does this. + _serverPosition += dt * _serverVelocity; + } } if (_entity->actionDataNeedsTransmit()) { From 8cccd5416a3f6a66933979dcc24330fd77fd0f2f Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 9 Jun 2016 16:10:27 -0700 Subject: [PATCH 17/45] try to fix mac errors --- libraries/gpu/src/gpu/Batch.h | 5 +++-- libraries/procedural/src/procedural/Procedural.cpp | 2 +- libraries/procedural/src/procedural/Procedural.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index f8b447975c..e0a0e057f7 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -292,8 +293,8 @@ public: _glUniform4f(location, v.x, v.y, v.z, v.w); } - void _glUniform(int location, const glm::quat& v) { - _glUniformMatrix3fv(location, 1, false, reinterpret_cast< const float* >(&glm::mat3_cast(v))); + void _glUniform(int location, const glm::mat3& v) { + _glUniformMatrix3fv(location, 1, false, glm::value_ptr(v)); } void _glColor4f(float red, float green, float blue, float alpha); diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 4f308e0812..ed3d5712e3 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -207,7 +207,7 @@ bool Procedural::ready() { void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation, const glm::vec3& eyePos) { _entityDimensions = size; _entityPosition = position; - _entityOrientation = orientation; + _entityOrientation = glm::mat3_cast(orientation); _eyePos = eyePos; if (_shaderUrl.isLocalFile()) { auto lastModified = (quint64)QFileInfo(_shaderPath).lastModified().toMSecsSinceEpoch(); diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index e27f8ade44..45dcfd7bf6 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -95,7 +95,7 @@ protected: // Entity metadata glm::vec3 _entityDimensions; glm::vec3 _entityPosition; - glm::quat _entityOrientation; + glm::mat3 _entityOrientation; glm::vec3 _eyePos; private: From e1ae2a193f0e3c510dcaa101ea5a21a984615437 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 10 Jun 2016 11:49:15 -0700 Subject: [PATCH 18/45] EntityMotionState now uses parent-relative position and rotation and velocity when deciding if it needs to send an edit packet to the entity-server --- libraries/physics/src/EntityMotionState.cpp | 41 ++++++------ libraries/physics/src/PhysicsEngine.cpp | 5 ++ libraries/shared/src/SpatiallyNestable.cpp | 69 +++++++++++++++++++++ libraries/shared/src/SpatiallyNestable.h | 22 ++++--- 4 files changed, 110 insertions(+), 27 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index be7862ade3..28f7756d9a 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -85,10 +85,10 @@ void EntityMotionState::updateServerPhysicsVariables() { return; } - _serverPosition = _entity->getPosition(); - _serverRotation = _entity->getRotation(); - _serverVelocity = _entity->getVelocity(); - _serverAngularVelocity = _entity->getAngularVelocity(); + Transform localTransform; + _entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity); + _serverPosition = localTransform.getTranslation(); + _serverRotation = localTransform.getRotation(); _serverAcceleration = _entity->getAcceleration(); _serverActionData = _entity->getActionData(); } @@ -274,11 +274,11 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { // if we've never checked before, our _lastStep will be 0, and we need to initialize our state if (_lastStep == 0) { btTransform xform = _body->getWorldTransform(); - _serverPosition = bulletToGLM(xform.getOrigin()); - _serverRotation = bulletToGLM(xform.getRotation()); - _serverVelocity = getBodyLinearVelocityGTSigma(); + _serverPosition = _entity->worldPositionToParent(bulletToGLM(xform.getOrigin())); + _serverRotation = _entity->worldRotationToParent(bulletToGLM(xform.getRotation())); + _serverVelocity = _entity->worldVelocityToParent(getBodyLinearVelocityGTSigma()); _serverAcceleration = Vectors::ZERO; - _serverAngularVelocity = bulletToGLM(_body->getAngularVelocity()); + _serverAngularVelocity = _entity->worldVelocityToParent(bulletToGLM(_body->getAngularVelocity())); _lastStep = simulationStep; _serverActionData = _entity->getActionData(); _numInactiveUpdates = 1; @@ -315,9 +315,6 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { _lastStep = simulationStep; if (glm::length2(_serverVelocity) > 0.0f) { - _serverVelocity += _serverAcceleration * dt; - _serverVelocity *= powf(1.0f - _body->getLinearDamping(), dt); - // the entity-server doesn't know where avatars are, so it doesn't do simple extrapolation for children of // avatars. We are trying to guess what values the entity server has, so we don't do it here, either. See // related code in EntitySimulation::moveSimpleKinematics. @@ -326,6 +323,9 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { bool hasAvatarAncestor = _entity->hasAncestorOfType(NestableType::Avatar); if (ancestryIsKnown && !hasAvatarAncestor) { + _serverVelocity += _serverAcceleration * dt; + _serverVelocity *= powf(1.0f - _body->getLinearDamping(), dt); + // NOTE: we ignore the second-order acceleration term when integrating // the position forward because Bullet also does this. _serverPosition += dt * _serverVelocity; @@ -351,7 +351,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { // compute position error btTransform worldTrans = _body->getWorldTransform(); - glm::vec3 position = bulletToGLM(worldTrans.getOrigin()); + glm::vec3 position = _entity->worldPositionToParent(bulletToGLM(worldTrans.getOrigin())); float dx2 = glm::distance2(position, _serverPosition); const float MAX_POSITION_ERROR_SQUARED = 0.000004f; // corresponds to 2mm @@ -386,7 +386,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { } } const float MIN_ROTATION_DOT = 0.99999f; // This corresponds to about 0.5 degrees of rotation - glm::quat actualRotation = bulletToGLM(worldTrans.getRotation()); + glm::quat actualRotation = _entity->worldRotationToParent(bulletToGLM(worldTrans.getRotation())); #ifdef WANT_DEBUG if ((fabsf(glm::dot(actualRotation, _serverRotation)) < MIN_ROTATION_DOT)) { @@ -491,11 +491,11 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ } // remember properties for local server prediction - _serverPosition = _entity->getPosition(); - _serverRotation = _entity->getRotation(); - _serverVelocity = _entity->getVelocity(); + Transform localTransform; + _entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity); + _serverPosition = localTransform.getTranslation(); + _serverRotation = localTransform.getRotation(); _serverAcceleration = _entity->getAcceleration(); - _serverAngularVelocity = _entity->getAngularVelocity(); _serverActionData = _entity->getActionData(); EntityItemProperties properties; @@ -600,7 +600,7 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() { if (_body && _entity) { dirtyFlags = _entity->getDirtyFlags(); - if (dirtyFlags | Simulation::DIRTY_SIMULATOR_ID) { + if (dirtyFlags & Simulation::DIRTY_SIMULATOR_ID) { // when SIMULATOR_ID changes we must check for reinterpretation of asymmetric collision mask // bits for the avatar groups (e.g. MY_AVATAR vs OTHER_AVATAR) uint8_t entityCollisionMask = _entity->getCollisionless() ? 0 : _entity->getCollisionMask(); @@ -613,8 +613,9 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() { // we add DIRTY_MOTION_TYPE if the body's motion type disagrees with entity velocity settings int bodyFlags = _body->getCollisionFlags(); bool isMoving = _entity->isMovingRelativeToParent(); - if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) || - (bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving)) { + if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) // || + // (bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving) + ) { dirtyFlags |= Simulation::DIRTY_MOTION_TYPE; } } diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index d3247ec62c..6f8acfa6a7 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -75,6 +75,7 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { motionState->setMotionType(motionType); switch(motionType) { case MOTION_TYPE_KINEMATIC: { + qDebug() << " --> KINEMATIC"; if (!body) { btCollisionShape* shape = motionState->getShape(); assert(shape); @@ -91,6 +92,8 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { break; } case MOTION_TYPE_DYNAMIC: { + qDebug() << " --> DYNAMIC"; + mass = motionState->getMass(); btCollisionShape* shape = motionState->getShape(); assert(shape); @@ -117,6 +120,8 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { } case MOTION_TYPE_STATIC: default: { + qDebug() << " --> STATIC"; + if (!body) { assert(motionState->getShape()); body = new btRigidBody(mass, motionState, motionState->getShape(), inertia); diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 2a3cb4af47..6edf80ab98 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -174,6 +174,66 @@ glm::vec3 SpatiallyNestable::worldToLocal(const glm::vec3& position, return result.getTranslation(); } +glm::vec3 SpatiallyNestable::worldPositionToParent(const glm::vec3& position) { + bool success; + glm::vec3 result = SpatiallyNestable::worldToLocal(position, getParentID(), getParentJointIndex(), success); + if (!success) { + qDebug() << "Warning -- worldToLocal failed" << getID(); + } + return result; +} + +glm::vec3 SpatiallyNestable::worldVelocityToLocal(const glm::vec3& velocity, // can be linear or angular + const QUuid& parentID, int parentJointIndex, + bool& success) { + Transform result; + QSharedPointer parentFinder = DependencyManager::get(); + if (!parentFinder) { + success = false; + return glm::vec3(); + } + + Transform parentTransform; + auto parentWP = parentFinder->find(parentID, success); + if (!success) { + return glm::vec3(); + } + + auto parent = parentWP.lock(); + if (!parentID.isNull() && !parent) { + success = false; + return glm::vec3(); + } + + if (parent) { + parentTransform = parent->getTransform(parentJointIndex, success); + if (!success) { + return glm::vec3(); + } + parentTransform.setScale(1.0f); // TODO: scale + } + success = true; + + parentTransform.setTranslation(glm::vec3(0.0f)); + + Transform velocityTransform; + velocityTransform.setTranslation(velocity); + Transform myWorldTransform; + Transform::mult(myWorldTransform, parentTransform, velocityTransform); + myWorldTransform.setTranslation(velocity); + Transform::inverseMult(result, parentTransform, myWorldTransform); + return result.getTranslation(); +} + +glm::vec3 SpatiallyNestable::worldVelocityToParent(const glm::vec3& velocity) { + bool success; + glm::vec3 result = SpatiallyNestable::worldVelocityToLocal(velocity, getParentID(), getParentJointIndex(), success); + if (!success) { + qDebug() << "Warning -- worldVelocityToLocal failed" << getID(); + } + return result; +} + glm::quat SpatiallyNestable::worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success) { @@ -214,6 +274,15 @@ glm::quat SpatiallyNestable::worldToLocal(const glm::quat& orientation, return result.getRotation(); } +glm::quat SpatiallyNestable::worldRotationToParent(const glm::quat& orientation) { + bool success; + glm::quat result = SpatiallyNestable::worldToLocal(orientation, getParentID(), getParentJointIndex(), success); + if (!success) { + qDebug() << "Warning -- worldToLocal failed" << getID(); + } + return result; +} + glm::vec3 SpatiallyNestable::localToWorld(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success) { diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 04bb57a688..ffb00ac040 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -46,11 +46,17 @@ public: virtual void setParentJointIndex(quint16 parentJointIndex); static glm::vec3 worldToLocal(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success); + static glm::vec3 worldVelocityToLocal(const glm::vec3& position, const QUuid& parentID, + int parentJointIndex, bool& success); static glm::quat worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success); static glm::vec3 localToWorld(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success); static glm::quat localToWorld(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success); + glm::vec3 worldPositionToParent(const glm::vec3& position); + glm::vec3 worldVelocityToParent(const glm::vec3& velocity); + glm::quat worldRotationToParent(const glm::quat& orientation); + // world frame virtual const Transform getTransform(bool& success, int depth = 0) const; virtual void setTransform(const Transform& transform, bool& success); @@ -144,6 +150,15 @@ public: bool hasAncestorOfType(NestableType nestableType); + void getLocalTransformAndVelocities(Transform& localTransform, + glm::vec3& localVelocity, + glm::vec3& localAngularVelocity) const; + + void setLocalTransformAndVelocities( + const Transform& localTransform, + const glm::vec3& localVelocity, + const glm::vec3& localAngularVelocity); + protected: const NestableType _nestableType; // EntityItem or an AvatarData QUuid _id; @@ -151,13 +166,6 @@ protected: quint16 _parentJointIndex { 0 }; // which joint of the parent is this relative to? SpatiallyNestablePointer getParentPointer(bool& success) const; - void getLocalTransformAndVelocities(Transform& localTransform, glm::vec3& localVelocity, glm::vec3& localAngularVelocity) const; - - void setLocalTransformAndVelocities( - const Transform& localTransform, - const glm::vec3& localVelocity, - const glm::vec3& localAngularVelocity); - mutable SpatiallyNestableWeakPointer _parent; virtual void beParentOfChild(SpatiallyNestablePointer newChild) const; From 41c399897a2eec5d3ad3ed43d59aa12c1879f0ed Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 10 Jun 2016 12:08:13 -0700 Subject: [PATCH 19/45] remove some debug prints --- libraries/physics/src/EntityMotionState.cpp | 2 ++ libraries/physics/src/PhysicsEngine.cpp | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 28f7756d9a..e5957ce7b2 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -613,6 +613,8 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() { // we add DIRTY_MOTION_TYPE if the body's motion type disagrees with entity velocity settings int bodyFlags = _body->getCollisionFlags(); bool isMoving = _entity->isMovingRelativeToParent(); + + // XXX what's right, here? if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) // || // (bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving) ) { diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 6f8acfa6a7..d3247ec62c 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -75,7 +75,6 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { motionState->setMotionType(motionType); switch(motionType) { case MOTION_TYPE_KINEMATIC: { - qDebug() << " --> KINEMATIC"; if (!body) { btCollisionShape* shape = motionState->getShape(); assert(shape); @@ -92,8 +91,6 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { break; } case MOTION_TYPE_DYNAMIC: { - qDebug() << " --> DYNAMIC"; - mass = motionState->getMass(); btCollisionShape* shape = motionState->getShape(); assert(shape); @@ -120,8 +117,6 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) { } case MOTION_TYPE_STATIC: default: { - qDebug() << " --> STATIC"; - if (!body) { assert(motionState->getShape()); body = new btRigidBody(mass, motionState, motionState->getShape(), inertia); From da98ee0916b904cd963f05c67c2a7c8264d0baee Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 10 Jun 2016 13:42:19 -0700 Subject: [PATCH 20/45] reorganized procedural shader code, added getWorldEyeWorldPos(), removed iWorldEyePosition --- .../src/RenderableProceduralItemShader.h | 382 ------------------ libraries/gpu/src/gpu/Transform.slh | 4 + .../procedural/src/procedural/Procedural.cpp | 13 +- .../procedural/src/procedural/Procedural.h | 1 - ...oceduralShaders.h => ProceduralCommon.slf} | 22 +- .../src/procedural/ProceduralSkybox.cpp | 2 +- 6 files changed, 16 insertions(+), 408 deletions(-) delete mode 100644 libraries/entities-renderer/src/RenderableProceduralItemShader.h rename libraries/procedural/src/procedural/{ProceduralShaders.h => ProceduralCommon.slf} (94%) diff --git a/libraries/entities-renderer/src/RenderableProceduralItemShader.h b/libraries/entities-renderer/src/RenderableProceduralItemShader.h deleted file mode 100644 index d7df43de14..0000000000 --- a/libraries/entities-renderer/src/RenderableProceduralItemShader.h +++ /dev/null @@ -1,382 +0,0 @@ -// -// Created by Bradley Austin Davis on 2015/09/05 -// Copyright 2013-2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Shader includes portions of webgl-noise: -// Description : Array and textureless GLSL 2D/3D/4D simplex -// noise functions. -// Author : Ian McEwan, Ashima Arts. -// Maintainer : ijm -// Lastmod : 20110822 (ijm) -// License : Copyright (C) 2011 Ashima Arts. All rights reserved. -// Distributed under the MIT License. See LICENSE file. -// https://github.com/ashima/webgl-noise -// - - -const QString SHADER_COMMON = R"SHADER( -layout(location = 0) out vec4 _fragColor0; -layout(location = 1) out vec4 _fragColor1; -layout(location = 2) out vec4 _fragColor2; - -// the alpha threshold -uniform float alphaThreshold; - -vec2 signNotZero(vec2 v) { - return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0); -} - -vec2 float32x3_to_oct(in vec3 v) { - vec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z))); - return ((v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p); -} - - -vec3 oct_to_float32x3(in vec2 e) { - vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y)); - if (v.z < 0) { - v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy); - } - return normalize(v); -} - -vec3 snorm12x2_to_unorm8x3(vec2 f) { - vec2 u = vec2(round(clamp(f, -1.0, 1.0) * 2047.0 + 2047.0)); - float t = floor(u.y / 256.0); - - return floor(vec3( - u.x / 16.0, - fract(u.x / 16.0) * 256.0 + t, - u.y - t * 256.0 - )) / 255.0; -} - -vec2 unorm8x3_to_snorm12x2(vec3 u) { - u *= 255.0; - u.y *= (1.0 / 16.0); - vec2 s = vec2( u.x * 16.0 + floor(u.y), - fract(u.y) * (16.0 * 256.0) + u.z); - return clamp(s * (1.0 / 2047.0) - 1.0, vec2(-1.0), vec2(1.0)); -} - -float mod289(float x) { - return x - floor(x * (1.0 / 289.0)) * 289.0; -} - -vec2 mod289(vec2 x) { - return x - floor(x * (1.0 / 289.0)) * 289.0; -} - -vec3 mod289(vec3 x) { - return x - floor(x * (1.0 / 289.0)) * 289.0; -} - -vec4 mod289(vec4 x) { - return x - floor(x * (1.0 / 289.0)) * 289.0; -} - -float permute(float x) { - return mod289(((x*34.0)+1.0)*x); -} - -vec3 permute(vec3 x) { - return mod289(((x*34.0)+1.0)*x); -} - -vec4 permute(vec4 x) { - return mod289(((x*34.0)+1.0)*x); -} - -float taylorInvSqrt(float r) { - return 1.79284291400159 - 0.85373472095314 * r; -} - -vec4 taylorInvSqrt(vec4 r) { - return 1.79284291400159 - 0.85373472095314 * r; -} - -vec4 grad4(float j, vec4 ip) { - const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); - vec4 p, s; - - p.xyz = floor(fract(vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0; - p.w = 1.5 - dot(abs(p.xyz), ones.xyz); - s = vec4(lessThan(p, vec4(0.0))); - p.xyz = p.xyz + (s.xyz * 2.0 - 1.0) * s.www; - - return p; -} - -// (sqrt(5) - 1)/4 = F4, used once below -#define F4 0.309016994374947451 - -float snoise(vec4 v) { - const vec4 C = vec4(0.138196601125011, // (5 - sqrt(5))/20 G4 - 0.276393202250021, // 2 * G4 - 0.414589803375032, // 3 * G4 - -0.447213595499958); // -1 + 4 * G4 - - // First corner - vec4 i = floor(v + dot(v, vec4(F4))); - vec4 x0 = v - i + dot(i, C.xxxx); - - // Other corners - - // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) - vec4 i0; - vec3 isX = step(x0.yzw, x0.xxx); - vec3 isYZ = step(x0.zww, x0.yyz); - i0.x = isX.x + isX.y + isX.z; - i0.yzw = 1.0 - isX; - i0.y += isYZ.x + isYZ.y; - i0.zw += 1.0 - isYZ.xy; - i0.z += isYZ.z; - i0.w += 1.0 - isYZ.z; - - // i0 now contains the unique values 0,1,2,3 in each channel - vec4 i3 = clamp(i0, 0.0, 1.0); - vec4 i2 = clamp(i0 - 1.0, 0.0, 1.0); - vec4 i1 = clamp(i0 - 2.0, 0.0, 1.0); - - vec4 x1 = x0 - i1 + C.xxxx; - vec4 x2 = x0 - i2 + C.yyyy; - vec4 x3 = x0 - i3 + C.zzzz; - vec4 x4 = x0 + C.wwww; - - // Permutations - i = mod289(i); - float j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x); - vec4 j1 = permute( - permute( - permute( - permute(i.w + vec4(i1.w, i2.w, i3.w, 1.0)) + i.z - + vec4(i1.z, i2.z, i3.z, 1.0)) + i.y - + vec4(i1.y, i2.y, i3.y, 1.0)) + i.x - + vec4(i1.x, i2.x, i3.x, 1.0)); - - // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope - // 7*7*6 = 294, which is close to the ring size 17*17 = 289. - vec4 ip = vec4(1.0 / 294.0, 1.0 / 49.0, 1.0 / 7.0, 0.0); - - vec4 p0 = grad4(j0, ip); - vec4 p1 = grad4(j1.x, ip); - vec4 p2 = grad4(j1.y, ip); - vec4 p3 = grad4(j1.z, ip); - vec4 p4 = grad4(j1.w, ip); - - // Normalise gradients - vec4 norm = taylorInvSqrt( - vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); - p0 *= norm.x; - p1 *= norm.y; - p2 *= norm.z; - p3 *= norm.w; - p4 *= taylorInvSqrt(dot(p4, p4)); - - // Mix contributions from the five corners - vec3 m0 = max(0.6 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0); - vec2 m1 = max(0.6 - vec2(dot(x3, x3), dot(x4, x4)), 0.0); - m0 = m0 * m0; - m1 = m1 * m1; - return 49.0 - * (dot(m0 * m0, vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2))) - + dot(m1 * m1, vec2(dot(p3, x3), dot(p4, x4)))); - -} - -float snoise(vec3 v) { - const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0); - const vec4 D = vec4(0.0, 0.5, 1.0, 2.0); - - // First corner - vec3 i = floor(v + dot(v, C.yyy)); - vec3 x0 = v - i + dot(i, C.xxx); - - // Other corners - vec3 g = step(x0.yzx, x0.xyz); - vec3 l = 1.0 - g; - vec3 i1 = min(g.xyz, l.zxy); - vec3 i2 = max(g.xyz, l.zxy); - - vec3 x1 = x0 - i1 + C.xxx; - vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y - vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y - - // Permutations - i = mod289(i); - vec4 p = permute( - permute( - permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y - + vec4(0.0, i1.y, i2.y, 1.0)) + i.x - + vec4(0.0, i1.x, i2.x, 1.0)); - - // Gradients: 7x7 points over a square, mapped onto an octahedron. - // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294) - float n_ = 0.142857142857; // 1.0/7.0 - vec3 ns = n_ * D.wyz - D.xzx; - - vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7) - - vec4 x_ = floor(j * ns.z); - vec4 y_ = floor(j - 7.0 * x_); // mod(j,N) - - vec4 x = x_ * ns.x + ns.yyyy; - vec4 y = y_ * ns.x + ns.yyyy; - vec4 h = 1.0 - abs(x) - abs(y); - - vec4 b0 = vec4(x.xy, y.xy); - vec4 b1 = vec4(x.zw, y.zw); - - //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0; - //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0; - vec4 s0 = floor(b0) * 2.0 + 1.0; - vec4 s1 = floor(b1) * 2.0 + 1.0; - vec4 sh = -step(h, vec4(0.0)); - - vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; - vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww; - - vec3 p0 = vec3(a0.xy, h.x); - vec3 p1 = vec3(a0.zw, h.y); - vec3 p2 = vec3(a1.xy, h.z); - vec3 p3 = vec3(a1.zw, h.w); - - //Normalise gradients - vec4 norm = taylorInvSqrt( - vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3))); - p0 *= norm.x; - p1 *= norm.y; - p2 *= norm.z; - p3 *= norm.w; - - // Mix final noise value - vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), - 0.0); - m = m * m; - return 42.0 - * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))); -} - -float snoise(vec2 v) { - const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0 - 0.366025403784439, // 0.5*(sqrt(3.0)-1.0) - -0.577350269189626, // -1.0 + 2.0 * C.x - 0.024390243902439); // 1.0 / 41.0 - // First corner - vec2 i = floor(v + dot(v, C.yy)); - vec2 x0 = v - i + dot(i, C.xx); - - // Other corners - vec2 i1; - i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); - vec4 x12 = x0.xyxy + C.xxzz; - x12.xy -= i1; - - // Permutations - i = mod289(i); // Avoid truncation effects in permutation - vec3 p = permute( - permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0)); - - vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), - 0.0); - m = m * m; - m = m * m; - - // Gradients: 41 points uniformly over a line, mapped onto a diamond. - // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287) - - vec3 x = 2.0 * fract(p * C.www) - 1.0; - vec3 h = abs(x) - 0.5; - vec3 ox = floor(x + 0.5); - vec3 a0 = x - ox; - - // Normalise gradients implicitly by scaling m - // Approximation of: m *= inversesqrt( a0*a0 + h*h ); - m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h); - - // Compute final noise value at P - vec3 g; - g.x = a0.x * x0.x + h.x * x0.y; - g.yz = a0.yz * x12.xz + h.yz * x12.yw; - return 130.0 * dot(m, g); -} - -// the interpolated normal -in vec3 _normal; -in vec3 _color; -in vec2 _texCoord0; -in vec4 _position; - -// TODO add more uniforms -uniform float iGlobalTime; // shader playback time (in seconds) -uniform vec3 iWorldScale; // the dimensions of the object being rendered -uniform mat3 iWorldOrientation; // the orientation of the object being rendered -uniform vec3 iWorldEyePosition; // the world position of the eye - -// TODO add support for textures -// TODO document available inputs other than the uniforms -// TODO provide world scale in addition to the untransformed position - -const vec3 DEFAULT_SPECULAR = vec3(0.1); -const float DEFAULT_SHININESS = 10; - -)SHADER"; - -// V1 shaders, only support emissive -// vec4 getProceduralColor() -const QString SHADER_TEMPLATE_V1 = SHADER_COMMON + R"SCRIBE( - -#line 1001 -%1 -#line 317 - -void main(void) { - vec4 emissive = getProceduralColor(); - - float alpha = emissive.a; - if (alpha != 1.0) { - discard; - } - - vec4 diffuse = vec4(_color.rgb, alpha); - vec4 normal = vec4(packNormal(normalize(_normal)), 0.5); - - _fragColor0 = diffuse; - _fragColor1 = normal; - _fragColor2 = vec4(emissive.rgb, DEFAULT_SHININESS / 128.0); -} - -)SCRIBE"; - -// void getProceduralDiffuseAndEmissive(out vec4 diffuse, out vec4 emissive) -const QString SHADER_TEMPLATE_V2 = SHADER_COMMON + R"SCRIBE( -// FIXME should we be doing the swizzle here? -vec3 iResolution = iWorldScale.xzy; - -// FIXME Mouse X,Y coordinates, and Z,W are for the click position if clicked (not supported in High Fidelity at the moment) -vec4 iMouse = vec4(0); - -// FIXME We set the seconds (iDate.w) of iDate to iGlobalTime, which contains the current date in seconds -vec4 iDate = vec4(0, 0, 0, iGlobalTime); - - -#line 1001 -%1 -#line 351 - -void main(void) { - vec3 diffuse = _color.rgb; - vec3 specular = DEFAULT_SPECULAR; - float shininess = DEFAULT_SHININESS; - - float emissiveAmount = getProceduralColors(diffuse, specular, shininess); - - _fragColor0 = vec4(diffuse.rgb, 1.0); - _fragColor1 = vec4(packNormal(normalize(_normal.xyz)), 1.0 - (emissiveAmount / 2.0)); - _fragColor2 = vec4(specular, shininess / 128.0); -} -)SCRIBE"; diff --git a/libraries/gpu/src/gpu/Transform.slh b/libraries/gpu/src/gpu/Transform.slh index 246167e186..20629c5f32 100644 --- a/libraries/gpu/src/gpu/Transform.slh +++ b/libraries/gpu/src/gpu/Transform.slh @@ -27,6 +27,10 @@ layout(std140) uniform transformCameraBuffer { TransformCamera getTransformCamera() { return _camera; } + +vec3 getEyeWorldPos() { + return _camera._viewInverse[3].xyz; +} <@endfunc@> diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index ed3d5712e3..c9ed959087 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -19,7 +19,7 @@ #include #include -#include "ProceduralShaders.h" +#include "ProceduralCommon_frag.h" // Userdata parsing constants static const QString PROCEDURAL_USER_DATA_KEY = "ProceduralEntity"; @@ -40,7 +40,6 @@ static const std::string STANDARD_UNIFORM_NAMES[Procedural::NUM_STANDARD_UNIFORM "iWorldScale", "iWorldPosition", "iWorldOrientation", - "iWorldEyePosition", "iChannelResolution" }; @@ -231,7 +230,7 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm std::string fragmentShaderSource = _fragmentSource; size_t replaceIndex = fragmentShaderSource.find(PROCEDURAL_COMMON_BLOCK); if (replaceIndex != std::string::npos) { - fragmentShaderSource.replace(replaceIndex, PROCEDURAL_COMMON_BLOCK.size(), SHADER_COMMON); + fragmentShaderSource.replace(replaceIndex, PROCEDURAL_COMMON_BLOCK.size(), ProceduralCommon_frag); } replaceIndex = fragmentShaderSource.find(PROCEDURAL_VERSION); @@ -421,14 +420,6 @@ void Procedural::setupUniforms() { batch._glUniform(_standardUniformSlots[POSITION], _entityPosition); }); } - - if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[EYE_POSITION]) { - // FIXME move into the 'set once' section, since this doesn't change over time - _uniforms.push_back([=](gpu::Batch& batch) { - batch._glUniform(_standardUniformSlots[EYE_POSITION], _eyePos); - }); - } - } void Procedural::setupChannels(bool shouldCreate) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 45dcfd7bf6..e551afe004 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -57,7 +57,6 @@ public: SCALE, POSITION, ORIENTATION, - EYE_POSITION, CHANNEL_RESOLUTION, NUM_STANDARD_UNIFORMS }; diff --git a/libraries/procedural/src/procedural/ProceduralShaders.h b/libraries/procedural/src/procedural/ProceduralCommon.slf similarity index 94% rename from libraries/procedural/src/procedural/ProceduralShaders.h rename to libraries/procedural/src/procedural/ProceduralCommon.slf index 00571c3a94..09fb1b0b04 100644 --- a/libraries/procedural/src/procedural/ProceduralShaders.h +++ b/libraries/procedural/src/procedural/ProceduralCommon.slf @@ -1,3 +1,5 @@ +<@include gpu/Config.slh@> +// Generated on <$_SCRIBE_DATE$> // // Created by Bradley Austin Davis on 2015/09/05 // Copyright 2013-2015 High Fidelity, Inc. @@ -17,8 +19,8 @@ // https://github.com/ashima/webgl-noise // - -const std::string SHADER_COMMON = R"SHADER( +<@include gpu/Transform.slh@> +<$declareStandardCameraTransform()$> float mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; @@ -262,11 +264,6 @@ float snoise(vec2 v) { return 130.0 * dot(m, g); } -// shader playback time (in seconds) -uniform float iGlobalTime; -// the dimensions of the object being rendered -uniform vec3 iWorldScale; - #define PROCEDURAL 1 //PROCEDURAL_VERSION @@ -286,17 +283,16 @@ const float iSampleRate = 1.0; const vec4 iChannelTime = vec4(0.0); +uniform float iGlobalTime; // shader playback time (in seconds) uniform vec4 iDate; uniform int iFrameCount; -uniform vec3 iWorldPosition; -uniform mat3 iWorldOrientation; -uniform vec3 iWorldEyePosition; +uniform vec3 iWorldPosition; // the position of the object being rendered +uniform vec3 iWorldScale; // the dimensions of the object being rendered +uniform mat3 iWorldOrientation; // the orientation of the object being rendered uniform vec3 iChannelResolution[4]; uniform sampler2D iChannel0; uniform sampler2D iChannel1; uniform sampler2D iChannel2; uniform sampler2D iChannel3; -#endif - -)SHADER"; +#endif \ No newline at end of file diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 5905bfb017..7ba711bdb1 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -52,7 +52,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setModelTransform(Transform()); // only for Mac auto& procedural = skybox._procedural; - procedural.prepare(batch, glm::vec3(0), glm::vec3(1), glm::quat(1, 0, 0, 0), glm::vec3(0)); + procedural.prepare(batch, glm::vec3(0), glm::vec3(1), glm::quat(), glm::vec3(0)); auto textureSlot = procedural.getShader()->getTextures().findLocation("cubeMap"); auto bufferSlot = procedural.getShader()->getBuffers().findLocation("skyboxBuffer"); skybox.prepare(batch, textureSlot, bufferSlot); From f32e29ac2df13b536586932a2b8d1bf0671ab759 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 10 Jun 2016 13:46:02 -0700 Subject: [PATCH 21/45] small changes --- libraries/gpu/src/gpu/Batch.h | 2 +- libraries/gpu/src/gpu/Context.h | 2 +- libraries/procedural/src/procedural/ProceduralCommon.slf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index e0a0e057f7..4e51038368 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -453,7 +453,7 @@ public: Params _params; Bytes _data; - // SSBO class... layout MUST match the layout in TransformCamera.slh + // SSBO class... layout MUST match the layout in Transform.slh class TransformObject { public: Mat4 _model; diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index cead2c623d..652338f911 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -95,7 +95,7 @@ public: virtual void syncCache() = 0; virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) = 0; - // UBO class... layout MUST match the layout in TransformCamera.slh + // UBO class... layout MUST match the layout in Transform.slh class TransformCamera { public: mutable Mat4 _view; diff --git a/libraries/procedural/src/procedural/ProceduralCommon.slf b/libraries/procedural/src/procedural/ProceduralCommon.slf index 09fb1b0b04..128723265f 100644 --- a/libraries/procedural/src/procedural/ProceduralCommon.slf +++ b/libraries/procedural/src/procedural/ProceduralCommon.slf @@ -23,7 +23,7 @@ <$declareStandardCameraTransform()$> float mod289(float x) { - return x - floor(x * (1.0 / 289.0)) * 289.0; + return x - floor(x * (1.0 / 289.0)) * 289.0; } vec2 mod289(vec2 x) { From 53435fc7301b3ec0dea8779e60b784305858a515 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 10 Jun 2016 14:04:33 -0700 Subject: [PATCH 22/45] removed extra argument --- libraries/entities-renderer/src/RenderableShapeEntityItem.cpp | 2 +- libraries/procedural/src/procedural/Procedural.cpp | 3 +-- libraries/procedural/src/procedural/Procedural.h | 3 +-- libraries/procedural/src/procedural/ProceduralSkybox.cpp | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index 2b04478831..ec07e10ccf 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -98,7 +98,7 @@ void RenderableShapeEntityItem::render(RenderArgs* args) { } batch.setModelTransform(modelTransform); // use a transform with scale, rotation, registration point and translation if (_procedural->ready()) { - _procedural->prepare(batch, getPosition(), getDimensions(), getOrientation(), args->getViewFrustum().getPosition()); + _procedural->prepare(batch, getPosition(), getDimensions(), getOrientation()); auto outColor = _procedural->getColor(color); batch._glColor4f(outColor.r, outColor.g, outColor.b, outColor.a); DependencyManager::get()->renderShape(batch, MAPPING[_shape]); diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index c9ed959087..a9a297a2e1 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -203,11 +203,10 @@ bool Procedural::ready() { return true; } -void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation, const glm::vec3& eyePos) { +void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation) { _entityDimensions = size; _entityPosition = position; _entityOrientation = glm::mat3_cast(orientation); - _eyePos = eyePos; if (_shaderUrl.isLocalFile()) { auto lastModified = (quint64)QFileInfo(_shaderPath).lastModified().toMSecsSinceEpoch(); if (lastModified > _shaderModified) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index e551afe004..6991b47946 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -38,7 +38,7 @@ public: void parse(const QString& userDataJson); bool ready(); - void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation, const glm::vec3& eyePos); + void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size, const glm::quat& orientation); const gpu::ShaderPointer& getShader() const { return _shader; } glm::vec4 getColor(const glm::vec4& entityColor); @@ -95,7 +95,6 @@ protected: glm::vec3 _entityDimensions; glm::vec3 _entityPosition; glm::mat3 _entityOrientation; - glm::vec3 _eyePos; private: // This should only be called from the render thread, as it shares data with Procedural::prepare diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 7ba711bdb1..9e9a26d902 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -52,7 +52,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setModelTransform(Transform()); // only for Mac auto& procedural = skybox._procedural; - procedural.prepare(batch, glm::vec3(0), glm::vec3(1), glm::quat(), glm::vec3(0)); + procedural.prepare(batch, glm::vec3(0), glm::vec3(1), glm::quat()); auto textureSlot = procedural.getShader()->getTextures().findLocation("cubeMap"); auto bufferSlot = procedural.getShader()->getBuffers().findLocation("skyboxBuffer"); skybox.prepare(batch, textureSlot, bufferSlot); From 7b21d711804e45cdbb121ecca0f9e189b2665f8e Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 10 Jun 2016 14:09:04 -0700 Subject: [PATCH 23/45] try to fix cmake error --- libraries/procedural/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/procedural/CMakeLists.txt b/libraries/procedural/CMakeLists.txt index 7145f7de5c..a2c1a019de 100644 --- a/libraries/procedural/CMakeLists.txt +++ b/libraries/procedural/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME procedural) -AUTOSCRIBE_SHADER_LIB(gpu model) +AUTOSCRIBE_SHADER_LIB(gpu model procedural) setup_hifi_library() link_hifi_libraries(shared gpu gpu-gl networking model model-networking) From 8a682450a9b88b0feb7e881bf2b238249d36ff0f Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Fri, 10 Jun 2016 17:01:22 -0700 Subject: [PATCH 24/45] still trying to fix cmake errors --- libraries/entities-renderer/CMakeLists.txt | 2 +- libraries/gpu-gl/CMakeLists.txt | 1 - libraries/procedural/CMakeLists.txt | 2 +- libraries/render-utils/CMakeLists.txt | 2 +- libraries/render/CMakeLists.txt | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index bb90c04c95..0063f4a701 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME entities-renderer) -AUTOSCRIBE_SHADER_LIB(gpu model render render-utils) +AUTOSCRIBE_SHADER_LIB(gpu model procedural render render-utils) setup_hifi_library(Widgets Network Script) link_hifi_libraries(shared gpu procedural model model-networking script-engine render render-utils) diff --git a/libraries/gpu-gl/CMakeLists.txt b/libraries/gpu-gl/CMakeLists.txt index dfac6dd516..398fdd04d6 100644 --- a/libraries/gpu-gl/CMakeLists.txt +++ b/libraries/gpu-gl/CMakeLists.txt @@ -1,5 +1,4 @@ set(TARGET_NAME gpu-gl) -AUTOSCRIBE_SHADER_LIB(gpu) setup_hifi_library() link_hifi_libraries(shared gl gpu) GroupSources("src") diff --git a/libraries/procedural/CMakeLists.txt b/libraries/procedural/CMakeLists.txt index a2c1a019de..7145f7de5c 100644 --- a/libraries/procedural/CMakeLists.txt +++ b/libraries/procedural/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME procedural) -AUTOSCRIBE_SHADER_LIB(gpu model procedural) +AUTOSCRIBE_SHADER_LIB(gpu model) setup_hifi_library() link_hifi_libraries(shared gpu gpu-gl networking model model-networking) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index c4f28aeffd..2a7d33e33a 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME render-utils) -AUTOSCRIBE_SHADER_LIB(gpu model render) +AUTOSCRIBE_SHADER_LIB(gpu model render procedural) # pull in the resources.qrc file qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts.qrc") setup_hifi_library(Widgets OpenGL Network Qml Quick Script) diff --git a/libraries/render/CMakeLists.txt b/libraries/render/CMakeLists.txt index 76fc8303ce..c5cfdf3668 100644 --- a/libraries/render/CMakeLists.txt +++ b/libraries/render/CMakeLists.txt @@ -1,5 +1,5 @@ set(TARGET_NAME render) -AUTOSCRIBE_SHADER_LIB(gpu model) +AUTOSCRIBE_SHADER_LIB(gpu model procedural) setup_hifi_library() link_hifi_libraries(shared gpu model) From 58f89c88a2af16b3d42e2f9357e4e5c3cc2a42a8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 11 Jun 2016 16:45:17 +1200 Subject: [PATCH 25/45] Remember last directory used for Window.browse() and Window.save() Use last directory if not specified in method call. Default to desktop. --- .../scripting/WindowScriptingInterface.cpp | 36 +++++++++++++++++-- .../src/scripting/WindowScriptingInterface.h | 4 +++ scripts/system/edit.js | 3 +- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 0443c65453..6579366cf8 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -14,6 +14,8 @@ #include #include +#include + #include "Application.h" #include "DomainHandler.h" #include "MainWindow.h" @@ -23,6 +25,10 @@ #include "WindowScriptingInterface.h" +static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); +static const QString LAST_BROWSE_LOCATION_SETTING = "LastBrowseLocation"; + + WindowScriptingInterface::WindowScriptingInterface() { const DomainHandler& domainHandler = DependencyManager::get()->getDomainHandler(); connect(&domainHandler, &DomainHandler::connectedToDomain, this, &WindowScriptingInterface::domainChanged); @@ -101,6 +107,14 @@ QString fixupPathForMac(const QString& directory) { return path; } +QString WindowScriptingInterface::getPreviousBrowseLocation() const { + return Setting::Handle(LAST_BROWSE_LOCATION_SETTING, DESKTOP_LOCATION).get(); +} + +void WindowScriptingInterface::setPreviousBrowseLocation(const QString& location) { + Setting::Handle(LAST_BROWSE_LOCATION_SETTING).set(location); +} + /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current /// working directory. /// \param const QString& title title of the window @@ -108,8 +122,17 @@ QString fixupPathForMac(const QString& directory) { /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { - QString path = fixupPathForMac(directory); + QString path = directory; + if (path == "") { + path = getPreviousBrowseLocation(); + } +#ifndef Q_OS_WIN + path = fixupPathForMac(directory); +#endif QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter); + if (!result.isEmpty()) { + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); + } return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); } @@ -120,8 +143,17 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { - QString path = fixupPathForMac(directory); + QString path = directory; + if (path == "") { + path = getPreviousBrowseLocation(); + } +#ifndef Q_OS_WIN + path = fixupPathForMac(directory); +#endif QString result = OffscreenUi::getSaveFileName(nullptr, title, path, nameFilter); + if (!result.isEmpty()) { + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); + } return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); } diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index dfe02a5064..b92114c1bf 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -49,6 +49,10 @@ signals: private slots: WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height); + +private: + QString getPreviousBrowseLocation() const; + void setPreviousBrowseLocation(const QString& location); }; #endif // hifi_WindowScriptingInterface_h diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 1232c8d94d..42eddf11c3 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -1221,8 +1221,7 @@ function handeMenuEvent(menuItem) { if (!selectionManager.hasSelection()) { Window.alert("No entities have been selected."); } else { - var filename = "entities__" + Window.location.hostname + ".svo.json"; - filename = Window.save("Select Where to Save", filename, "*.json") + var filename = Window.save("Select Where to Save", "", "*.json") if (filename) { var success = Clipboard.exportEntities(filename, selectionManager.selections); if (!success) { From d74f1c8b5dc93ce543af94a55036317f0612d917 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 13 Jun 2016 14:51:14 +1200 Subject: [PATCH 26/45] Fix default directory for Settings directory preference fields --- .../qml/dialogs/preferences/BrowsablePreference.qml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/resources/qml/dialogs/preferences/BrowsablePreference.qml b/interface/resources/qml/dialogs/preferences/BrowsablePreference.qml index 9a19889938..2cf50891c9 100644 --- a/interface/resources/qml/dialogs/preferences/BrowsablePreference.qml +++ b/interface/resources/qml/dialogs/preferences/BrowsablePreference.qml @@ -65,7 +65,10 @@ Preference { verticalCenter: dataTextField.verticalCenter } onClicked: { - var browser = fileBrowserBuilder.createObject(desktop, { selectDirectory: true, folder: fileDialogHelper.pathToUrl(preference.value) }); + var browser = fileBrowserBuilder.createObject(desktop, { + selectDirectory: true, + dir: fileDialogHelper.pathToUrl(preference.value) + }); browser.selectedFile.connect(function(fileUrl){ console.log(fileUrl); dataTextField.text = fileDialogHelper.urlToPath(fileUrl); From 546699da03c889d2ef7df821de6db770e60acc7a Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 13 Jun 2016 15:06:10 +1200 Subject: [PATCH 27/45] When choosing a directory default selection to default directory --- interface/resources/qml/dialogs/FileDialog.qml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interface/resources/qml/dialogs/FileDialog.qml b/interface/resources/qml/dialogs/FileDialog.qml index 93ccbc0b8c..f877aa448e 100644 --- a/interface/resources/qml/dialogs/FileDialog.qml +++ b/interface/resources/qml/dialogs/FileDialog.qml @@ -82,6 +82,12 @@ ModalWindow { // Clear selection when click on external frame. frameClicked.connect(function() { d.clearSelection(); }); + + if (selectDirectory) { + currentSelection.text = d.capitalizeDrive(helper.urlToPath(initialFolder)); + } + + fileTableView.forceActiveFocus(); } Item { From f7578f084f4142e5a6c2ade27975a4a20f926aca Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 13 Jun 2016 15:21:59 +1200 Subject: [PATCH 28/45] Fix buttons on warning message box when can't export a file --- interface/resources/qml/dialogs/FileDialog.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/resources/qml/dialogs/FileDialog.qml b/interface/resources/qml/dialogs/FileDialog.qml index f877aa448e..56f761e42d 100644 --- a/interface/resources/qml/dialogs/FileDialog.qml +++ b/interface/resources/qml/dialogs/FileDialog.qml @@ -709,7 +709,6 @@ ModalWindow { if (!helper.urlIsWritable(selection)) { desktop.messageBox({ icon: OriginalDialogs.StandardIcon.Warning, - buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No, text: "Unable to write to location " + selection }) return; From 52245f25f28645b66caaeee686fe752cf6e07d23 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 13 Jun 2016 11:48:45 -0700 Subject: [PATCH 29/45] rework code that transforms global _server* values into parent-frame values --- libraries/physics/src/EntityMotionState.cpp | 39 ++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index e5957ce7b2..5fffc9901b 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -274,9 +274,39 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { // if we've never checked before, our _lastStep will be 0, and we need to initialize our state if (_lastStep == 0) { btTransform xform = _body->getWorldTransform(); - _serverPosition = _entity->worldPositionToParent(bulletToGLM(xform.getOrigin())); - _serverRotation = _entity->worldRotationToParent(bulletToGLM(xform.getRotation())); - _serverVelocity = _entity->worldVelocityToParent(getBodyLinearVelocityGTSigma()); + + // _serverPosition = _entity->worldPositionToParent(bulletToGLM(xform.getOrigin())); + // _serverRotation = _entity->worldRotationToParent(bulletToGLM(xform.getRotation())); + // _serverVelocity = _entity->worldVelocityToParent(getBodyLinearVelocityGTSigma()); + + + _serverPosition = bulletToGLM(xform.getOrigin()); + _serverRotation = bulletToGLM(xform.getRotation()); + _serverVelocity = getBodyLinearVelocityGTSigma(); + bool success; + Transform parentTransform = _entity->getParentTransform(success); + if (success) { + Transform bodyTransform; + bodyTransform.setTranslation(_serverPosition); + bodyTransform.setRotation(_serverRotation); + Transform result; + Transform::inverseMult(result, parentTransform, bodyTransform); + _serverPosition = result.getTranslation(); + _serverRotation = result.getRotation(); + + // transform velocity into parent-frame + parentTransform.setTranslation(glm::vec3(0.0f)); + Transform velocityTransform; + velocityTransform.setTranslation(_serverVelocity); + Transform myWorldTransform; + Transform::mult(myWorldTransform, parentTransform, velocityTransform); + myWorldTransform.setTranslation(_serverVelocity); + Transform::inverseMult(result, parentTransform, myWorldTransform); + _serverVelocity = result.getTranslation(); + } + + + _serverAcceleration = Vectors::ZERO; _serverAngularVelocity = _entity->worldVelocityToParent(bulletToGLM(_body->getAngularVelocity())); _lastStep = simulationStep; @@ -614,8 +644,9 @@ uint32_t EntityMotionState::getIncomingDirtyFlags() { int bodyFlags = _body->getCollisionFlags(); bool isMoving = _entity->isMovingRelativeToParent(); - // XXX what's right, here? if (((bodyFlags & btCollisionObject::CF_STATIC_OBJECT) && isMoving) // || + // TODO -- there is opportunity for an optimization here, but this currently causes + // excessive re-insertion of the rigid body. // (bodyFlags & btCollisionObject::CF_KINEMATIC_OBJECT && !isMoving) ) { dirtyFlags |= Simulation::DIRTY_MOTION_TYPE; From 5553c9f87fd0bcc6c8062aa8c7ddef80372aeaa6 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 14 Jun 2016 07:46:41 +1200 Subject: [PATCH 30/45] Code review --- interface/src/scripting/WindowScriptingInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 6579366cf8..f0ae221566 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -123,7 +123,7 @@ void WindowScriptingInterface::setPreviousBrowseLocation(const QString& location /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { QString path = directory; - if (path == "") { + if (path.isEmpty()) { path = getPreviousBrowseLocation(); } #ifndef Q_OS_WIN @@ -144,7 +144,7 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { QString path = directory; - if (path == "") { + if (path.isEmpty()) { path = getPreviousBrowseLocation(); } #ifndef Q_OS_WIN From 342fc07d2904192d32283a7eddeb15c425c5507a Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 13 Jun 2016 13:06:56 -0700 Subject: [PATCH 31/45] select active element in edit.js after change --- scripts/system/html/entityProperties.html | 24 +++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 2a82d8fa74..1c4c3740cd 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -546,17 +546,11 @@ disableProperties(); } else { - var activeElement = document.activeElement; - - try { - var selected = (activeElement - && activeElement.selectionStart == 0 - && activeElement.selectionEnd == activeElement.value.length); - } catch (e) { - var selected = false; - } + properties = data.selections[0].properties; + + //WE SHOULD ONLY UPDATE CHANGED VALUES elID.innerHTML = properties.id; elType.innerHTML = properties.type; @@ -572,6 +566,7 @@ enableProperties(); } + console.log('updated properties :: ',properties) elName.value = properties.name; @@ -811,11 +806,10 @@ elYTextureURL.value = properties.yTextureURL; elZTextureURL.value = properties.zTextureURL; } - - if (selected) { - activeElement.focus(); - activeElement.select(); - } + + var activeElement = document.activeElement; + + activeElement.select(); } } }); @@ -1178,7 +1172,7 @@ for (var i = 0; i < els.length; i++) { var clicked = false; var originalText; - els[i].onfocus = function() { + els[i].onfocus = function(e) { originalText = this.value; this.select(); clicked = false; From 567118f4a9053aca53ade3fb079ba14b4a2a2491 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 13 Jun 2016 13:08:12 -0700 Subject: [PATCH 32/45] cleanup --- scripts/system/html/entityProperties.html | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 1c4c3740cd..ca0f9be072 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -550,7 +550,6 @@ properties = data.selections[0].properties; - //WE SHOULD ONLY UPDATE CHANGED VALUES elID.innerHTML = properties.id; elType.innerHTML = properties.type; From 188590a891010e44b0b5c188f3095db3a7af0498 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 13 Jun 2016 13:08:22 -0700 Subject: [PATCH 33/45] cleanup --- scripts/system/html/entityProperties.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index ca0f9be072..c8edbdb369 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -564,8 +564,6 @@ } else { enableProperties(); } - - console.log('updated properties :: ',properties) elName.value = properties.name; From eba518cb65634edb8dd47824ecb01f25eb9b27ed Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 13 Jun 2016 14:26:41 -0700 Subject: [PATCH 34/45] try to make code that converts bullet-calculated values to parent-frame values more effecient --- libraries/physics/src/EntityMotionState.cpp | 53 +++++++-------------- libraries/shared/src/SpatiallyNestable.cpp | 27 ----------- libraries/shared/src/SpatiallyNestable.h | 4 -- 3 files changed, 17 insertions(+), 67 deletions(-) diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 5fffc9901b..8f22c576f0 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -271,44 +271,25 @@ bool EntityMotionState::isCandidateForOwnership() const { bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { // NOTE: we only get here if we think we own the simulation assert(_body); + + bool parentTransformSuccess; + Transform localToWorld = _entity->getParentTransform(parentTransformSuccess); + Transform worldToLocal; + Transform worldVelocityToLocal; + if (parentTransformSuccess) { + localToWorld.evalInverse(worldToLocal); + worldVelocityToLocal = worldToLocal; + worldVelocityToLocal.setTranslation(glm::vec3(0.0f)); + } + // if we've never checked before, our _lastStep will be 0, and we need to initialize our state if (_lastStep == 0) { btTransform xform = _body->getWorldTransform(); - - // _serverPosition = _entity->worldPositionToParent(bulletToGLM(xform.getOrigin())); - // _serverRotation = _entity->worldRotationToParent(bulletToGLM(xform.getRotation())); - // _serverVelocity = _entity->worldVelocityToParent(getBodyLinearVelocityGTSigma()); - - - _serverPosition = bulletToGLM(xform.getOrigin()); - _serverRotation = bulletToGLM(xform.getRotation()); - _serverVelocity = getBodyLinearVelocityGTSigma(); - bool success; - Transform parentTransform = _entity->getParentTransform(success); - if (success) { - Transform bodyTransform; - bodyTransform.setTranslation(_serverPosition); - bodyTransform.setRotation(_serverRotation); - Transform result; - Transform::inverseMult(result, parentTransform, bodyTransform); - _serverPosition = result.getTranslation(); - _serverRotation = result.getRotation(); - - // transform velocity into parent-frame - parentTransform.setTranslation(glm::vec3(0.0f)); - Transform velocityTransform; - velocityTransform.setTranslation(_serverVelocity); - Transform myWorldTransform; - Transform::mult(myWorldTransform, parentTransform, velocityTransform); - myWorldTransform.setTranslation(_serverVelocity); - Transform::inverseMult(result, parentTransform, myWorldTransform); - _serverVelocity = result.getTranslation(); - } - - - + _serverPosition = worldToLocal.transform(bulletToGLM(xform.getOrigin())); + _serverRotation = worldToLocal.getRotation() * bulletToGLM(xform.getRotation()); + _serverVelocity = worldVelocityToLocal.transform(getBodyLinearVelocityGTSigma()); _serverAcceleration = Vectors::ZERO; - _serverAngularVelocity = _entity->worldVelocityToParent(bulletToGLM(_body->getAngularVelocity())); + _serverAngularVelocity = worldVelocityToLocal.transform(bulletToGLM(_body->getAngularVelocity())); _lastStep = simulationStep; _serverActionData = _entity->getActionData(); _numInactiveUpdates = 1; @@ -381,7 +362,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { // compute position error btTransform worldTrans = _body->getWorldTransform(); - glm::vec3 position = _entity->worldPositionToParent(bulletToGLM(worldTrans.getOrigin())); + glm::vec3 position = worldToLocal.transform(bulletToGLM(worldTrans.getOrigin())); float dx2 = glm::distance2(position, _serverPosition); const float MAX_POSITION_ERROR_SQUARED = 0.000004f; // corresponds to 2mm @@ -416,7 +397,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) { } } const float MIN_ROTATION_DOT = 0.99999f; // This corresponds to about 0.5 degrees of rotation - glm::quat actualRotation = _entity->worldRotationToParent(bulletToGLM(worldTrans.getRotation())); + glm::quat actualRotation = worldToLocal.getRotation() * bulletToGLM(worldTrans.getRotation()); #ifdef WANT_DEBUG if ((fabsf(glm::dot(actualRotation, _serverRotation)) < MIN_ROTATION_DOT)) { diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 6edf80ab98..29a033f340 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -174,15 +174,6 @@ glm::vec3 SpatiallyNestable::worldToLocal(const glm::vec3& position, return result.getTranslation(); } -glm::vec3 SpatiallyNestable::worldPositionToParent(const glm::vec3& position) { - bool success; - glm::vec3 result = SpatiallyNestable::worldToLocal(position, getParentID(), getParentJointIndex(), success); - if (!success) { - qDebug() << "Warning -- worldToLocal failed" << getID(); - } - return result; -} - glm::vec3 SpatiallyNestable::worldVelocityToLocal(const glm::vec3& velocity, // can be linear or angular const QUuid& parentID, int parentJointIndex, bool& success) { @@ -225,15 +216,6 @@ glm::vec3 SpatiallyNestable::worldVelocityToLocal(const glm::vec3& velocity, // return result.getTranslation(); } -glm::vec3 SpatiallyNestable::worldVelocityToParent(const glm::vec3& velocity) { - bool success; - glm::vec3 result = SpatiallyNestable::worldVelocityToLocal(velocity, getParentID(), getParentJointIndex(), success); - if (!success) { - qDebug() << "Warning -- worldVelocityToLocal failed" << getID(); - } - return result; -} - glm::quat SpatiallyNestable::worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success) { @@ -274,15 +256,6 @@ glm::quat SpatiallyNestable::worldToLocal(const glm::quat& orientation, return result.getRotation(); } -glm::quat SpatiallyNestable::worldRotationToParent(const glm::quat& orientation) { - bool success; - glm::quat result = SpatiallyNestable::worldToLocal(orientation, getParentID(), getParentJointIndex(), success); - if (!success) { - qDebug() << "Warning -- worldToLocal failed" << getID(); - } - return result; -} - glm::vec3 SpatiallyNestable::localToWorld(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success) { diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index ffb00ac040..23beffda53 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -53,10 +53,6 @@ public: static glm::vec3 localToWorld(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success); static glm::quat localToWorld(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success); - glm::vec3 worldPositionToParent(const glm::vec3& position); - glm::vec3 worldVelocityToParent(const glm::vec3& velocity); - glm::quat worldRotationToParent(const glm::quat& orientation); - // world frame virtual const Transform getTransform(bool& success, int depth = 0) const; virtual void setTransform(const Transform& transform, bool& success); From f8f62a4ff1120f4a83cea57b82b614ed80fa0d4f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 13 Jun 2016 15:10:52 -0700 Subject: [PATCH 35/45] remove unused function --- libraries/shared/src/SpatiallyNestable.cpp | 42 ---------------------- libraries/shared/src/SpatiallyNestable.h | 2 -- 2 files changed, 44 deletions(-) diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 29a033f340..2a3cb4af47 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -174,48 +174,6 @@ glm::vec3 SpatiallyNestable::worldToLocal(const glm::vec3& position, return result.getTranslation(); } -glm::vec3 SpatiallyNestable::worldVelocityToLocal(const glm::vec3& velocity, // can be linear or angular - const QUuid& parentID, int parentJointIndex, - bool& success) { - Transform result; - QSharedPointer parentFinder = DependencyManager::get(); - if (!parentFinder) { - success = false; - return glm::vec3(); - } - - Transform parentTransform; - auto parentWP = parentFinder->find(parentID, success); - if (!success) { - return glm::vec3(); - } - - auto parent = parentWP.lock(); - if (!parentID.isNull() && !parent) { - success = false; - return glm::vec3(); - } - - if (parent) { - parentTransform = parent->getTransform(parentJointIndex, success); - if (!success) { - return glm::vec3(); - } - parentTransform.setScale(1.0f); // TODO: scale - } - success = true; - - parentTransform.setTranslation(glm::vec3(0.0f)); - - Transform velocityTransform; - velocityTransform.setTranslation(velocity); - Transform myWorldTransform; - Transform::mult(myWorldTransform, parentTransform, velocityTransform); - myWorldTransform.setTranslation(velocity); - Transform::inverseMult(result, parentTransform, myWorldTransform); - return result.getTranslation(); -} - glm::quat SpatiallyNestable::worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success) { diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index 23beffda53..c2563a1188 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -46,8 +46,6 @@ public: virtual void setParentJointIndex(quint16 parentJointIndex); static glm::vec3 worldToLocal(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success); - static glm::vec3 worldVelocityToLocal(const glm::vec3& position, const QUuid& parentID, - int parentJointIndex, bool& success); static glm::quat worldToLocal(const glm::quat& orientation, const QUuid& parentID, int parentJointIndex, bool& success); static glm::vec3 localToWorld(const glm::vec3& position, const QUuid& parentID, int parentJointIndex, bool& success); From 1306417c8e8a9f68f71ca002f2b2a23e8495dadb Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 13 Jun 2016 17:48:58 -0700 Subject: [PATCH 36/45] more verbose messaging about incorrect entity types --- libraries/entities/src/EntityTypes.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 7b1133c2aa..4ba4ad5676 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -17,6 +17,7 @@ #include "EntityItem.h" #include "EntityItemProperties.h" #include "EntityTypes.h" +#include "EntitiesLogging.h" #include "LightEntityItem.h" #include "ModelEntityItem.h" @@ -63,6 +64,9 @@ EntityTypes::EntityType EntityTypes::getEntityTypeFromName(const QString& name) if (matchedTypeName != _nameToTypeMap.end()) { return matchedTypeName.value(); } + if (name.size() > 0 && name[0].isLower()) { + qCDebug(entities) << "Entity types must start with an uppercase letter. Please change the type" << name; + } return Unknown; } From df9fd6c7fc7c172ebe9c751364071d0b8c1c7b3c Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Mon, 13 Jun 2016 18:35:39 -0700 Subject: [PATCH 37/45] reset vive grip buttons to 0 if not pressed --- plugins/openvr/src/ViveControllerManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 0d2cdc940a..a7a0a2f56f 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -363,6 +363,10 @@ void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint } else if (button == vr::k_EButton_SteamVR_Touchpad) { _buttonPressedMap.insert(isLeftHand ? LS : RS); } + } else { + if (button == vr::k_EButton_Grip) { + _axisStateMap[isLeftHand ? LEFT_GRIP : RIGHT_GRIP] = 0.0f; + } } if (touched) { From 34c8d257d2ac2638b3d8ea6232a02bad8222fdea Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Mon, 13 Jun 2016 15:26:48 -0700 Subject: [PATCH 38/45] Fixing issues with unclosed groups in settings persistence --- libraries/networking/src/AccountManager.cpp | 1 + libraries/script-engine/src/ScriptEngines.cpp | 1 + libraries/shared/src/SettingHandle.cpp | 9 +++++++++ libraries/shared/src/SettingHandle.h | 2 ++ libraries/shared/src/SettingInterface.cpp | 2 ++ 5 files changed, 15 insertions(+) diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index bac031885f..26b3801ec1 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -173,6 +173,7 @@ void AccountManager::setAuthURL(const QUrl& authURL) { << "from previous settings file"; } } + settings.endGroup(); if (_accountInfo.getAccessToken().token.isEmpty()) { qCWarning(networking) << "Unable to load account file. No existing account settings will be loaded."; diff --git a/libraries/script-engine/src/ScriptEngines.cpp b/libraries/script-engine/src/ScriptEngines.cpp index 29c223f4b3..beddc21787 100644 --- a/libraries/script-engine/src/ScriptEngines.cpp +++ b/libraries/script-engine/src/ScriptEngines.cpp @@ -334,6 +334,7 @@ void ScriptEngines::clearScripts() { Settings settings; settings.beginWriteArray(SETTINGS_KEY); settings.remove(""); + settings.endArray(); } void ScriptEngines::saveScripts() { diff --git a/libraries/shared/src/SettingHandle.cpp b/libraries/shared/src/SettingHandle.cpp index b2f23f5a04..13f9ea48ce 100644 --- a/libraries/shared/src/SettingHandle.cpp +++ b/libraries/shared/src/SettingHandle.cpp @@ -18,6 +18,7 @@ const QString Settings::firstRun { "firstRun" }; + Settings::Settings() : _manager(DependencyManager::get()), _locker(&(_manager->getLock())) @@ -25,6 +26,9 @@ Settings::Settings() : } Settings::~Settings() { + if (_prefixes.size() != 0) { + qFatal("Unstable Settings Prefixes: You must call endGroup for every beginGroup and endArray for every begin*Array call"); + } } void Settings::remove(const QString& key) { @@ -50,14 +54,17 @@ bool Settings::contains(const QString& key) const { } int Settings::beginReadArray(const QString & prefix) { + _prefixes.push(prefix); return _manager->beginReadArray(prefix); } void Settings::beginWriteArray(const QString& prefix, int size) { + _prefixes.push(prefix); _manager->beginWriteArray(prefix, size); } void Settings::endArray() { + _prefixes.pop(); _manager->endArray(); } @@ -66,10 +73,12 @@ void Settings::setArrayIndex(int i) { } void Settings::beginGroup(const QString& prefix) { + _prefixes.push(prefix); _manager->beginGroup(prefix); } void Settings::endGroup() { + _prefixes.pop(); _manager->endGroup(); } diff --git a/libraries/shared/src/SettingHandle.h b/libraries/shared/src/SettingHandle.h index e83c563036..f19fc5875b 100644 --- a/libraries/shared/src/SettingHandle.h +++ b/libraries/shared/src/SettingHandle.h @@ -58,8 +58,10 @@ public: void setQuatValue(const QString& name, const glm::quat& quatValue); void getQuatValueIfValid(const QString& name, glm::quat& quatValue); +private: QSharedPointer _manager; QWriteLocker _locker; + QStack _prefixes; }; namespace Setting { diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index 630d52bf7d..1ebaa5cf82 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -98,6 +98,8 @@ namespace Setting { // Register Handle manager->registerHandle(this); _isInitialized = true; + } else { + qWarning() << "Settings interface used after manager destroyed"; } // Load value from disk From d52a1fe6f925e448b67a4b997690514389f5ca28 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Mon, 13 Jun 2016 20:26:27 -0700 Subject: [PATCH 39/45] Fix persistence for global scope settings handles, clean up invalid variants in settings --- libraries/shared/src/SettingHandle.h | 39 +++++++++++++++++++---- libraries/shared/src/SettingInterface.cpp | 4 +-- libraries/shared/src/SettingInterface.h | 11 ++++--- libraries/shared/src/SettingManager.cpp | 10 +++--- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/libraries/shared/src/SettingHandle.h b/libraries/shared/src/SettingHandle.h index f19fc5875b..74587dcdcb 100644 --- a/libraries/shared/src/SettingHandle.h +++ b/libraries/shared/src/SettingHandle.h @@ -77,15 +77,40 @@ namespace Setting { virtual ~Handle() { deinit(); } // Returns setting value, returns its default value if not found - T get() { return get(_defaultValue); } + T get() const { + return get(_defaultValue); + } + // Returns setting value, returns other if not found - T get(const T& other) { maybeInit(); return (_isSet) ? _value : other; } - T getDefault() const { return _defaultValue; } + T get(const T& other) const { + maybeInit(); + return (_isSet) ? _value : other; + } + + const T& getDefault() const { + return _defaultValue; + } - void set(const T& value) { maybeInit(); _value = value; _isSet = true; } - void reset() { set(_defaultValue); } - - void remove() { maybeInit(); _isSet = false; } + void reset() { + set(_defaultValue); + } + + void set(const T& value) { + maybeInit(); + if (_value != value) { + _value = value; + _isSet = true; + save(); + } + } + + void remove() { + maybeInit(); + if (_isSet) { + _isSet = false; + save(); + } + } protected: virtual void setVariant(const QVariant& variant); diff --git a/libraries/shared/src/SettingInterface.cpp b/libraries/shared/src/SettingInterface.cpp index 1ebaa5cf82..95c6bc1efc 100644 --- a/libraries/shared/src/SettingInterface.cpp +++ b/libraries/shared/src/SettingInterface.cpp @@ -119,9 +119,9 @@ namespace Setting { } - void Interface::maybeInit() { + void Interface::maybeInit() const { if (!_isInitialized) { - init(); + const_cast(this)->init(); } } diff --git a/libraries/shared/src/SettingInterface.h b/libraries/shared/src/SettingInterface.h index 2b32e8a3b4..5e23d42223 100644 --- a/libraries/shared/src/SettingInterface.h +++ b/libraries/shared/src/SettingInterface.h @@ -39,19 +39,20 @@ namespace Setting { virtual ~Interface() = default; void init(); - void maybeInit(); + void maybeInit() const; void deinit(); void save(); void load(); - - bool _isInitialized = false; + bool _isSet = false; const QString _key; + + private: + mutable bool _isInitialized = false; friend class Manager; - - QWeakPointer _manager; + mutable QWeakPointer _manager; }; } diff --git a/libraries/shared/src/SettingManager.cpp b/libraries/shared/src/SettingManager.cpp index bacec2ee0c..ed8565d6c3 100644 --- a/libraries/shared/src/SettingManager.cpp +++ b/libraries/shared/src/SettingManager.cpp @@ -33,8 +33,8 @@ namespace Setting { void Manager::customDeleter() { } - void Manager::registerHandle(Setting::Interface* handle) { - QString key = handle->getKey(); + void Manager::registerHandle(Interface* handle) { + const QString& key = handle->getKey(); withWriteLock([&] { if (_handles.contains(key)) { qWarning() << "Setting::Manager::registerHandle(): Key registered more than once, overriding: " << key; @@ -58,7 +58,9 @@ namespace Setting { } else { loadedValue = value(key); } - handle->setVariant(loadedValue); + if (loadedValue.isValid()) { + handle->setVariant(loadedValue); + } }); } @@ -101,7 +103,7 @@ namespace Setting { if (newValue == savedValue) { continue; } - if (newValue == UNSET_VALUE) { + if (newValue == UNSET_VALUE || !newValue.isValid()) { remove(key); } else { setValue(key, newValue); From 2163f9b5f34241d631324fce349c2e058cf54cfd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 14 Jun 2016 10:43:45 -0700 Subject: [PATCH 40/45] signal once for domain protocol mismatch, case 918 --- libraries/networking/src/DomainHandler.cpp | 23 +++++++++++++++++++--- libraries/networking/src/DomainHandler.h | 3 ++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 6880b7a329..057dd3747d 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -118,6 +118,8 @@ void DomainHandler::hardReset() { _hostname = QString(); _sockAddr.clear(); + _hasSignalledProtocolMismatch = false; + _hasCheckedForAccessToken = false; // clear any pending path we may have wanted to ask the previous DS about @@ -405,9 +407,24 @@ void DomainHandler::processDomainServerConnectionDeniedPacket(QSharedPointer(); diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index 1328174e87..3ab583d597 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -144,7 +144,8 @@ private: QString _pendingPath; QTimer _settingsTimer; - QStringList _domainConnectionRefusals; + QList _domainConnectionRefusals; + bool _hasSignalledProtocolMismatch { false }; bool _hasCheckedForAccessToken { false }; int _connectionDenialsSinceKeypairRegen { 0 }; From b1c472e82b8cccc4ff3a1d500b229b74858ba016 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Tue, 14 Jun 2016 12:13:27 -0700 Subject: [PATCH 41/45] Fixing settings, even in release builds --- libraries/shared/src/SettingHandle.h | 2 +- libraries/shared/src/SettingManager.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libraries/shared/src/SettingHandle.h b/libraries/shared/src/SettingHandle.h index 74587dcdcb..8e07d28dad 100644 --- a/libraries/shared/src/SettingHandle.h +++ b/libraries/shared/src/SettingHandle.h @@ -97,7 +97,7 @@ namespace Setting { void set(const T& value) { maybeInit(); - if (_value != value) { + if ((!_isSet && (value != _defaultValue)) || _value != value) { _value = value; _isSet = true; save(); diff --git a/libraries/shared/src/SettingManager.cpp b/libraries/shared/src/SettingManager.cpp index ed8565d6c3..abb8525b03 100644 --- a/libraries/shared/src/SettingManager.cpp +++ b/libraries/shared/src/SettingManager.cpp @@ -96,6 +96,7 @@ namespace Setting { } void Manager::saveAll() { + bool forceSync = false; withWriteLock([&] { for (auto key : _pendingChanges.keys()) { auto newValue = _pendingChanges[key]; @@ -104,14 +105,20 @@ namespace Setting { continue; } if (newValue == UNSET_VALUE || !newValue.isValid()) { + forceSync = true; remove(key); } else { + forceSync = true; setValue(key, newValue); } } _pendingChanges.clear(); }); + if (forceSync) { + sync(); + } + // Restart timer if (_saveTimer) { _saveTimer->start(); From f6994f2783cf17d7e30312784ddcf78865bb47e4 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Tue, 14 Jun 2016 17:41:53 -0700 Subject: [PATCH 42/45] Revert "Revert "refresh API info during re-connect - case 570"" This reverts commit 1624146fc2ecf6abf508b03769f81ff2220158ae. --- libraries/networking/src/AddressManager.cpp | 44 ++++++++++++++++++--- libraries/networking/src/AddressManager.h | 9 ++++- libraries/networking/src/DomainHandler.cpp | 18 +++------ libraries/networking/src/DomainHandler.h | 10 ++--- libraries/networking/src/NodeList.cpp | 14 +++++-- 5 files changed, 67 insertions(+), 28 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 1b7ed11cce..9a3d147ead 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -144,12 +144,21 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { // 4. domain network address (IP or dns resolvable hostname) // use our regex'ed helpers to figure out what we're supposed to do with this - if (!handleUsername(lookupUrl.authority())) { + if (handleUsername(lookupUrl.authority())) { + // handled a username for lookup + + // in case we're failing to connect to where we thought this user was + // store their username as previous lookup so we can refresh their location via API + _previousLookup = lookupUrl; + } else { // we're assuming this is either a network address or global place name // check if it is a network address first bool hostChanged; if (handleNetworkAddress(lookupUrl.host() - + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())), trigger, hostChanged)) { + + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())), trigger, hostChanged)) { + + // a network address lookup clears the previous lookup since we don't expect to re-attempt it + _previousLookup.clear(); // If the host changed then we have already saved to history if (hostChanged) { @@ -165,10 +174,16 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { // we may have a path that defines a relative viewpoint - if so we should jump to that now handlePath(path, trigger); } else if (handleDomainID(lookupUrl.host())){ + // store this domain ID as the previous lookup in case we're failing to connect and want to refresh API info + _previousLookup = lookupUrl; + // no place name - this is probably a domain ID // try to look up the domain ID on the metaverse API attemptDomainIDLookup(lookupUrl.host(), lookupUrl.path(), trigger); } else { + // store this place name as the previous lookup in case we fail to connect and want to refresh API info + _previousLookup = lookupUrl; + // wasn't an address - lookup the place name // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path(), trigger); @@ -180,9 +195,13 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) { } else if (lookupUrl.toString().startsWith('/')) { qCDebug(networking) << "Going to relative path" << lookupUrl.path(); + // a path lookup clears the previous lookup since we don't expect to re-attempt it + _previousLookup.clear(); + // if this is a relative path then handle it as a relative viewpoint handlePath(lookupUrl.path(), trigger, true); emit lookupResultsFinished(); + return true; } @@ -276,7 +295,7 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const qCDebug(networking) << "Possible domain change required to connect to" << domainHostname << "on" << domainPort; - emit possibleDomainChangeRequired(domainHostname, domainPort); + emit possibleDomainChangeRequired(domainHostname, domainPort, domainID); } else { QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString(); @@ -315,7 +334,10 @@ void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const QString overridePath = reply.property(OVERRIDE_PATH_KEY).toString(); if (!overridePath.isEmpty()) { - handlePath(overridePath, trigger); + // make sure we don't re-handle an overriden path if this was a refresh of info from API + if (trigger != LookupTrigger::AttemptedRefresh) { + handlePath(overridePath, trigger); + } } else { // take the path that came back const QString PLACE_PATH_KEY = "path"; @@ -598,7 +620,7 @@ bool AddressManager::setDomainInfo(const QString& hostname, quint16 port, Lookup DependencyManager::get()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::HandleAddress); - emit possibleDomainChangeRequired(hostname, port); + emit possibleDomainChangeRequired(hostname, port, QUuid()); return hostChanged; } @@ -618,6 +640,13 @@ void AddressManager::goToUser(const QString& username) { QByteArray(), nullptr, requestParams); } +void AddressManager::refreshPreviousLookup() { + // if we have a non-empty previous lookup, fire it again now (but don't re-store it in the history) + if (!_previousLookup.isEmpty()) { + handleUrl(_previousLookup, LookupTrigger::AttemptedRefresh); + } +} + void AddressManager::copyAddress() { QApplication::clipboard()->setText(currentAddress().toString()); } @@ -629,7 +658,10 @@ void AddressManager::copyPath() { void AddressManager::addCurrentAddressToHistory(LookupTrigger trigger) { // if we're cold starting and this is called for the first address (from settings) we don't do anything - if (trigger != LookupTrigger::StartupFromSettings && trigger != LookupTrigger::DomainPathResponse) { + if (trigger != LookupTrigger::StartupFromSettings + && trigger != LookupTrigger::DomainPathResponse + && trigger != LookupTrigger::AttemptedRefresh) { + if (trigger == LookupTrigger::Back) { // we're about to push to the forward stack // if it's currently empty emit our signal to say that going forward is now possible diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index 643924ff5c..a3aaee3ba2 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -48,7 +48,8 @@ public: Forward, StartupFromSettings, DomainPathResponse, - Internal + Internal, + AttemptedRefresh }; bool isConnected(); @@ -89,6 +90,8 @@ public slots: void goToUser(const QString& username); + void refreshPreviousLookup(); + void storeCurrentAddress(); void copyAddress(); @@ -99,7 +102,7 @@ signals: void lookupResultIsOffline(); void lookupResultIsNotFound(); - void possibleDomainChangeRequired(const QString& newHostname, quint16 newPort); + void possibleDomainChangeRequired(const QString& newHostname, quint16 newPort, const QUuid& domainID); void possibleDomainChangeRequiredViaICEForID(const QString& iceServerHostname, const QUuid& domainID); void locationChangeRequired(const glm::vec3& newPosition, @@ -152,6 +155,8 @@ private: quint64 _lastBackPush = 0; QString _newHostLookupPath; + + QUrl _previousLookup; }; #endif // hifi_AddressManager_h diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 4f85296f03..1efcfc7f27 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -28,16 +28,8 @@ DomainHandler::DomainHandler(QObject* parent) : QObject(parent), - _uuid(), _sockAddr(HifiSockAddr(QHostAddress::Null, DEFAULT_DOMAIN_SERVER_PORT)), - _assignmentUUID(), - _connectionToken(), - _iceDomainID(), - _iceClientID(), - _iceServerSockAddr(), _icePeer(this), - _isConnected(false), - _settingsObject(), _settingsTimer(this) { _sockAddr.setObjectName("DomainServer"); @@ -105,7 +97,7 @@ void DomainHandler::hardReset() { softReset(); qCDebug(networking) << "Hard reset in NodeList DomainHandler."; - _iceDomainID = QUuid(); + _pendingDomainID = QUuid(); _iceServerSockAddr = HifiSockAddr(); _hostname = QString(); _sockAddr.clear(); @@ -139,7 +131,7 @@ void DomainHandler::setUUID(const QUuid& uuid) { } } -void DomainHandler::setHostnameAndPort(const QString& hostname, quint16 port) { +void DomainHandler::setSocketAndID(const QString& hostname, quint16 port, const QUuid& domainID) { if (hostname != _hostname || _sockAddr.getPort() != port) { // re-set the domain info so that auth information is reloaded @@ -171,6 +163,8 @@ void DomainHandler::setHostnameAndPort(const QString& hostname, quint16 port) { // grab the port by reading the string after the colon _sockAddr.setPort(port); } + + _pendingDomainID = domainID; } void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id) { @@ -181,7 +175,7 @@ void DomainHandler::setIceServerHostnameAndID(const QString& iceServerHostname, // refresh our ICE client UUID to something new _iceClientID = QUuid::createUuid(); - _iceDomainID = id; + _pendingDomainID = id; HifiSockAddr* replaceableSockAddr = &_iceServerSockAddr; replaceableSockAddr->~HifiSockAddr(); @@ -343,7 +337,7 @@ void DomainHandler::processICEResponsePacket(QSharedPointer mes DependencyManager::get()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::ReceiveDSPeerInformation); - if (_icePeer.getUUID() != _iceDomainID) { + if (_icePeer.getUUID() != _pendingDomainID) { qCDebug(networking) << "Received a network peer with ID that does not match current domain. Will not attempt connection."; _icePeer.reset(); } else { diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index bcee7668d1..226186f1d0 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -58,8 +58,8 @@ public: const QUuid& getAssignmentUUID() const { return _assignmentUUID; } void setAssignmentUUID(const QUuid& assignmentUUID) { _assignmentUUID = assignmentUUID; } - - const QUuid& getICEDomainID() const { return _iceDomainID; } + + const QUuid& getPendingDomainID() const { return _pendingDomainID; } const QUuid& getICEClientID() const { return _iceClientID; } @@ -94,7 +94,7 @@ public: }; public slots: - void setHostnameAndPort(const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT); + void setSocketAndID(const QString& hostname, quint16 port = DEFAULT_DOMAIN_SERVER_PORT, const QUuid& id = QUuid()); void setIceServerHostnameAndID(const QString& iceServerHostname, const QUuid& id); void processSettingsPacketList(QSharedPointer packetList); @@ -136,11 +136,11 @@ private: HifiSockAddr _sockAddr; QUuid _assignmentUUID; QUuid _connectionToken; - QUuid _iceDomainID; + QUuid _pendingDomainID; // ID of domain being connected to, via ICE or direct connection QUuid _iceClientID; HifiSockAddr _iceServerSockAddr; NetworkPeer _icePeer; - bool _isConnected; + bool _isConnected { false }; QJsonObject _settingsObject; QString _pendingPath; QTimer _settingsTimer; diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 16a4083b08..082200fccc 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -50,7 +50,7 @@ NodeList::NodeList(char newOwnerType, unsigned short socketListenPort, unsigned // handle domain change signals from AddressManager connect(addressManager.data(), &AddressManager::possibleDomainChangeRequired, - &_domainHandler, &DomainHandler::setHostnameAndPort); + &_domainHandler, &DomainHandler::setSocketAndID); connect(addressManager.data(), &AddressManager::possibleDomainChangeRequiredViaICEForID, &_domainHandler, &DomainHandler::setIceServerHostnameAndID); @@ -355,6 +355,14 @@ void NodeList::sendDomainServerCheckIn() { // increment the count of un-replied check-ins _numNoReplyDomainCheckIns++; } + + if (!_publicSockAddr.isNull() && !_domainHandler.isConnected() && !_domainHandler.getPendingDomainID().isNull()) { + // if we aren't connected to the domain-server, and we have an ID + // (that we presume belongs to a domain in the HF Metaverse) + // we request connection information for the domain every so often to make sure what we have is up to date + + DependencyManager::get()->refreshPreviousLookup(); + } } void NodeList::handleDSPathQuery(const QString& newPath) { @@ -462,7 +470,7 @@ void NodeList::handleICEConnectionToDomainServer() { LimitedNodeList::sendPeerQueryToIceServer(_domainHandler.getICEServerSockAddr(), _domainHandler.getICEClientID(), - _domainHandler.getICEDomainID()); + _domainHandler.getPendingDomainID()); } } @@ -475,7 +483,7 @@ void NodeList::pingPunchForDomainServer() { if (_domainHandler.getICEPeer().getConnectionAttempts() == 0) { qCDebug(networking) << "Sending ping packets to establish connectivity with domain-server with ID" - << uuidStringWithoutCurlyBraces(_domainHandler.getICEDomainID()); + << uuidStringWithoutCurlyBraces(_domainHandler.getPendingDomainID()); } else { if (_domainHandler.getICEPeer().getConnectionAttempts() % NUM_DOMAIN_SERVER_PINGS_BEFORE_RESET == 0) { // if we have then nullify the domain handler's network peer and send a fresh ICE heartbeat From 747b33f7561b594002586aec0133b70de1ebcc42 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Tue, 14 Jun 2016 17:42:01 -0700 Subject: [PATCH 43/45] Revert "additional revert related change" This reverts commit 8586e91a3b78e37f54384721990b979caff96c3e. --- libraries/networking/src/AddressManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 9a3d147ead..80989acd2c 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -384,7 +384,7 @@ void AddressManager::handleAPIError(QNetworkReply& errorReply) { if (errorReply.error() == QNetworkReply::ContentNotFoundError) { // if this is a lookup that has no result, don't keep re-trying it - //_previousLookup.clear(); + _previousLookup.clear(); emit lookupResultIsNotFound(); } From d778ec96d7f7c67ceb3565df8b74c5d0785d5b6d Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Tue, 14 Jun 2016 17:42:13 -0700 Subject: [PATCH 44/45] Revert "fix shapes to property polymorph and persist" This reverts commit 3bee4b1f9f07e933c4a5e5a8d46e4503b96315ba. --- .../entities/src/EntityItemProperties.cpp | 19 ++------ .../networking/src/udt/PacketHeaders.cpp | 2 +- libraries/networking/src/udt/PacketHeaders.h | 1 - scripts/system/html/entityProperties.html | 48 +++++++++++++------ 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index ba39727ff9..f273507d0d 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -314,8 +314,6 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_CLIENT_ONLY, clientOnly); CHECK_PROPERTY_CHANGE(PROP_OWNING_AVATAR_ID, owningAvatarID); - CHECK_PROPERTY_CHANGE(PROP_SHAPE, shape); - changedProperties += _animation.getChangedProperties(); changedProperties += _keyLight.getChangedProperties(); changedProperties += _skybox.getChangedProperties(); @@ -437,9 +435,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool if (_type == EntityTypes::Sphere) { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(PROP_SHAPE_TYPE, shapeType, QString("Sphere")); } - if (_type == EntityTypes::Box || _type == EntityTypes::Sphere || _type == EntityTypes::Shape) { - COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_SHAPE, shape); - } // FIXME - it seems like ParticleEffect should also support this if (_type == EntityTypes::Model || _type == EntityTypes::Zone) { @@ -1149,11 +1144,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_STROKE_WIDTHS, properties.getStrokeWidths()); APPEND_ENTITY_PROPERTY(PROP_TEXTURES, properties.getTextures()); } - // NOTE: Spheres and Boxes are just special cases of Shape, and they need to include their PROP_SHAPE - // when encoding/decoding edits because otherwise they can't polymorph to other shape types - if (properties.getType() == EntityTypes::Shape || - properties.getType() == EntityTypes::Box || - properties.getType() == EntityTypes::Sphere) { + if (properties.getType() == EntityTypes::Shape) { APPEND_ENTITY_PROPERTY(PROP_SHAPE, properties.getShape()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); @@ -1220,6 +1211,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem } else { packetData->discardSubTree(); } + return success; } @@ -1442,12 +1434,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STROKE_WIDTHS, QVector, setStrokeWidths); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_TEXTURES, QString, setTextures); } - - // NOTE: Spheres and Boxes are just special cases of Shape, and they need to include their PROP_SHAPE - // when encoding/decoding edits because otherwise they can't polymorph to other shape types - if (properties.getType() == EntityTypes::Shape || - properties.getType() == EntityTypes::Box || - properties.getType() == EntityTypes::Sphere) { + if (properties.getType() == EntityTypes::Shape) { READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SHAPE, QString, setShape); } diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index db743f81e4..92e5b52f75 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -49,7 +49,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityAdd: case PacketType::EntityEdit: case PacketType::EntityData: - return VERSION_ENTITIES_PROPERLY_ENCODE_SHAPE_EDITS; + return VERSION_ENTITIES_MORE_SHAPES; case PacketType::AvatarIdentity: case PacketType::AvatarData: case PacketType::BulkAvatarData: diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 320635379d..97398c6744 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -179,7 +179,6 @@ const PacketVersion VERSION_ATMOSPHERE_REMOVED = 56; const PacketVersion VERSION_LIGHT_HAS_FALLOFF_RADIUS = 57; const PacketVersion VERSION_ENTITIES_NO_FLY_ZONES = 58; const PacketVersion VERSION_ENTITIES_MORE_SHAPES = 59; -const PacketVersion VERSION_ENTITIES_PROPERLY_ENCODE_SHAPE_EDITS = 60; enum class AvatarMixerPacketVersion : PacketVersion { TranslationSupport = 17, diff --git a/scripts/system/html/entityProperties.html b/scripts/system/html/entityProperties.html index 2a82d8fa74..5c87f753d9 100644 --- a/scripts/system/html/entityProperties.html +++ b/scripts/system/html/entityProperties.html @@ -557,6 +557,7 @@ } properties = data.selections[0].properties; + elID.innerHTML = properties.id; elType.innerHTML = properties.type; @@ -674,9 +675,6 @@ for (var i = 0; i < elShapeSections.length; i++) { elShapeSections[i].style.display = 'table'; } - elShape.value = properties.shape; - setDropdownText(elShape); - } else { for (var i = 0; i < elShapeSections.length; i++) { console.log("Hiding shape section " + elShapeSections[i]) @@ -1351,17 +1349,6 @@
-
@@ -1375,6 +1362,39 @@
+
+ M +
+ +
+ + +
+
+ + +
+ + From 59912012c628906a1fee781545bb0698442290b7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 15 Jun 2016 09:48:53 -0700 Subject: [PATCH 45/45] clear domain connection refusals on hard reset, not soft --- libraries/networking/src/DomainHandler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 057dd3747d..170669dede 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -97,7 +97,6 @@ void DomainHandler::softReset() { clearSettings(); - _domainConnectionRefusals.clear(); _connectionDenialsSinceKeypairRegen = 0; // cancel the failure timeout for any pending requests for settings @@ -119,6 +118,7 @@ void DomainHandler::hardReset() { _sockAddr.clear(); _hasSignalledProtocolMismatch = false; + _domainConnectionRefusals.clear(); _hasCheckedForAccessToken = false; @@ -408,6 +408,7 @@ void DomainHandler::processDomainServerConnectionDeniedPacket(QSharedPointer