diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index 88897a0fed..bd368ef7c2 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -656,6 +656,8 @@ void Agent::queryAvatars() { ViewFrustum view; view.setPosition(scriptedAvatar->getWorldPosition()); view.setOrientation(scriptedAvatar->getHeadOrientation()); + view.setProjection(DEFAULT_FIELD_OF_VIEW_DEGREES, DEFAULT_ASPECT_RATIO, + DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP); view.calculate(); ConicalViewFrustum conicalView { view }; @@ -876,18 +878,30 @@ void Agent::aboutToFinish() { DependencyManager::destroy(); // destroy all other created dependencies - DependencyManager::destroy(); - DependencyManager::destroy(); DependencyManager::destroy(); - DependencyManager::destroy(); DependencyManager::destroy(); - DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + + DependencyManager::destroy(); + // drop our shared pointer to the script engine, then ask ScriptEngines to shutdown scripting // this ensures that the ScriptEngine goes down before ScriptEngines _scriptEngine.clear(); diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 76ff5ab2ed..c1943de2cc 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -129,17 +129,12 @@ void AssignmentClient::stopAssignmentClient() { QThread* currentAssignmentThread = _currentAssignment->thread(); // ask the current assignment to stop - BLOCKING_INVOKE_METHOD(_currentAssignment, "stop"); + QMetaObject::invokeMethod(_currentAssignment, "stop"); - // ask the current assignment to delete itself on its thread - _currentAssignment->deleteLater(); - - // when this thread is destroyed we don't need to run our assignment complete method - disconnect(currentAssignmentThread, &QThread::destroyed, this, &AssignmentClient::assignmentCompleted); - - // wait on the thread from that assignment - it will be gone once the current assignment deletes - currentAssignmentThread->quit(); - currentAssignmentThread->wait(); + auto PROCESS_EVENTS_INTERVAL_MS = 100; + while (!currentAssignmentThread->wait(PROCESS_EVENTS_INTERVAL_MS)) { + QCoreApplication::processEvents(); + } } } diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index d6f893c42e..77f416f31e 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -435,7 +435,11 @@ void AudioMixer::start() { QCoreApplication::processEvents(); } - int numToRetain = nodeList->size() * (1 - _throttlingRatio); + int numToRetain = -1; + assert(_throttlingRatio >= 0.0f && _throttlingRatio <= 1.0f); + if (_throttlingRatio > EPSILON) { + numToRetain = nodeList->size() * (1.0f - _throttlingRatio); + } nodeList->nestedEach([&](NodeList::const_iterator cbegin, NodeList::const_iterator cend) { // mix across slave threads auto mixTimer = _mixTiming.timer(); @@ -488,11 +492,8 @@ void AudioMixer::throttle(chrono::microseconds duration, int frame) { // target different mix and backoff ratios (they also have different backoff rates) // this is to prevent oscillation, and encourage throttling to find a steady state - const float TARGET = 0.9f; - // on a "regular" machine with 100 avatars, this is the largest value where - // - overthrottling can be recovered - // - oscillations will not occur after the recovery - const float BACKOFF_TARGET = 0.44f; + const float TARGET = _throttleStartTarget; + const float BACKOFF_TARGET = _throttleBackoffTarget; // the mixer is known to struggle at about 80 on a "regular" machine // so throttle 2/80 the streams to ensure smooth audio (throttling is linear) @@ -551,6 +552,24 @@ void AudioMixer::parseSettingsObject(const QJsonObject& settingsObject) { _slavePool.setNumThreads(numThreads); } } + + const QString THROTTLE_START_KEY = "throttle_start"; + const QString THROTTLE_BACKOFF_KEY = "throttle_backoff"; + + float settingsThrottleStart = audioThreadingGroupObject[THROTTLE_START_KEY].toDouble(_throttleStartTarget); + float settingsThrottleBackoff = audioThreadingGroupObject[THROTTLE_BACKOFF_KEY].toDouble(_throttleBackoffTarget); + + if (settingsThrottleBackoff > settingsThrottleStart) { + qCWarning(audio) << "Throttle backoff target cannot be higher than throttle start target. Using default values."; + } else if (settingsThrottleBackoff < 0.0f || settingsThrottleStart > 1.0f) { + qCWarning(audio) << "Throttle start and backoff targets must be greater than or equal to 0.0" + << "and lesser than or equal to 1.0. Using default values."; + } else { + _throttleStartTarget = settingsThrottleStart; + _throttleBackoffTarget = settingsThrottleBackoff; + } + + qCDebug(audio) << "Throttle Start:" << _throttleStartTarget << "Throttle Backoff:" << _throttleBackoffTarget; } if (settingsObject.contains(AUDIO_BUFFER_GROUP_KEY)) { diff --git a/assignment-client/src/audio/AudioMixer.h b/assignment-client/src/audio/AudioMixer.h index b8ea0d5c58..c7726d2fea 100644 --- a/assignment-client/src/audio/AudioMixer.h +++ b/assignment-client/src/audio/AudioMixer.h @@ -144,11 +144,13 @@ private: static std::map _availableCodecs; static QStringList _codecPreferenceOrder; - static std::vector _audioZones; static std::vector _zoneSettings; static std::vector _zoneReverbSettings; + float _throttleStartTarget = 0.9f; + float _throttleBackoffTarget = 0.44f; + AudioMixerSlave::SharedData _workerSharedData; }; diff --git a/assignment-client/src/audio/AudioMixerClientData.cpp b/assignment-client/src/audio/AudioMixerClientData.cpp index 9a78ba31a2..90698bfac8 100644 --- a/assignment-client/src/audio/AudioMixerClientData.cpp +++ b/assignment-client/src/audio/AudioMixerClientData.cpp @@ -337,6 +337,13 @@ void AudioMixerClientData::removeAgentAvatarAudioStream() { if (it != _audioStreams.end()) { _audioStreams.erase(it); + + // Clear mixing structures so that they get recreated with up to date + // data if the stream comes back + setHasReceivedFirstMix(false); + _streams.skipped.clear(); + _streams.inactive.clear(); + _streams.active.clear(); } } diff --git a/assignment-client/src/avatars/AvatarMixerClientData.cpp b/assignment-client/src/avatars/AvatarMixerClientData.cpp index 76cdf13986..5e36d8beaf 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.cpp +++ b/assignment-client/src/avatars/AvatarMixerClientData.cpp @@ -152,6 +152,8 @@ void AvatarMixerClientData::processSetTraitsMessage(ReceivedMessage& message, if (packetTraitVersion > instanceVersionRef) { if (traitSize == AvatarTraits::DELETED_TRAIT_SIZE) { _avatar->processDeletedTraitInstance(traitType, instanceID); + // Mixer doesn't need deleted IDs. + _avatar->getAndClearRecentlyDetachedIDs(); // to track a deleted instance but keep version information // the avatar mixer uses the negative value of the sent version diff --git a/assignment-client/src/avatars/AvatarMixerSlave.cpp b/assignment-client/src/avatars/AvatarMixerSlave.cpp index 7e0b6a00ad..a037f24345 100644 --- a/assignment-client/src/avatars/AvatarMixerSlave.cpp +++ b/assignment-client/src/avatars/AvatarMixerSlave.cpp @@ -416,7 +416,8 @@ void AvatarMixerSlave::broadcastAvatarDataToAgent(const SharedNodePointer& node) // NOTE: Here's where we determine if we are over budget and drop remaining avatars, // or send minimal avatar data in uncommon case of PALIsOpen. int minimRemainingAvatarBytes = minimumBytesPerAvatar * remainingAvatars; - bool overBudget = (identityBytesSent + numAvatarDataBytes + minimRemainingAvatarBytes) > maxAvatarBytesPerFrame; + auto frameByteEstimate = identityBytesSent + traitBytesSent + numAvatarDataBytes + minimRemainingAvatarBytes; + bool overBudget = frameByteEstimate > maxAvatarBytesPerFrame; if (overBudget) { if (PALIsOpen) { _stats.overBudgetAvatars++; @@ -497,8 +498,11 @@ void AvatarMixerSlave::broadcastAvatarDataToAgent(const SharedNodePointer& node) _stats.avatarDataPackingElapsedTime += (quint64) chrono::duration_cast(endAvatarDataPacking - startAvatarDataPacking).count(); - // use helper to add any changed traits to our packet list - traitBytesSent += addChangedTraitsToBulkPacket(nodeData, otherNodeData, *traitsPacketList); + if (!overBudget) { + // use helper to add any changed traits to our packet list + traitBytesSent += addChangedTraitsToBulkPacket(nodeData, otherNodeData, *traitsPacketList); + } + remainingAvatars--; } diff --git a/assignment-client/src/avatars/ScriptableAvatar.cpp b/assignment-client/src/avatars/ScriptableAvatar.cpp index 51038a782f..bf5d87a6bf 100644 --- a/assignment-client/src/avatars/ScriptableAvatar.cpp +++ b/assignment-client/src/avatars/ScriptableAvatar.cpp @@ -21,7 +21,7 @@ #include ScriptableAvatar::ScriptableAvatar() { - _clientTraitsHandler = std::unique_ptr(new ClientTraitsHandler(this)); + _clientTraitsHandler.reset(new ClientTraitsHandler(this)); } QByteArray ScriptableAvatar::toByteArrayStateful(AvatarDataDetail dataDetail, bool dropFaceTracking) { diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index 272985093c..ef0c807bc4 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -583,15 +583,29 @@ void EntityScriptServer::handleOctreePacket(QSharedPointer mess void EntityScriptServer::aboutToFinish() { shutdownScriptEngine(); + DependencyManager::get()->setEntityTree(nullptr); + DependencyManager::get()->cleanup(); + + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + DependencyManager::destroy(); + + DependencyManager::destroy(); + DependencyManager::destroy(); + + DependencyManager::destroy(); + DependencyManager::destroy(); + + DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); - DependencyManager::get()->cleanup(); DependencyManager::destroy(); - DependencyManager::destroy(); - DependencyManager::destroy(); // cleanup the AudioInjectorManager (and any still running injectors) DependencyManager::destroy(); diff --git a/cmake/macros/MemoryDebugger.cmake b/cmake/macros/MemoryDebugger.cmake index ed80e03c6b..09716715f0 100644 --- a/cmake/macros/MemoryDebugger.cmake +++ b/cmake/macros/MemoryDebugger.cmake @@ -16,9 +16,9 @@ if (HIFI_MEMORY_DEBUGGING) if (UNIX) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # for clang on Linux - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address -fsanitize-recover=address") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address -fsanitize-recover=address") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address -fsanitize-recover=address") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -shared-libasan -fsanitize=undefined -fsanitize=address -fsanitize-recover=address") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -shared-libasan -fsanitize=undefined -fsanitize=address -fsanitize-recover=address") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -shared-libasan -fsanitize=undefined -fsanitize=address -fsanitize-recover=address") else () # for gcc on Linux SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fsanitize=address -U_FORTIFY_SOURCE -fno-stack-protector -fno-omit-frame-pointer") diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 5d1f725ab4..49023c9af8 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -1012,6 +1012,24 @@ "placeholder": "1", "default": "1", "advanced": true + }, + { + "name": "throttle_start", + "type": "double", + "label": "Throttle Start Target", + "help": "Target percentage of frame time to start throttling", + "placeholder": "0.9", + "default": 0.9, + "advanced": true + }, + { + "name": "throttle_backoff", + "type": "double", + "label": "Throttle Backoff Target", + "help": "Target percentage of frame time to backoff throttling", + "placeholder": "0.44", + "default": 0.44, + "advanced": true } ] }, diff --git a/domain-server/resources/web/content/js/content.js b/domain-server/resources/web/content/js/content.js index 346e846748..85bd9e68b3 100644 --- a/domain-server/resources/web/content/js/content.js +++ b/domain-server/resources/web/content/js/content.js @@ -10,10 +10,85 @@ $(document).ready(function(){ function progressBarHTML(extraClass, label) { var html = "
"; html += "
"; - html += label + "
"; + html += ""; return html; } + function showUploadProgress(title) { + swal({ + title: title, + text: progressBarHTML('upload-content-progress', 'Upload'), + html: true, + showConfirmButton: false, + allowEscapeKey: false + }); + } + + function uploadNextChunk(file, offset, id) { + if (offset == undefined) { + offset = 0; + } + if (id == undefined) { + // Identify this upload session + id = Math.round(Math.random() * 2147483647); + } + + var fileSize = file.size; + var filename = file.name; + + var CHUNK_SIZE = 1048576; // 1 MiB + + var isFinal = Boolean(fileSize - offset <= CHUNK_SIZE); + var nextChunkSize = Math.min(fileSize - offset, CHUNK_SIZE); + var chunk = file.slice(offset, offset + nextChunkSize, file.type); + var chunkFormData = new FormData(); + + var formItemName = 'restore-file-chunk'; + if (offset == 0) { + formItemName = isFinal ? 'restore-file-chunk-only' : 'restore-file-chunk-initial'; + } else if (isFinal) { + formItemName = 'restore-file-chunk-final'; + } + + chunkFormData.append(formItemName, chunk, filename); + var ajaxParams = { + url: '/content/upload', + type: 'POST', + timeout: 30000, // 30 s + headers: {"X-Session-Id": id}, + cache: false, + processData: false, + contentType: false, + data: chunkFormData + }; + + var ajaxObject = $.ajax(ajaxParams); + ajaxObject.fail(function (jqXHR, textStatus, errorThrown) { + showErrorMessage( + "Error", + "There was a problem restoring domain content.\n" + + "Please ensure that the content archive or entity file is valid and try again." + ); + }); + + updateProgressBars($('.upload-content-progress'), (offset + nextChunkSize) * 100 / fileSize); + + if (!isFinal) { + ajaxObject.done(function (data, textStatus, jqXHR) + { uploadNextChunk(file, offset + CHUNK_SIZE, id); }); + } else { + ajaxObject.done(function(data, textStatus, jqXHR) { + isRestoring = true; + + // immediately reload backup information since one should be restoring now + reloadBackupInformation(); + + swal.close(); + }); + } + + } + function setupBackupUpload() { // construct the HTML needed for the settings backup panel var html = "
"; @@ -50,34 +125,10 @@ $(document).ready(function(){ "Restore content", function() { var files = $('#' + RESTORE_SETTINGS_FILE_ID).prop('files'); + var file = files[0]; - var fileFormData = new FormData(); - fileFormData.append('restore-file', files[0]); - - showSpinnerAlert("Uploading content to restore"); - - $.ajax({ - url: '/content/upload', - type: 'POST', - timeout: 3600000, // Set timeout to 1h - cache: false, - processData: false, - contentType: false, - data: fileFormData - }).done(function(data, textStatus, jqXHR) { - isRestoring = true; - - // immediately reload backup information since one should be restoring now - reloadBackupInformation(); - - swal.close(); - }).fail(function(jqXHR, textStatus, errorThrown) { - showErrorMessage( - "Error", - "There was a problem restoring domain content.\n" - + "Please ensure that the content archive or entity file is valid and try again." - ); - }); + showUploadProgress("Uploading " + file.name); + uploadNextChunk(file); } ); }); @@ -168,6 +219,11 @@ $(document).ready(function(){ checkBackupStatus(); }); + function updateProgressBars($progressBar, value) { + $progressBar.attr('aria-valuenow', value).attr('style', 'width: ' + value + '%'); + $progressBar.find('.ongoing-msg').html(" " + Math.round(value) + "%"); + } + function reloadBackupInformation() { // make a GET request to get backup information to populate the table $.ajax({ @@ -204,11 +260,6 @@ $(document).ready(function(){ + "
  • Delete
  • "; } - function updateProgressBars($progressBar, value) { - $progressBar.attr('aria-valuenow', value).attr('style', 'width: ' + value + '%'); - $progressBar.find('.sr-only').html(value + "% Complete"); - } - // before we add any new rows and update existing ones // remove our flag for active rows $('.' + ACTIVE_BACKUP_ROW_CLASS).removeClass(ACTIVE_BACKUP_ROW_CLASS); diff --git a/domain-server/src/DomainContentBackupManager.cpp b/domain-server/src/DomainContentBackupManager.cpp index 518ed73f9e..3b8180e49e 100644 --- a/domain-server/src/DomainContentBackupManager.cpp +++ b/domain-server/src/DomainContentBackupManager.cpp @@ -348,6 +348,27 @@ void DomainContentBackupManager::recoverFromUploadedBackup(MiniPromise::Promise }); } +void DomainContentBackupManager::recoverFromUploadedFile(MiniPromise::Promise promise, QString uploadedFilename) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "recoverFromUploadedFile", Q_ARG(MiniPromise::Promise, promise), + Q_ARG(QString, uploadedFilename)); + return; + } + + qDebug() << "Recovering from uploaded file -" << uploadedFilename; + + QFile uploadedFile(uploadedFilename); + QuaZip uploadedZip { &uploadedFile }; + + QString backupName = MANUAL_BACKUP_PREFIX + "uploaded.zip"; + + bool success = recoverFromBackupZip(backupName, uploadedZip); + + promise->resolve({ + { "success", success } + }); +} + std::vector DomainContentBackupManager::getAllBackups() { QDir backupDir { _backupDirectory }; diff --git a/domain-server/src/DomainContentBackupManager.h b/domain-server/src/DomainContentBackupManager.h index 2b07afe0b3..4af3ae5bfd 100644 --- a/domain-server/src/DomainContentBackupManager.h +++ b/domain-server/src/DomainContentBackupManager.h @@ -86,6 +86,7 @@ public slots: void createManualBackup(MiniPromise::Promise promise, const QString& name); void recoverFromBackup(MiniPromise::Promise promise, const QString& backupName); void recoverFromUploadedBackup(MiniPromise::Promise promise, QByteArray uploadedBackup); + void recoverFromUploadedFile(MiniPromise::Promise promise, QString uploadedFilename); void deleteBackup(MiniPromise::Promise promise, const QString& backupName); signals: diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 8cf033c130..69f16af8b3 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -2258,46 +2258,18 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url // check the file extension to see what kind of file this is // to make sure we handle this filetype for a content restore auto dispositionValue = QString(firstFormData.first.value("Content-Disposition")); - auto formDataFilenameRegex = QRegExp("filename=\"(.+)\""); - auto matchIndex = formDataFilenameRegex.indexIn(dispositionValue); + QRegExp formDataFieldsRegex(R":(name="(restore-file.*)".*filename="(.+)"):"); + auto matchIndex = formDataFieldsRegex.indexIn(dispositionValue); + QString formItemName = ""; QString uploadedFilename = ""; if (matchIndex != -1) { - uploadedFilename = formDataFilenameRegex.cap(1); - } - - if (uploadedFilename.endsWith(".json", Qt::CaseInsensitive) - || uploadedFilename.endsWith(".json.gz", Qt::CaseInsensitive)) { - // invoke our method to hand the new octree file off to the octree server - QMetaObject::invokeMethod(this, "handleOctreeFileReplacement", - Qt::QueuedConnection, Q_ARG(QByteArray, firstFormData.second)); - - // respond with a 200 for success - connection->respond(HTTPConnection::StatusCode200); - } else if (uploadedFilename.endsWith(".zip", Qt::CaseInsensitive)) { - auto deferred = makePromise("recoverFromUploadedBackup"); - - deferred->then([connectionPtr, JSON_MIME_TYPE](QString error, QVariantMap result) { - if (!connectionPtr) { - return; - } - - QJsonObject rootJSON; - auto success = result["success"].toBool(); - rootJSON["success"] = success; - QJsonDocument docJSON(rootJSON); - connectionPtr->respond(success ? HTTPConnection::StatusCode200 : HTTPConnection::StatusCode400, docJSON.toJson(), - JSON_MIME_TYPE.toUtf8()); - }); - - _contentManager->recoverFromUploadedBackup(deferred, firstFormData.second); - - return true; - } else { - // we don't have handling for this filetype, send back a 400 for failure - connection->respond(HTTPConnection::StatusCode400); + formItemName = formDataFieldsRegex.cap(1); + uploadedFilename = formDataFieldsRegex.cap(2); } + // Received a chunk + processPendingContent(connection, formItemName, uploadedFilename, firstFormData.second); } else { // respond with a 400 for failure connection->respond(HTTPConnection::StatusCode400); @@ -2546,6 +2518,72 @@ bool DomainServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl &u } } +bool DomainServer::processPendingContent(HTTPConnection* connection, QString itemName, QString filename, QByteArray dataChunk) { + static const QString UPLOAD_SESSION_KEY { "X-Session-Id" }; + QByteArray sessionIdBytes = connection->requestHeader(UPLOAD_SESSION_KEY); + int sessionId = sessionIdBytes.toInt(); + + bool newUpload = itemName == "restore-file" || itemName == "restore-file-chunk-initial" || itemName == "restore-file-chunk-only"; + + if (filename.endsWith(".zip", Qt::CaseInsensitive)) { + static const QString TEMPORARY_CONTENT_FILEPATH { QDir::tempPath() + "/hifiUploadContent_XXXXXX.zip" }; + + if (_pendingContentFiles.find(sessionId) == _pendingContentFiles.end()) { + if (!newUpload) { + return false; + } + std::unique_ptr newTemp(new QTemporaryFile(TEMPORARY_CONTENT_FILEPATH)); + _pendingContentFiles[sessionId] = std::move(newTemp); + } else if (newUpload) { + qCDebug(domain_server) << "New upload received using existing session ID"; + _pendingContentFiles[sessionId]->resize(0); + } + + QTemporaryFile& _pendingFileContent = *_pendingContentFiles[sessionId]; + if (!_pendingFileContent.open()) { + _pendingContentFiles.erase(sessionId); + connection->respond(HTTPConnection::StatusCode400); + return false; + } + _pendingFileContent.seek(_pendingFileContent.size()); + _pendingFileContent.write(dataChunk); + _pendingFileContent.close(); + + // Respond immediately - will timeout if we wait for restore. + connection->respond(HTTPConnection::StatusCode200); + if (itemName == "restore-file" || itemName == "restore-file-chunk-final" || itemName == "restore-file-chunk-only") { + auto deferred = makePromise("recoverFromUploadedBackup"); + + deferred->then([this, sessionId](QString error, QVariantMap result) { + _pendingContentFiles.erase(sessionId); + }); + + _contentManager->recoverFromUploadedFile(deferred, _pendingFileContent.fileName()); + } + } else if (filename.endsWith(".json", Qt::CaseInsensitive) + || filename.endsWith(".json.gz", Qt::CaseInsensitive)) { + if (_pendingUploadedContents.find(sessionId) == _pendingUploadedContents.end() && !newUpload) { + qCDebug(domain_server) << "Json upload with invalid session ID received"; + return false; + } + QByteArray& _pendingUploadedContent = _pendingUploadedContents[sessionId]; + _pendingUploadedContent += dataChunk; + connection->respond(HTTPConnection::StatusCode200); + + if (itemName == "restore-file" || itemName == "restore-file-chunk-final" || itemName == "restore-file-chunk-only") { + // invoke our method to hand the new octree file off to the octree server + QMetaObject::invokeMethod(this, "handleOctreeFileReplacement", + Qt::QueuedConnection, Q_ARG(QByteArray, _pendingUploadedContent)); + _pendingUploadedContents.erase(sessionId); + } + } else { + connection->respond(HTTPConnection::StatusCode400); + return false; + } + + return true; +} + HTTPSConnection* DomainServer::connectionFromReplyWithState(QNetworkReply* reply) { // grab the UUID state property from the reply QUuid stateUUID = reply->property(STATE_QUERY_KEY.toLocal8Bit()).toUuid(); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index e2bddc1aa5..f0c20241a2 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -209,6 +210,8 @@ private: HTTPSConnection* connectionFromReplyWithState(QNetworkReply* reply); + bool processPendingContent(HTTPConnection* connection, QString itemName, QString filename, QByteArray dataChunk); + bool forwardMetaverseAPIRequest(HTTPConnection* connection, const QString& metaversePath, const QString& requestSubobject, @@ -281,6 +284,9 @@ private: QHash> _pendingOAuthConnections; + std::unordered_map _pendingUploadedContents; + std::unordered_map> _pendingContentFiles; + QThread _assetClientThread; }; diff --git a/interface/resources/config/keyboard.json b/interface/resources/config/keyboard.json index 186a9c1084..b3688ef06e 100644 --- a/interface/resources/config/keyboard.json +++ b/interface/resources/config/keyboard.json @@ -701,9 +701,9 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.53203323516845703, + "x": -0.59333323516845703, "y": 0.019300000742077827, - "z": -0.07286686894893646 + "z": 0.037454843521118164 }, "modelURL": "meshes/keyboard/SM_key.fbx", "texture": { @@ -752,7 +752,7 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.59333323516845703, + "x": -0.65333323516845703, "y": 0.019300000742077827, "z": 0.037454843521118164 }, @@ -777,9 +777,9 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.5103323516845703, - "y": 0.019300000742077827, - "z": -0.127054843521118164 + "x": -0.5503323516845703, + "y": 0.019300000742077827, + "z": -0.07282185554504395 }, "modelURL": "meshes/keyboard/SM_enter.fbx", "texture": { @@ -1479,9 +1479,9 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.53203323516845703, + "x": -0.59333323516845703, "y": 0.019300000742077827, - "z": -0.07286686894893646 + "z": 0.037454843521118164 }, "modelURL": "meshes/keyboard/SM_key.fbx", "texture": { @@ -1530,7 +1530,7 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.59333323516845703, + "x": -0.65333323516845703, "y": 0.019300000742077827, "z": 0.037454843521118164 }, @@ -1555,9 +1555,9 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.5103323516845703, - "y": 0.019300000742077827, - "z": -0.127054843521118164 + "x": -0.5503323516845703, + "y": 0.019300000742077827, + "z": -0.07282185554504395 }, "modelURL": "meshes/keyboard/SM_enter.fbx", "texture": { @@ -2305,9 +2305,9 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.53203323516845703, + "x": -0.59333323516845703, "y": 0.019300000742077827, - "z": -0.07286686894893646 + "z": 0.037454843521118164 }, "modelURL": "meshes/keyboard/SM_key.fbx", "texture": { @@ -2356,7 +2356,7 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.59333323516845703, + "x": -0.65333323516845703, "y": 0.019300000742077827, "z": 0.037454843521118164 }, @@ -2381,9 +2381,9 @@ "y": 0.04787999764084816 }, "position": { - "x": -0.5103323516845703, - "y": 0.019300000742077827, - "z": -0.127054843521118164 + "x": -0.5503323516845703, + "y": 0.019300000742077827, + "z": -0.07282185554504395 }, "modelURL": "meshes/keyboard/SM_enter.fbx", "texture": { diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index 8cdb3c2327..db8ff24fcb 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -18,7 +18,7 @@ window.isKeyboardRaised = false; window.isNumericKeyboard = false; window.isPasswordField = false; - window.lastActiveElement = null; + window.lastActiveInputElement = null; function getActiveElement() { return document.activeElement; @@ -70,11 +70,15 @@ var keyboardRaised = shouldRaiseKeyboard(); var numericKeyboard = shouldSetNumeric(); var passwordField = shouldSetPasswordField(); - var activeElement = getActiveElement(); + var activeInputElement = null; + // Only set the active input element when there is an input element focussed, otherwise it will scroll on body focus as well. + if (keyboardRaised) { + activeInputElement = getActiveElement(); + } if (isWindowFocused && (keyboardRaised !== window.isKeyboardRaised || numericKeyboard !== window.isNumericKeyboard - || passwordField !== window.isPasswordField || activeElement !== window.lastActiveElement)) { + || passwordField !== window.isPasswordField || activeInputElement !== window.lastActiveInputElement)) { if (typeof EventBridge !== "undefined" && EventBridge !== null) { EventBridge.emitWebEvent( @@ -96,7 +100,7 @@ window.isKeyboardRaised = keyboardRaised; window.isNumericKeyboard = numericKeyboard; window.isPasswordField = passwordField; - window.lastActiveElement = activeElement; + window.lastActiveInputElement = activeInputElement; } }, POLL_FREQUENCY); diff --git a/interface/resources/html/tabletHelp.html b/interface/resources/html/tabletHelp.html index 279213bbcb..dd7931d0ed 100644 --- a/interface/resources/html/tabletHelp.html +++ b/interface/resources/html/tabletHelp.html @@ -66,7 +66,7 @@ diff --git a/interface/resources/meshes/drumstick.fbx b/interface/resources/meshes/drumstick.fbx index 0243d9fd1b..b384e6a30a 100644 Binary files a/interface/resources/meshes/drumstick.fbx and b/interface/resources/meshes/drumstick.fbx differ diff --git a/interface/resources/qml/LoginDialog/LinkAccountBody.qml b/interface/resources/qml/LoginDialog/LinkAccountBody.qml index 103761236d..3e4614c342 100644 --- a/interface/resources/qml/LoginDialog/LinkAccountBody.qml +++ b/interface/resources/qml/LoginDialog/LinkAccountBody.qml @@ -23,6 +23,8 @@ Item { width: root.pane.width property bool failAfterSignUp: false + onWidthChanged: d.resize(); + function login() { flavorText.visible = false mainTextContainer.visible = false @@ -127,7 +129,7 @@ Item { Column { id: form width: parent.width - onHeightChanged: d.resize(); onWidthChanged: d.resize(); + onHeightChanged: d.resize(); anchors { top: mainTextContainer.bottom diff --git a/interface/resources/qml/controlsUit/Keyboard.qml b/interface/resources/qml/controlsUit/Keyboard.qml index c38631ff79..a55523f34a 100644 --- a/interface/resources/qml/controlsUit/Keyboard.qml +++ b/interface/resources/qml/controlsUit/Keyboard.qml @@ -44,14 +44,14 @@ Rectangle { onPasswordChanged: { - var use3DKeyboard = (typeof MenuInterface === "undefined") ? false : MenuInterface.isOptionChecked("Use 3D Keyboard"); + var use3DKeyboard = (typeof KeyboardScriptingInterface === "undefined") ? false : KeyboardScriptingInterface.use3DKeyboard; if (use3DKeyboard) { KeyboardScriptingInterface.password = password; } } onRaisedChanged: { - var use3DKeyboard = (typeof MenuInterface === "undefined") ? false : MenuInterface.isOptionChecked("Use 3D Keyboard"); + var use3DKeyboard = (typeof KeyboardScriptingInterface === "undefined") ? false : KeyboardScriptingInterface.use3DKeyboard; if (!use3DKeyboard) { keyboardBase.height = raised ? raisedHeight : 0; keyboardBase.visible = raised; diff --git a/interface/resources/qml/dialogs/TabletLoginDialog.qml b/interface/resources/qml/dialogs/TabletLoginDialog.qml index dad2bb91aa..0b19e34b0a 100644 --- a/interface/resources/qml/dialogs/TabletLoginDialog.qml +++ b/interface/resources/qml/dialogs/TabletLoginDialog.qml @@ -141,6 +141,7 @@ TabletModalWindow { Component.onDestruction: { loginKeyboard.raised = false; + KeyboardScriptingInterface.raised = false; } Component.onCompleted: { diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index f57c612b98..354c8095a0 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -70,8 +70,8 @@ OriginalDesktop.Desktop { anchors.horizontalCenter: settings.constrainToolbarToCenterX ? desktop.horizontalCenter : undefined; // Literal 50 is overwritten by settings from previous session, and sysToolbar.x comes from settings when not constrained. x: sysToolbar.x - buttonModel: tablet.buttons; - shown: tablet.toolbarMode; + buttonModel: tablet ? tablet.buttons : null; + shown: tablet ? tablet.toolbarMode : false; } Settings { diff --git a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml index c2a4d47992..7e17d20375 100644 --- a/interface/resources/qml/hifi/commerce/checkout/Checkout.qml +++ b/interface/resources/qml/hifi/commerce/checkout/Checkout.qml @@ -19,6 +19,7 @@ import controlsUit 1.0 as HifiControlsUit import "../../../controls" as HifiControls import "../wallet" as HifiWallet import "../common" as HifiCommerceCommon +import "../.." as HifiCommon // references XXX from root context @@ -31,6 +32,7 @@ Rectangle { property bool ownershipStatusReceived: false; property bool balanceReceived: false; property bool availableUpdatesReceived: false; + property bool itemInfoReceived: false; property string baseItemName: ""; property string itemName; property string itemId; @@ -181,11 +183,14 @@ Rectangle { onItemIdChanged: { root.ownershipStatusReceived = false; + root.itemInfoReceived = false; Commerce.alreadyOwned(root.itemId); root.availableUpdatesReceived = false; root.currentUpdatesPage = 1; Commerce.getAvailableUpdates(root.itemId); - itemPreviewImage.source = "https://hifi-metaverse.s3-us-west-1.amazonaws.com/marketplace/previews/" + itemId + "/thumbnail/hifi-mp-" + itemId + ".jpg"; + + var MARKETPLACE_API_URL = Account.metaverseServerURL + "/api/v1/marketplace/items/"; + http.request({uri: MARKETPLACE_API_URL + root.itemId}, updateCheckoutQMLFromHTTP); } onItemTypeChanged: { @@ -279,6 +284,7 @@ Rectangle { ownershipStatusReceived = false; balanceReceived = false; availableUpdatesReceived = false; + itemInfoReceived = false; Commerce.getWalletStatus(); } } @@ -355,7 +361,7 @@ Rectangle { Rectangle { id: loading; z: 997; - visible: !root.ownershipStatusReceived || !root.balanceReceived || !root.availableUpdatesReceived; + visible: !root.ownershipStatusReceived || !root.balanceReceived || !root.availableUpdatesReceived || !root.itemInfoReceived; anchors.fill: parent; color: hifi.colors.white; @@ -1063,10 +1069,33 @@ Rectangle { } } } + + + HifiCommon.RootHttpRequest { + id: http; + } // // FUNCTION DEFINITIONS START // + + function updateCheckoutQMLFromHTTP(error, result) { + if (error || (result.status !== 'success')) { + // The QML will display a loading spinner forever if the user is stuck here. + console.log("Error in Checkout.qml when getting marketplace item info!"); + return; + } + + root.itemInfoReceived = true; + root.itemName = result.data.title; + root.itemPrice = result.data.cost; + root.itemHref = Account.metaverseServerURL + result.data.path; + root.itemAuthor = result.data.creator; + root.itemType = result.data.item_type || "unknown"; + itemPreviewImage.source = result.data.thumbnail_url; + refreshBuyUI(); + } + // // Function Name: fromScript() // @@ -1080,18 +1109,24 @@ Rectangle { // Description: // Called when a message is received from a script. // + function fromScript(message) { switch (message.method) { - case 'updateCheckoutQML': - root.itemId = message.params.itemId; - root.itemName = message.params.itemName.trim(); - root.itemPrice = message.params.itemPrice; - root.itemHref = message.params.itemHref; - root.referrer = message.params.referrer; - root.itemAuthor = message.params.itemAuthor; + case 'updateCheckoutQMLItemID': + if (!message.params.itemId) { + console.log("A message with method 'updateCheckoutQMLItemID' was sent without an itemId!"); + return; + } + + // If we end up following the referrer (i.e. in case the wallet "isn't set up" or the user cancels), + // we want the user to be placed back on the individual item's page - thus we set the + // default of the referrer in this case to "itemPage". + root.referrer = message.params.referrer || "itemPage"; root.itemEdition = message.params.itemEdition || -1; - root.itemType = message.params.itemType || "unknown"; - refreshBuyUI(); + root.itemId = message.params.itemId; + break; + case 'http.response': + http.handleHttpResponse(message); break; default: console.log('Checkout.qml: Unrecognized message from marketplaces.js'); diff --git a/interface/resources/qml/hifi/commerce/common/sendAsset/RecipientDisplay.qml b/interface/resources/qml/hifi/commerce/common/sendAsset/RecipientDisplay.qml index 9e1a967d50..10756957d3 100644 --- a/interface/resources/qml/hifi/commerce/common/sendAsset/RecipientDisplay.qml +++ b/interface/resources/qml/hifi/commerce/common/sendAsset/RecipientDisplay.qml @@ -25,14 +25,15 @@ Item { id: root; - property bool isDisplayingNearby; // as opposed to 'connections' + // true when sending to 'nearby' or when a script raises the send asset dialog + property bool multiLineDisplay; property string displayName; property string userName; property string profilePic; property string textColor: hifi.colors.white; Item { - visible: root.isDisplayingNearby; + visible: root.multiLineDisplay; anchors.fill: parent; RalewaySemiBold { @@ -71,7 +72,7 @@ Item { } Item { - visible: !root.isDisplayingNearby; + visible: !root.multiLineDisplay; anchors.fill: parent; Image { diff --git a/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml b/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml index d6378f82ac..2d0bb2d87b 100644 --- a/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml +++ b/interface/resources/qml/hifi/commerce/common/sendAsset/SendAsset.qml @@ -39,7 +39,7 @@ Item { property string sendingPubliclyEffectImage; property var http; property var listModelName; - property var keyboardContainer: nil; + property var keyboardContainer; // This object is always used in a popup or full-screen Wallet section. // This MouseArea is used to prevent a user from being @@ -56,7 +56,7 @@ Item { // Background Rectangle { z: 1; - visible: root.assetName !== "" && sendAssetStep.visible; + visible: root.assetCertID !== "" && sendAssetStep.referrer !== "payIn" && sendAssetStep.visible; anchors.top: parent.top; anchors.topMargin: root.parentAppTitleBarHeight; anchors.left: parent.left; @@ -84,7 +84,6 @@ Item { if (sendPubliclyCheckbox.checked && sendAssetStep.referrer === "nearby") { sendSignalToParent({ method: 'sendAsset_sendPublicly', - assetName: root.assetName, recipient: sendAssetStep.selectedRecipientNodeID, amount: parseInt(amountTextField.text), effectImage: root.sendingPubliclyEffectImage @@ -108,6 +107,14 @@ Item { root.nextActiveView = 'paymentFailure'; } } + + onCertificateInfoResult: { + if (result.status !== 'success') { + console.log("Failed to get certificate info", result.data.message); + } else { + root.assetName = result.data.marketplace_item_name; + } + } } Connections { @@ -155,7 +162,7 @@ Item { Item { id: userInfoContainer; - visible: root.assetName === ""; + visible: root.assetCertID === ""; anchors.top: parent.top; anchors.left: parent.left; anchors.right: parent.right; @@ -251,7 +258,7 @@ Item { LinearGradient { anchors.fill: parent; - visible: root.assetName === ""; + visible: root.assetCertID === ""; start: Qt.point(0, 0); end: Qt.point(0, height); gradient: Gradient { @@ -262,7 +269,7 @@ Item { RalewaySemiBold { id: sendAssetText; - text: root.assetName === "" ? "Send Money To:" : "Gift \"" + root.assetName + "\" To:"; + text: root.assetCertID === "" ? "Send Money To:" : "Gift \"" + root.assetName + "\" To:"; // Anchors anchors.top: parent.top; anchors.topMargin: 26; @@ -405,7 +412,7 @@ Item { HifiModels.PSFListModel { id: connectionsModel; http: root.http; - listModelName: root.listModelName; + listModelName: root.listModelName || ""; endpoint: "/api/v1/users?filter=connections"; itemsPerPage: 9; listView: connectionsList; @@ -441,7 +448,7 @@ Item { HiFiGlyphs { id: closeGlyphButton_connections; text: hifi.glyphs.close; - color: root.assetName === "" ? hifi.colors.lightGrayText : hifi.colors.baseGray; + color: root.assetCertID === "" ? hifi.colors.lightGrayText : hifi.colors.baseGray; size: 26; anchors.top: parent.top; anchors.topMargin: 10; @@ -684,7 +691,7 @@ Item { HiFiGlyphs { id: closeGlyphButton_nearby; text: hifi.glyphs.close; - color: root.assetName === "" ? hifi.colors.lightGrayText : hifi.colors.baseGray; + color: root.assetCertID === "" ? hifi.colors.lightGrayText : hifi.colors.baseGray; size: 26; anchors.top: parent.top; anchors.topMargin: 10; @@ -760,7 +767,7 @@ Item { RalewaySemiBold { id: sendToText; - text: root.assetName === "" ? "Send to:" : "Gift to:"; + text: root.assetCertID === "" ? "Send to:" : "Gift to:"; // Anchors anchors.top: parent.top; anchors.topMargin: 36; @@ -853,7 +860,7 @@ Item { id: sendAssetStep; z: 996; - property string referrer; // either "connections" or "nearby" + property string referrer; // either "connections", "nearby", or "payIn" property string selectedRecipientNodeID; property string selectedRecipientDisplayName; property string selectedRecipientUserName; @@ -865,7 +872,8 @@ Item { RalewaySemiBold { id: sendAssetText_sendAssetStep; - text: root.assetName === "" ? "Send Money" : "Gift \"" + root.assetName + "\""; + text: sendAssetStep.referrer === "payIn" && root.assetCertID !== "" ? "Send \"" + root.assetName + "\":" : + (root.assetCertID === "" ? "Send Money To:" : "Gift \"" + root.assetName + "\" To:"); // Anchors anchors.top: parent.top; anchors.topMargin: 26; @@ -878,7 +886,7 @@ Item { // Text size size: 22; // Style - color: root.assetName === "" ? hifi.colors.white : hifi.colors.black; + color: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colors.white : hifi.colors.black; } Item { @@ -893,7 +901,7 @@ Item { RalewaySemiBold { id: sendToText_sendAssetStep; - text: root.assetName === "" ? "Send to:" : "Gift to:"; + text: (root.assetCertID === "" || sendAssetStep.referrer === "payIn") ? "Send to:" : "Gift to:"; // Anchors anchors.top: parent.top; anchors.left: parent.left; @@ -902,7 +910,7 @@ Item { // Text size size: 18; // Style - color: root.assetName === "" ? hifi.colors.white : hifi.colors.black; + color: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colors.white : hifi.colors.black; verticalAlignment: Text.AlignVCenter; } @@ -912,25 +920,26 @@ Item { anchors.right: changeButton.left; anchors.rightMargin: 12; height: parent.height; - textColor: root.assetName === "" ? hifi.colors.white : hifi.colors.black; + textColor: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colors.white : hifi.colors.black; displayName: sendAssetStep.selectedRecipientDisplayName; userName: sendAssetStep.selectedRecipientUserName; profilePic: sendAssetStep.selectedRecipientProfilePic !== "" ? ((0 === sendAssetStep.selectedRecipientProfilePic.indexOf("http")) ? sendAssetStep.selectedRecipientProfilePic : (Account.metaverseServerURL + sendAssetStep.selectedRecipientProfilePic)) : ""; - isDisplayingNearby: sendAssetStep.referrer === "nearby"; + multiLineDisplay: sendAssetStep.referrer === "nearby" || sendAssetStep.referrer === "payIn"; } // "CHANGE" button HifiControlsUit.Button { id: changeButton; - color: root.assetName === "" ? hifi.buttons.none : hifi.buttons.white; + color: root.assetCertID === "" ? hifi.buttons.none : hifi.buttons.white; colorScheme: hifi.colorSchemes.dark; anchors.right: parent.right; anchors.verticalCenter: parent.verticalCenter; height: 35; width: 100; text: "CHANGE"; + visible: sendAssetStep.referrer !== "payIn"; onClicked: { if (sendAssetStep.referrer === "connections") { root.nextActiveView = "chooseRecipientConnection"; @@ -944,7 +953,7 @@ Item { Item { id: amountContainer; - visible: root.assetName === ""; + visible: root.assetCertID === ""; anchors.top: sendToContainer.bottom; anchors.topMargin: 2; anchors.left: parent.left; @@ -970,8 +979,9 @@ Item { HifiControlsUit.TextField { id: amountTextField; - text: root.assetName === "" ? "" : "1"; - colorScheme: root.assetName === "" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; + readOnly: sendAssetStep.referrer === "payIn"; + text: root.assetCertID === "" ? "" : "1"; + colorScheme: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; inputMethodHints: Qt.ImhDigitsOnly; // Anchors anchors.verticalCenter: parent.verticalCenter; @@ -980,8 +990,8 @@ Item { height: 50; // Style leftPermanentGlyph: hifi.glyphs.hfc; - activeFocusOnPress: true; - activeFocusOnTab: true; + activeFocusOnPress: !amountTextField.readOnly; + activeFocusOnTab: !amountTextField.readOnly; validator: IntValidator { bottom: 0; } @@ -1071,6 +1081,7 @@ Item { TextArea { id: optionalMessage; + readOnly: sendAssetStep.referrer === "payIn"; property int maximumLength: 72; property string previousText: text; placeholderText: "Optional Public Message (" + maximumLength + " character limit)"; @@ -1081,12 +1092,13 @@ Item { // Style background: Rectangle { anchors.fill: parent; - color: root.assetName === "" ? (optionalMessage.activeFocus ? hifi.colors.black : hifi.colors.baseGrayShadow) : + color: (root.assetCertID === "" || sendAssetStep.referrer === "payIn") ? + (optionalMessage.activeFocus && !optionalMessage.readOnly ? hifi.colors.black : hifi.colors.baseGrayShadow) : (optionalMessage.activeFocus ? "#EFEFEF" : "#EEEEEE"); - border.width: optionalMessage.activeFocus ? 1 : 0; - border.color: optionalMessage.activeFocus ? hifi.colors.primaryHighlight : hifi.colors.textFieldLightBackground; + border.width: optionalMessage.activeFocus && !optionalMessage.readOnly ? 1 : 0; + border.color: optionalMessage.activeFocus && !optionalMessage.readOnly ? hifi.colors.primaryHighlight : hifi.colors.textFieldLightBackground; } - color: root.assetName === "" ? hifi.colors.white : hifi.colors.black; + color: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colors.white : hifi.colors.black; textFormat: TextEdit.PlainText; wrapMode: TextEdit.Wrap; activeFocusOnPress: true; @@ -1122,7 +1134,8 @@ Item { // Text size size: 16; // Style - color: optionalMessage.text.length === optionalMessage.maximumLength ? "#ea89a5" : (root.assetName === "" ? hifi.colors.lightGrayText : hifi.colors.baseGrayHighlight); + color: optionalMessage.text.length === optionalMessage.maximumLength ? "#ea89a5" : + (root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colors.lightGrayText : hifi.colors.baseGrayHighlight); verticalAlignment: Text.AlignTop; horizontalAlignment: Text.AlignRight; } @@ -1167,7 +1180,7 @@ Item { parent.color = hifi.colors.blueAccent; } onClicked: { - lightboxPopup.titleText = (root.assetName === "" ? "Send Effect" : "Gift Effect"); + lightboxPopup.titleText = (root.assetCertID === "" ? "Send Effect" : "Gift Effect"); lightboxPopup.bodyImageSource = "sendAsset/images/send-money-effect-sm.jpg"; // Path relative to CommerceLightbox.qml lightboxPopup.bodyText = "Enabling this option will create a particle effect between you and " + "your recipient that is visible to everyone nearby."; @@ -1196,7 +1209,7 @@ Item { // "CANCEL" button HifiControlsUit.Button { id: cancelButton_sendAssetStep; - color: root.assetName === "" ? hifi.buttons.noneBorderlessWhite : hifi.buttons.noneBorderlessGray; + color: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.buttons.noneBorderlessWhite : hifi.buttons.noneBorderlessGray; colorScheme: hifi.colorSchemes.dark; anchors.right: sendButton.left; anchors.rightMargin: 24; @@ -1205,8 +1218,12 @@ Item { width: 100; text: "CANCEL"; onClicked: { - resetSendAssetData(); - root.nextActiveView = "sendAssetHome"; + if (sendAssetStep.referrer === "payIn") { + sendToScript({method: "closeSendAsset"}); + } else { + resetSendAssetData(); + root.nextActiveView = "sendAssetHome"; + } } } @@ -1214,7 +1231,7 @@ Item { HifiControlsUit.Button { id: sendButton; color: hifi.buttons.blue; - colorScheme: root.assetName === "" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; + colorScheme: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; anchors.right: parent.right; anchors.rightMargin: 0; anchors.verticalCenter: parent.verticalCenter; @@ -1222,11 +1239,11 @@ Item { width: 100; text: "SUBMIT"; onClicked: { - if (root.assetName === "" && parseInt(amountTextField.text) > parseInt(balanceText.text)) { + if (root.assetCertID === "" && parseInt(amountTextField.text) > parseInt(balanceText.text)) { amountTextField.focus = true; amountTextField.error = true; amountTextFieldError.text = "amount exceeds available funds"; - } else if (root.assetName === "" && (amountTextField.text === "" || parseInt(amountTextField.text) < 1)) { + } else if (root.assetCertID === "" && (amountTextField.text === "" || parseInt(amountTextField.text) < 1)) { amountTextField.focus = true; amountTextField.error = true; amountTextFieldError.text = "invalid amount"; @@ -1236,7 +1253,7 @@ Item { root.isCurrentlySendingAsset = true; amountTextField.focus = false; optionalMessage.focus = false; - if (sendAssetStep.referrer === "connections") { + if (sendAssetStep.referrer === "connections" || sendAssetStep.referrer === "payIn") { Commerce.transferAssetToUsername(sendAssetStep.selectedRecipientUserName, root.assetCertID, parseInt(amountTextField.text), @@ -1317,18 +1334,18 @@ Item { Rectangle { anchors.top: parent.top; - anchors.topMargin: root.assetName === "" ? 15 : 125; + anchors.topMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 125; anchors.left: parent.left; - anchors.leftMargin: root.assetName === "" ? 15 : 50; + anchors.leftMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; anchors.right: parent.right; - anchors.rightMargin: root.assetName === "" ? 15 : 50; + anchors.rightMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; anchors.bottom: parent.bottom; - anchors.bottomMargin: root.assetName === "" ? 15 : 125; + anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 125; color: "#FFFFFF"; RalewaySemiBold { id: paymentSentText; - text: root.assetName === "" ? "Payment Sent" : "Gift Sent"; + text: root.assetCertID === "" ? "Payment Sent" : (sendAssetStep.referrer === "payIn" ? "Item Sent" : "Gift Sent"); // Anchors anchors.top: parent.top; anchors.topMargin: 26; @@ -1346,7 +1363,7 @@ Item { HiFiGlyphs { id: closeGlyphButton_paymentSuccess; - visible: root.assetName === ""; + visible: root.assetCertID === "" && sendAssetStep.referrer !== "payIn"; text: hifi.glyphs.close; color: hifi.colors.lightGrayText; size: 26; @@ -1364,10 +1381,14 @@ Item { parent.text = hifi.glyphs.close; } onClicked: { - root.nextActiveView = "sendAssetHome"; - resetSendAssetData(); - if (root.assetName !== "") { - sendSignalToParent({method: "closeSendAsset"}); + if (sendAssetStep.referrer === "payIn") { + sendToScript({method: "closeSendAsset"}); + } else { + root.nextActiveView = "sendAssetHome"; + resetSendAssetData(); + if (root.assetName !== "") { + sendSignalToParent({method: "closeSendAsset"}); + } } } } @@ -1409,14 +1430,14 @@ Item { userName: sendAssetStep.selectedRecipientUserName; profilePic: sendAssetStep.selectedRecipientProfilePic !== "" ? ((0 === sendAssetStep.selectedRecipientProfilePic.indexOf("http")) ? sendAssetStep.selectedRecipientProfilePic : (Account.metaverseServerURL + sendAssetStep.selectedRecipientProfilePic)) : ""; - isDisplayingNearby: sendAssetStep.referrer === "nearby"; + multiLineDisplay: sendAssetStep.referrer === "nearby" || sendAssetStep.referrer === "payIn"; } } Item { id: giftContainer_paymentSuccess; - visible: root.assetName !== ""; + visible: root.assetCertID !== ""; anchors.top: sendToContainer_paymentSuccess.bottom; anchors.topMargin: 8; anchors.left: parent.left; @@ -1427,7 +1448,7 @@ Item { RalewaySemiBold { id: gift_paymentSuccess; - text: "Gift:"; + text: sendAssetStep.referrer === "payIn" ? "Item:" : "Gift:"; // Anchors anchors.top: parent.top; anchors.left: parent.left; @@ -1458,7 +1479,7 @@ Item { Item { id: amountContainer_paymentSuccess; - visible: root.assetName === ""; + visible: root.assetCertID === ""; anchors.top: sendToContainer_paymentSuccess.bottom; anchors.topMargin: 16; anchors.left: parent.left; @@ -1513,7 +1534,7 @@ Item { RalewaySemiBold { id: optionalMessage_paymentSuccess; - visible: root.assetName === ""; + visible: root.assetCertID === ""; text: optionalMessage.text; // Anchors anchors.top: amountContainer_paymentSuccess.visible ? amountContainer_paymentSuccess.bottom : sendToContainer_paymentSuccess.bottom; @@ -1535,18 +1556,22 @@ Item { HifiControlsUit.Button { id: closeButton; color: hifi.buttons.blue; - colorScheme: root.assetName === "" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; + colorScheme: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; anchors.horizontalCenter: parent.horizontalCenter; anchors.bottom: parent.bottom; - anchors.bottomMargin: root.assetName === "" ? 80 : 30; + anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 80 : 30; height: 50; width: 120; text: "Close"; onClicked: { - root.nextActiveView = "sendAssetHome"; - resetSendAssetData(); - if (root.assetName !== "") { - sendSignalToParent({method: "closeSendAsset"}); + if (sendAssetStep.referrer === "payIn") { + sendToScript({method: "closeSendAsset"}); + } else { + root.nextActiveView = "sendAssetHome"; + resetSendAssetData(); + if (root.assetName !== "") { + sendSignalToParent({method: "closeSendAsset"}); + } } } } @@ -1574,18 +1599,18 @@ Item { Rectangle { anchors.top: parent.top; - anchors.topMargin: root.assetName === "" ? 15 : 150; + anchors.topMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 150; anchors.left: parent.left; - anchors.leftMargin: root.assetName === "" ? 15 : 50; + anchors.leftMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; anchors.right: parent.right; - anchors.rightMargin: root.assetName === "" ? 15 : 50; + anchors.rightMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 50; anchors.bottom: parent.bottom; - anchors.bottomMargin: root.assetName === "" ? 15 : 300; + anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 15 : 300; color: "#FFFFFF"; RalewaySemiBold { id: paymentFailureText; - text: root.assetName === "" ? "Payment Failed" : "Failed"; + text: root.assetCertID === "" && sendAssetStep.referrer !== "payIn" ? "Payment Failed" : "Failed"; // Anchors anchors.top: parent.top; anchors.topMargin: 26; @@ -1603,7 +1628,7 @@ Item { HiFiGlyphs { id: closeGlyphButton_paymentFailure; - visible: root.assetName === ""; + visible: root.assetCertID === "" && sendAssetStep.referrer !== "payIn"; text: hifi.glyphs.close; color: hifi.colors.lightGrayText; size: 26; @@ -1632,7 +1657,8 @@ Item { RalewaySemiBold { id: paymentFailureDetailText; - text: "The recipient you specified was unable to receive your " + (root.assetName === "" ? "payment." : "gift."); + text: "The recipient you specified was unable to receive your " + + (root.assetCertID === "" ? "payment." : (sendAssetStep.referrer === "payIn" ? "item." : "gift.")); anchors.top: paymentFailureText.bottom; anchors.topMargin: 20; anchors.left: parent.left; @@ -1650,7 +1676,7 @@ Item { Item { id: sendToContainer_paymentFailure; - visible: root.assetName === ""; + visible: root.assetCertID === "" || sendAssetStep.referrer === "payIn"; anchors.top: paymentFailureDetailText.bottom; anchors.topMargin: 8; anchors.left: parent.left; @@ -1685,13 +1711,13 @@ Item { userName: sendAssetStep.selectedRecipientUserName; profilePic: sendAssetStep.selectedRecipientProfilePic !== "" ? ((0 === sendAssetStep.selectedRecipientProfilePic.indexOf("http")) ? sendAssetStep.selectedRecipientProfilePic : (Account.metaverseServerURL + sendAssetStep.selectedRecipientProfilePic)) : ""; - isDisplayingNearby: sendAssetStep.referrer === "nearby"; + multiLineDisplay: sendAssetStep.referrer === "nearby" || sendAssetStep.referrer === "payIn"; } } Item { id: amountContainer_paymentFailure; - visible: root.assetName === ""; + visible: root.assetCertID === ""; anchors.top: sendToContainer_paymentFailure.bottom; anchors.topMargin: 16; anchors.left: parent.left; @@ -1746,7 +1772,7 @@ Item { RalewaySemiBold { id: optionalMessage_paymentFailure; - visible: root.assetName === ""; + visible: root.assetCertID === "" || sendAssetStep.referrer === "payIn"; text: optionalMessage.text; // Anchors anchors.top: amountContainer_paymentFailure.visible ? amountContainer_paymentFailure.bottom : sendToContainer_paymentFailure.bottom; @@ -1768,19 +1794,23 @@ Item { HifiControlsUit.Button { id: closeButton_paymentFailure; color: hifi.buttons.noneBorderless; - colorScheme: root.assetName === "" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; + colorScheme: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; anchors.right: retryButton_paymentFailure.left; anchors.rightMargin: 12; anchors.bottom: parent.bottom; - anchors.bottomMargin: root.assetName === "" ? 80 : 30; + anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 80 : 30; height: 50; width: 120; text: "Cancel"; onClicked: { - root.nextActiveView = "sendAssetHome"; - resetSendAssetData(); - if (root.assetName !== "") { - sendSignalToParent({method: "closeSendAsset"}); + if (sendAssetStep.referrer === "payIn") { + sendToScript({method: "closeSendAsset"}); + } else { + root.nextActiveView = "sendAssetHome"; + resetSendAssetData(); + if (root.assetName !== "") { + sendSignalToParent({method: "closeSendAsset"}); + } } } } @@ -1789,17 +1819,17 @@ Item { HifiControlsUit.Button { id: retryButton_paymentFailure; color: hifi.buttons.blue; - colorScheme: root.assetName === "" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; + colorScheme: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? hifi.colorSchemes.dark : hifi.colorSchemes.light; anchors.right: parent.right; anchors.rightMargin: 12; anchors.bottom: parent.bottom; - anchors.bottomMargin: root.assetName === "" ? 80 : 30; + anchors.bottomMargin: root.assetCertID === "" || sendAssetStep.referrer === "payIn" ? 80 : 30; height: 50; width: 120; text: "Retry"; onClicked: { root.isCurrentlySendingAsset = true; - if (sendAssetStep.referrer === "connections") { + if (sendAssetStep.referrer === "connections" || sendAssetStep.referrer === "payIn") { Commerce.transferAssetToUsername(sendAssetStep.selectedRecipientUserName, root.assetCertID, parseInt(amountTextField.text), @@ -1866,11 +1896,32 @@ Item { case 'updateSelectedRecipientUsername': sendAssetStep.selectedRecipientUserName = message.userName; break; + case 'updateSendAssetQML': + root.assetName = ""; + root.assetCertID = message.assetCertID || ""; + if (root.assetCertID === "") { + amountTextField.text = message.amount || 1; + } else { + amountTextField.text = ""; + Commerce.certificateInfo(root.assetCertID); + } + sendAssetStep.referrer = "payIn"; + sendAssetStep.selectedRecipientNodeID = ""; + sendAssetStep.selectedRecipientDisplayName = "Determined by script:"; + sendAssetStep.selectedRecipientUserName = message.username; + optionalMessage.text = message.message || "No Message Provided"; + + root.nextActiveView = "sendAssetStep"; + break; + case 'inspectionCertificate_resetCert': + // NOP + break; default: console.log('SendAsset: Unrecognized message from wallet.js'); } } signal sendSignalToParent(var msg); + signal sendToScript(var message); // // FUNCTION DEFINITIONS END // diff --git a/interface/resources/qml/hifi/dialogs/security/Security.qml b/interface/resources/qml/hifi/dialogs/security/Security.qml index b754cb06ab..5c52af1c05 100644 --- a/interface/resources/qml/hifi/dialogs/security/Security.qml +++ b/interface/resources/qml/hifi/dialogs/security/Security.qml @@ -256,7 +256,7 @@ Rectangle { color: hifi.colors.baseGrayHighlight; HifiStylesUit.RalewaySemiBold { - text: "Wallet"; + text: "Secure Transactions"; anchors.fill: parent; anchors.leftMargin: 20; color: hifi.colors.white; @@ -287,7 +287,7 @@ Rectangle { HifiStylesUit.RalewaySemiBold { id: securityPictureText; - text: "Wallet Security Picture"; + text: "Security Picture"; // Anchors anchors.top: parent.top; anchors.bottom: parent.bottom; diff --git a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml index e18fdea444..46817e07cf 100644 --- a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml +++ b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml @@ -207,12 +207,12 @@ Flickable { width: 112 label: "Y Offset" suffix: " cm" - minimumValue: -10 + minimumValue: -50 + maximumValue: 50 realStepSize: 1 - realValue: -5 colorScheme: hifi.colorSchemes.dark - onEditingFinished: { + onRealValueChanged: { sendConfigurationSettings(); openVrConfiguration.forceActiveFocus(); } @@ -223,14 +223,14 @@ Flickable { id: headZOffset width: 112 label: "Z Offset" - minimumValue: -10 + minimumValue: -50 + maximumValue: 50 realStepSize: 1 decimals: 1 suffix: " cm" - realValue: -5 colorScheme: hifi.colorSchemes.dark - onEditingFinished: { + onRealValueChanged: { sendConfigurationSettings(); openVrConfiguration.forceActiveFocus(); } @@ -319,11 +319,12 @@ Flickable { width: 112 suffix: " cm" label: "Y Offset" - minimumValue: -10 + minimumValue: -30 + maximumValue: 30 realStepSize: 1 colorScheme: hifi.colorSchemes.dark - onEditingFinished: { + onRealValueChanged: { sendConfigurationSettings(); openVrConfiguration.forceActiveFocus(); } @@ -335,12 +336,13 @@ Flickable { width: 112 label: "Z Offset" suffix: " cm" - minimumValue: -10 + minimumValue: -30 + maximumValue: 30 realStepSize: 1 decimals: 1 colorScheme: hifi.colorSchemes.dark - onEditingFinished: { + onRealValueChanged: { sendConfigurationSettings(); openVrConfiguration.forceActiveFocus(); } @@ -574,7 +576,7 @@ Flickable { colorScheme: hifi.colorSchemes.dark realValue: 33.0 - onEditingFinished: { + onRealValueChanged: { sendConfigurationSettings(); openVrConfiguration.forceActiveFocus(); } @@ -592,7 +594,7 @@ Flickable { colorScheme: hifi.colorSchemes.dark realValue: 48 - onEditingFinished: { + onRealValueChanged: { sendConfigurationSettings(); openVrConfiguration.forceActiveFocus(); } @@ -771,7 +773,7 @@ Flickable { realStepSize: 1.0 colorScheme: hifi.colorSchemes.dark - onEditingFinished: { + onRealValueChanged: { calibrationTimer.interval = realValue * 1000; openVrConfiguration.countDown = realValue; numberAnimation.duration = calibrationTimer.interval; @@ -977,6 +979,13 @@ Flickable { var configurationType = settings["trackerConfiguration"]; displayTrackerConfiguration(configurationType); + // default offset for user wearing puck on the center of their forehead. + headYOffset.realValue = 4; // (cm), puck is above the head joint. + headZOffset.realValue = 8; // (cm), puck is in front of the head joint. + + // defaults for user wearing the pucks on the backs of their palms. + handYOffset.realValue = 8; // (cm), puck is past the the hand joint. (set this to zero if puck is on the wrist) + handZOffset.realValue = -4; // (cm), puck is on above hand joint. var HmdHead = settings["HMDHead"]; var viveController = settings["handController"]; diff --git a/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml b/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml index b8972378ad..ab0a98a8c5 100644 --- a/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml +++ b/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml @@ -56,7 +56,7 @@ StackView { Qt.callLater(function() { addressBarDialog.keyboardEnabled = HMD.active; addressLine.forceActiveFocus(); - addressBarDialog.raised = true; + addressBarDialog.keyboardRaised = true; }) } diff --git a/interface/resources/qml/hifi/tablet/TabletHome.qml b/interface/resources/qml/hifi/tablet/TabletHome.qml index f1f54e8419..4d7883522e 100644 --- a/interface/resources/qml/hifi/tablet/TabletHome.qml +++ b/interface/resources/qml/hifi/tablet/TabletHome.qml @@ -61,7 +61,7 @@ Item { RalewaySemiBold { text: Account.loggedIn ? qsTr("Log out") : qsTr("Log in") horizontalAlignment: Text.AlignRight - anchors.right: parent.right + Layout.alignment: Qt.AlignRight font.pixelSize: 20 color: "#afafaf" } @@ -71,7 +71,7 @@ Item { height: Account.loggedIn ? parent.height/2 - parent.spacing/2 : 0 text: Account.loggedIn ? "[" + tabletRoot.usernameShort + "]" : "" horizontalAlignment: Text.AlignRight - anchors.right: parent.right + Layout.alignment: Qt.AlignRight font.pixelSize: 20 color: "#afafaf" } @@ -115,9 +115,9 @@ Item { property int previousIndex: -1 Repeater { id: pageRepeater - model: Math.ceil(tabletProxy.buttons.rowCount() / TabletEnums.ButtonsOnPage) + model: tabletProxy != null ? Math.ceil(tabletProxy.buttons.rowCount() / TabletEnums.ButtonsOnPage) : 0 onItemAdded: { - item.proxyModel.sourceModel = tabletProxy.buttons; + item.proxyModel.sourceModel = tabletProxy != null ? tabletProxy.buttons : null; item.proxyModel.pageIndex = index; } diff --git a/interface/resources/sounds/keyboardPress.mp3 b/interface/resources/sounds/keyboardPress.mp3 new file mode 100644 index 0000000000..e4cd21b971 Binary files /dev/null and b/interface/resources/sounds/keyboardPress.mp3 differ diff --git a/interface/resources/sounds/keyboard_key.mp3 b/interface/resources/sounds/keyboard_key.mp3 deleted file mode 100644 index e2cec81032..0000000000 Binary files a/interface/resources/sounds/keyboard_key.mp3 and /dev/null differ diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7a30b566e9..0b53e24a8e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -87,7 +87,6 @@ #include #include #include -#include #include #include #include @@ -122,8 +121,6 @@ #include #include #include -#include -#include #include #include #include @@ -264,54 +261,7 @@ extern "C" { #include "AndroidHelper.h" #endif -enum ApplicationEvent { - // Execute a lambda function - Lambda = QEvent::User + 1, - // Trigger the next render - Render, - // Trigger the next idle - Idle, -}; - -class RenderEventHandler : public QObject { - using Parent = QObject; - Q_OBJECT -public: - RenderEventHandler() { - // Transfer to a new thread - moveToNewNamedThread(this, "RenderThread", [](QThread* renderThread) { - hifi::qt::addBlockingForbiddenThread("Render", renderThread); - qApp->_lastTimeRendered.start(); - }, std::bind(&RenderEventHandler::initialize, this), QThread::HighestPriority); - } - -private: - void initialize() { - setObjectName("Render"); - PROFILE_SET_THREAD_NAME("Render"); - setCrashAnnotation("render_thread_id", std::to_string((size_t)QThread::currentThreadId())); - } - - void render() { - if (qApp->shouldPaint()) { - qApp->paintGL(); - } - } - - bool event(QEvent* event) override { - switch ((int)event->type()) { - case ApplicationEvent::Render: - render(); - qApp->_pendingRenderEvent.store(false); - return true; - - default: - break; - } - return Parent::event(event); - } -}; - +#include "graphics/RenderEventHandler.h" Q_LOGGING_CATEGORY(trace_app_input_mouse, "trace.app.input.mouse") @@ -371,8 +321,8 @@ static const QString INFO_HELP_PATH = "html/tabletHelp.html"; static const unsigned int THROTTLED_SIM_FRAMERATE = 15; static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE; - -static const uint32_t INVALID_FRAME = UINT32_MAX; +static const int ENTITY_SERVER_ADDED_TIMEOUT = 5000; +static const int ENTITY_SERVER_CONNECTION_TIMEOUT = 5000; static const float INITIAL_QUERY_RADIUS = 10.0f; // priority radius for entities before physics enabled @@ -925,7 +875,9 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { #endif DependencyManager::set(); DependencyManager::set(); +#if !defined(DISABLE_QML) DependencyManager::set(); +#endif DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -998,6 +950,14 @@ const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = false; const QString DEFAULT_CURSOR_NAME = "DEFAULT"; const bool DEFAULT_MINI_TABLET_ENABLED = true; +QSharedPointer getOffscreenUI() { +#if !defined(DISABLE_QML) + return DependencyManager::get(); +#else + return nullptr; +#endif +} + Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runningMarkerExisted) : QApplication(argc, argv), _window(new MainWindow(desktop())), @@ -1229,6 +1189,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo getOverlays().deleteOverlay(getTabletScreenID()); getOverlays().deleteOverlay(getTabletHomeButtonID()); getOverlays().deleteOverlay(getTabletFrameID()); + _failedToConnectToEntityServer = false; + }); + + _entityServerConnectionTimer.setSingleShot(true); + connect(&_entityServerConnectionTimer, &QTimer::timeout, this, &Application::setFailedToConnectToEntityServer); + + connect(&domainHandler, &DomainHandler::connectedToDomain, this, [this]() { + if (!isServerlessMode()) { + _entityServerConnectionTimer.setInterval(ENTITY_SERVER_ADDED_TIMEOUT); + _entityServerConnectionTimer.start(); + _failedToConnectToEntityServer = false; + } }); connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &Application::domainConnectionRefused); @@ -1590,7 +1562,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo auto userInputMapper = DependencyManager::get(); connect(userInputMapper.data(), &UserInputMapper::actionEvent, [this](int action, float state) { using namespace controller; - auto offscreenUi = DependencyManager::get(); auto tabletScriptingInterface = DependencyManager::get(); { auto actionEnum = static_cast(action); @@ -1729,7 +1700,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0; }); _applicationStateDevice->setInputVariant(STATE_NAV_FOCUSED, []() -> float { - return DependencyManager::get()->navigationFocused() ? 1 : 0; + auto offscreenUi = getOffscreenUI(); + return offscreenUi ? (offscreenUi->navigationFocused() ? 1 : 0) : 0; }); _applicationStateDevice->setInputVariant(STATE_PLATFORM_WINDOWS, []() -> float { #if defined(Q_OS_WIN) @@ -1795,9 +1767,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo // Now that we've loaded the menu and thus switched to the previous display plugin // we can unlock the desktop repositioning code, since all the positions will be // relative to the desktop size for this plugin - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); connect(offscreenUi.data(), &OffscreenUi::desktopReady, []() { - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); auto desktop = offscreenUi->getDesktop(); if (desktop) { desktop->setProperty("repositionLocked", false); @@ -2036,7 +2008,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo auto displayPlugin = qApp->getActiveDisplayPlugin(); - properties["render_rate"] = _renderLoopCounter.rate(); + properties["render_rate"] = getRenderLoopRate(); properties["target_render_rate"] = getTargetRenderFrameRate(); properties["present_rate"] = displayPlugin->presentRate(); properties["new_frame_present_rate"] = displayPlugin->newFramePresentRate(); @@ -2348,7 +2320,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo DependencyManager::get()->createKeyboard(); _pendingIdleEvent = false; - _pendingRenderEvent = false; + _graphicsEngine.startup(); qCDebug(interfaceapp) << "Metaverse session ID is" << uuidStringWithoutCurlyBraces(accountManager->getSessionID()); @@ -2358,6 +2330,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(&AndroidHelper::instance(), &AndroidHelper::enterForeground, this, &Application::enterForeground); AndroidHelper::instance().notifyLoadComplete(); #else +#if !defined(DISABLE_QML) // Do not show login dialog if requested not to on the command line const QString HIFI_NO_LOGIN_COMMAND_LINE_KEY = "--no-login-suggestion"; int index = arguments().indexOf(HIFI_NO_LOGIN_COMMAND_LINE_KEY); @@ -2382,6 +2355,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo checkLoginTimer->start(); } #endif +#endif } void Application::updateVerboseLogging() { @@ -2532,7 +2506,9 @@ void Application::onAboutToQuit() { DependencyManager::get()->startThread(); // Hide Running Scripts dialog so that it gets destroyed in an orderly manner; prevents warnings at shutdown. - DependencyManager::get()->hide("RunningScripts"); +#if !defined(DISABLE_QML) + getOffscreenUI()->hide("RunningScripts"); +#endif _aboutToQuit = true; @@ -2544,6 +2520,8 @@ void Application::cleanupBeforeQuit() { QString webengineRemoteDebugging = QProcessEnvironment::systemEnvironment().value("QTWEBENGINE_REMOTE_DEBUGGING", "false"); qCDebug(interfaceapp) << "QTWEBENGINE_REMOTE_DEBUGGING =" << webengineRemoteDebugging; + DependencyManager::prepareToExit(); + if (tracing::enabled()) { auto tracer = DependencyManager::get(); tracer->stopTracing(); @@ -2612,11 +2590,6 @@ void Application::cleanupBeforeQuit() { // Cleanup all overlays after the scripts, as scripts might add more _overlays.cleanupAllOverlays(); - // The cleanup process enqueues the transactions but does not process them. Calling this here will force the actual - // removal of the items. - // See https://highfidelity.fogbugz.com/f/cases/5328 - _main3DScene->enqueueFrame(); // flush all the transactions - _main3DScene->processTransactionQueue(); // process and apply deletions // first stop all timers directly or by invokeMethod // depending on what thread they run in @@ -2631,7 +2604,6 @@ void Application::cleanupBeforeQuit() { } _window->saveGeometry(); - _gpuContext->shutdown(); // Destroy third party processes after scripts have finished using them. #ifdef HAVE_DDE @@ -2656,6 +2628,7 @@ void Application::cleanupBeforeQuit() { // destroy Audio so it and its threads have a chance to go down safely // this must happen after QML, as there are unexplained audio crashes originating in qtwebengine + QMetaObject::invokeMethod(DependencyManager::get().data(), "stop"); DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); @@ -2688,10 +2661,9 @@ Application::~Application() { _shapeManager.collectGarbage(); assert(_shapeManager.getNumShapes() == 0); - // shutdown render engine - _main3DScene = nullptr; - _renderEngine = nullptr; - + // shutdown graphics engine + _graphicsEngine.shutdown(); + _gameWorkload.shutdown(); DependencyManager::destroy(); @@ -2747,10 +2719,8 @@ Application::~Application() { // quit the thread used by the closure event sender closeEventSender->thread()->quit(); - // Can't log to file passed this point, FileLogger about to be deleted + // Can't log to file past this point, FileLogger about to be deleted qInstallMessageHandler(LogHandler::verboseMessageHandler); - - _renderEventHandler->deleteLater(); } void Application::initializeGL() { @@ -2770,10 +2740,10 @@ void Application::initializeGL() { _glWidget->windowHandle()->setFormat(getDefaultOpenGLSurfaceFormat()); // When loading QtWebEngineWidgets, it creates a global share context on startup. - // We have to account for this possibility by checking here for an existing + // We have to account for this possibility by checking here for an existing // global share context auto globalShareContext = qt_gl_global_share_context(); - + #if !defined(DISABLE_QML) // Build a shared canvas / context for the Chromium processes if (!globalShareContext) { @@ -2840,26 +2810,13 @@ void Application::initializeGL() { #endif - _renderEventHandler = new RenderEventHandler(); - // Build an offscreen GL context for the main thread. _glWidget->makeCurrent(); glClearColor(0.2f, 0.2f, 0.2f, 1); glClear(GL_COLOR_BUFFER_BIT); _glWidget->swapBuffers(); - - // Create the GPU backend - - // Requires the window context, because that's what's used in the actual rendering - // and the GPU backend will make things like the VAO which cannot be shared across - // contexts - _glWidget->makeCurrent(); - gpu::Context::init(); - _glWidget->makeCurrent(); - _gpuContext = std::make_shared(); - - DependencyManager::get()->setGPUContext(_gpuContext); + _graphicsEngine.initializeGPU(_glWidget); } static const QString SPLASH_SKYBOX{ "{\"ProceduralEntity\":{ \"version\":2, \"shaderUrl\":\"qrc:///shaders/splashSkybox.frag\" } }" }; @@ -2873,7 +2830,7 @@ void Application::initializeDisplayPlugins() { // Once time initialization code DisplayPluginPointer targetDisplayPlugin; foreach(auto displayPlugin, displayPlugins) { - displayPlugin->setContext(_gpuContext); + displayPlugin->setContext(_graphicsEngine.getGPUContext()); if (displayPlugin->getName() == lastActiveDisplayPluginName) { targetDisplayPlugin = displayPlugin; } @@ -2943,24 +2900,15 @@ void Application::initializeDisplayPlugins() { void Application::initializeRenderEngine() { // FIXME: on low end systems os the shaders take up to 1 minute to compile, so we pause the deadlock watchdog thread. DeadlockWatchdogThread::withPause([&] { - // Set up the render engine - render::CullFunctor cullFunctor = LODManager::shouldRender; - _renderEngine->addJob("UpdateScene"); -#ifndef Q_OS_ANDROID - _renderEngine->addJob("SecondaryCameraJob", cullFunctor, !DISABLE_DEFERRED); -#endif - _renderEngine->addJob("RenderMainView", cullFunctor, !DISABLE_DEFERRED, render::ItemKey::TAG_BITS_0, render::ItemKey::TAG_BITS_0); - _renderEngine->load(); - _renderEngine->registerScene(_main3DScene); - - // Now that OpenGL is initialized, we are sure we have a valid context and can create the various pipeline shaders with success. - DependencyManager::get()->initializeShapePipelines(); + _graphicsEngine.initializeRender(DISABLE_DEFERRED); DependencyManager::get()->registerKeyboardHighlighting(); }); } extern void setupPreferences(); +#if !defined(DISABLE_QML) static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, int index, bool active = false); +#endif void Application::initializeUi() { AddressBarDialog::registerType(); @@ -3010,12 +2958,13 @@ void Application::initializeUi() { tabletScriptingInterface->getTablet(SYSTEM_TABLET); } - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); connect(offscreenUi.data(), &hifi::qml::OffscreenSurface::rootContextCreated, this, &Application::onDesktopRootContextCreated); connect(offscreenUi.data(), &hifi::qml::OffscreenSurface::rootItemCreated, this, &Application::onDesktopRootItemCreated); +#if !defined(DISABLE_QML) offscreenUi->setProxyWindow(_window->windowHandle()); // OffscreenUi is a subclass of OffscreenQmlSurface specifically designed to // support the window management and scripting proxies for VR use @@ -3025,9 +2974,13 @@ void Application::initializeUi() { // FIXME either expose so that dialogs can set this themselves or // do better detection in the offscreen UI of what has focus offscreenUi->setNavigationFocused(false); +#else + _window->setMenuBar(new Menu()); +#endif setupPreferences(); +#if !defined(DISABLE_QML) _glWidget->installEventFilter(offscreenUi.data()); offscreenUi->setMouseTranslator([=](const QPointF& pt) { QPointF result = pt; @@ -3040,6 +2993,7 @@ void Application::initializeUi() { return result.toPoint(); }); offscreenUi->resume(); +#endif connect(_window, &MainWindow::windowGeometryChanged, [this](const QRect& r){ resizeGL(); if (_touchscreenVirtualPadDevice) { @@ -3078,6 +3032,7 @@ void Application::initializeUi() { } }); +#if !defined(DISABLE_QML) // Pre-create a couple of Web3D overlays to speed up tablet UI auto offscreenSurfaceCache = DependencyManager::get(); offscreenSurfaceCache->setOnRootContextCreated([&](const QString& rootObject, QQmlContext* surfaceContext) { @@ -3091,9 +3046,11 @@ void Application::initializeUi() { offscreenSurfaceCache->reserve(TabletScriptingInterface::QML, 1); offscreenSurfaceCache->reserve(Web3DOverlay::QML, 2); +#endif flushMenuUpdates(); +#if !defined(DISABLE_QML) // Now that the menu is instantiated, ensure the display plugin menu is properly updated { auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins(); @@ -3112,6 +3069,7 @@ void Application::initializeUi() { auto parent = getPrimaryMenu()->getMenu(MenuOption::OutputMenu); parent->addSeparator(); } +#endif // The display plugins are created before the menu now, so we need to do this here to hide the menu bar // now that it exists @@ -3143,7 +3101,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { surfaceContext->setContextProperty("Recording", DependencyManager::get().data()); surfaceContext->setContextProperty("Preferences", DependencyManager::get().data()); surfaceContext->setContextProperty("AddressManager", DependencyManager::get().data()); - surfaceContext->setContextProperty("FrameTimings", &_frameTimingsScriptingInterface); + surfaceContext->setContextProperty("FrameTimings", &_graphicsEngine._frameTimingsScriptingInterface); surfaceContext->setContextProperty("Rates", new RatesScriptingInterface(this)); surfaceContext->setContextProperty("TREE_SCALE", TREE_SCALE); @@ -3192,7 +3150,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { surfaceContext->setContextProperty("LODManager", DependencyManager::get().data()); surfaceContext->setContextProperty("HMD", DependencyManager::get().data()); surfaceContext->setContextProperty("Scene", DependencyManager::get().data()); - surfaceContext->setContextProperty("Render", _renderEngine->getConfiguration().get()); + surfaceContext->setContextProperty("Render", _graphicsEngine.getRenderEngine()->getConfiguration().get()); surfaceContext->setContextProperty("Workload", _gameWorkload._engine->getConfiguration().get()); surfaceContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface()); surfaceContext->setContextProperty("Snapshot", DependencyManager::get().data()); @@ -3216,12 +3174,12 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { void Application::onDesktopRootItemCreated(QQuickItem* rootItem) { Stats::show(); AnimStats::show(); - auto surfaceContext = DependencyManager::get()->getSurfaceContext(); + auto surfaceContext = getOffscreenUI()->getSurfaceContext(); surfaceContext->setContextProperty("Stats", Stats::getInstance()); surfaceContext->setContextProperty("AnimStats", AnimStats::getInstance()); #if !defined(Q_OS_ANDROID) - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); auto qml = PathUtils::qmlUrl("AvatarInputsBar.qml"); offscreenUi->show(qml, "AvatarInputsBar"); #endif @@ -3404,7 +3362,7 @@ void Application::setPreferredCursor(const QString& cursorName) { void Application::setSettingConstrainToolbarPosition(bool setting) { _constrainToolbarPosition.set(setting); - DependencyManager::get()->setConstrainToolbarToCenterX(setting); + getOffscreenUI()->setConstrainToolbarToCenterX(setting); } void Application::setMiniTabletEnabled(bool enabled) { @@ -3417,26 +3375,37 @@ void Application::showHelp() { static const QString HAND_CONTROLLER_NAME_OCULUS_TOUCH = "oculus"; static const QString HAND_CONTROLLER_NAME_WINDOWS_MR = "windowsMR"; + static const QString VIVE_PLUGIN_NAME = "HTC Vive"; + static const QString OCULUS_RIFT_PLUGIN_NAME = "Oculus Rift"; + static const QString WINDOWS_MR_PLUGIN_NAME = "WindowsMR"; + static const QString TAB_KEYBOARD_MOUSE = "kbm"; static const QString TAB_GAMEPAD = "gamepad"; static const QString TAB_HAND_CONTROLLERS = "handControllers"; - QString handControllerName = HAND_CONTROLLER_NAME_VIVE; + QString handControllerName; QString defaultTab = TAB_KEYBOARD_MOUSE; - if (PluginUtils::isViveControllerAvailable()) { - defaultTab = TAB_HAND_CONTROLLERS; - handControllerName = HAND_CONTROLLER_NAME_VIVE; - } else if (PluginUtils::isOculusTouchControllerAvailable()) { - defaultTab = TAB_HAND_CONTROLLERS; - handControllerName = HAND_CONTROLLER_NAME_OCULUS_TOUCH; - } else if (qApp->getActiveDisplayPlugin()->getName() == "WindowMS") { + if (PluginUtils::isHMDAvailable(WINDOWS_MR_PLUGIN_NAME)) { defaultTab = TAB_HAND_CONTROLLERS; handControllerName = HAND_CONTROLLER_NAME_WINDOWS_MR; + } else if (PluginUtils::isHMDAvailable(VIVE_PLUGIN_NAME)) { + defaultTab = TAB_HAND_CONTROLLERS; + handControllerName = HAND_CONTROLLER_NAME_VIVE; + } else if (PluginUtils::isHMDAvailable(OCULUS_RIFT_PLUGIN_NAME)) { + if (PluginUtils::isOculusTouchControllerAvailable()) { + defaultTab = TAB_HAND_CONTROLLERS; + handControllerName = HAND_CONTROLLER_NAME_OCULUS_TOUCH; + } else if (PluginUtils::isXboxControllerAvailable()) { + defaultTab = TAB_GAMEPAD; + } else { + defaultTab = TAB_KEYBOARD_MOUSE; + } } else if (PluginUtils::isXboxControllerAvailable()) { defaultTab = TAB_GAMEPAD; + } else { + defaultTab = TAB_KEYBOARD_MOUSE; } - // TODO need some way to detect windowsMR to load controls reference default tab in Help > Controls Reference menu. QUrlQuery queryString; queryString.addQueryItem("handControllerName", handControllerName); @@ -3469,7 +3438,7 @@ void Application::resizeGL() { auto renderResolutionScale = getRenderResolutionScale(); if (displayPlugin->getRenderResolutionScale() != renderResolutionScale) { - auto renderConfig = _renderEngine->getConfiguration(); + auto renderConfig = _graphicsEngine.getRenderEngine()->getConfiguration(); assert(renderConfig); auto mainView = renderConfig->getConfig("RenderMainView.RenderDeferredTask"); assert(mainView); @@ -3487,7 +3456,9 @@ void Application::resizeGL() { _myCamera.loadViewFrustum(_viewFrustum); } - DependencyManager::get()->resize(fromGlm(displayPlugin->getRecommendedUiSize())); +#if !defined(DISABLE_QML) + getOffscreenUI()->resize(fromGlm(displayPlugin->getRecommendedUiSize())); +#endif } void Application::handleSandboxStatus(QNetworkReply* reply) { @@ -3698,8 +3669,8 @@ void Application::onPresent(quint32 frameCount) { postEvent(this, new QEvent((QEvent::Type)ApplicationEvent::Idle), Qt::HighEventPriority); } expected = false; - if (_renderEventHandler && !isAboutToQuit() && _pendingRenderEvent.compare_exchange_strong(expected, true)) { - postEvent(_renderEventHandler, new QEvent((QEvent::Type)ApplicationEvent::Render)); + if (_graphicsEngine.checkPendingRenderEvent() && !isAboutToQuit()) { + postEvent(_graphicsEngine._renderEventHandler, new QEvent((QEvent::Type)ApplicationEvent::Render)); } } @@ -3887,10 +3858,12 @@ bool Application::eventFilter(QObject* object, QEvent* event) { } if (event->type() == QEvent::ShortcutOverride) { - if (DependencyManager::get()->shouldSwallowShortcut(event)) { +#if !defined(DISABLE_QML) + if (getOffscreenUI()->shouldSwallowShortcut(event)) { event->accept(); return true; } +#endif // Filter out captured keys before they're used for shortcut actions. if (_controllerScriptingInterface->isKeyCaptured(static_cast(event))) { @@ -3973,7 +3946,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_X: if (isShifted && isMeta) { - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); offscreenUi->togglePinned(); //offscreenUi->getSurfaceContext()->engine()->clearComponentCache(); //OffscreenUi::information("Debugging", "Component cache cleared"); @@ -3989,7 +3962,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_B: if (isMeta) { - auto offscreenUi = DependencyManager::get(); + auto offscreenUi = getOffscreenUI(); offscreenUi->load("Browser.qml"); } else if (isOption) { controller::InputRecorder* inputRecorder = controller::InputRecorder::getInstance(); @@ -4011,7 +3984,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_R: if (isMeta && !event->isAutoRepeat()) { DependencyManager::get()->reloadAllScripts(); - DependencyManager::get()->clearCache(); + getOffscreenUI()->clearCache(); } break; @@ -4208,9 +4181,13 @@ void Application::mouseMoveEvent(QMouseEvent* event) { return; // bail } - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); auto eventPosition = compositor.getMouseEventPosition(event); - QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); + QPointF transformedPos = offscreenUi ? offscreenUi->mapToVirtualScreen(eventPosition) : QPointF(); +#else + QPointF transformedPos; +#endif auto button = event->button(); auto buttons = event->buttons(); // Determine if the ReticleClick Action is 1 and if so, fake include the LeftMouseButton @@ -4248,7 +4225,8 @@ void Application::mousePressEvent(QMouseEvent* event) { // Inhibit the menu if the user is using alt-mouse dragging _altPressed = false; - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); // If we get a mouse press event it means it wasn't consumed by the offscreen UI, // hence, we should defocus all of the offscreen UI windows, in order to allow // keyboard shortcuts not to be swallowed by them. In particular, WebEngineViews @@ -4257,6 +4235,9 @@ void Application::mousePressEvent(QMouseEvent* event) { auto eventPosition = getApplicationCompositor().getMouseEventPosition(event); QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); +#else + QPointF transformedPos; +#endif QMouseEvent mappedEvent(event->type(), transformedPos, event->screenPos(), event->button(), @@ -4293,9 +4274,13 @@ void Application::mousePressEvent(QMouseEvent* event) { } void Application::mouseDoublePressEvent(QMouseEvent* event) { - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); auto eventPosition = getApplicationCompositor().getMouseEventPosition(event); QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); +#else + QPointF transformedPos; +#endif QMouseEvent mappedEvent(event->type(), transformedPos, event->screenPos(), event->button(), @@ -4316,9 +4301,13 @@ void Application::mouseDoublePressEvent(QMouseEvent* event) { void Application::mouseReleaseEvent(QMouseEvent* event) { - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); auto eventPosition = getApplicationCompositor().getMouseEventPosition(event); QPointF transformedPos = offscreenUi->mapToVirtualScreen(eventPosition); +#else + QPointF transformedPos; +#endif QMouseEvent mappedEvent(event->type(), transformedPos, event->screenPos(), event->button(), @@ -4469,39 +4458,6 @@ bool Application::acceptSnapshot(const QString& urlString) { return true; } -static uint32_t _renderedFrameIndex { INVALID_FRAME }; - -bool Application::shouldPaint() const { - if (_aboutToQuit || _window->isMinimized()) { - return false; - } - - auto displayPlugin = getActiveDisplayPlugin(); - -#ifdef DEBUG_PAINT_DELAY - static uint64_t paintDelaySamples{ 0 }; - static uint64_t paintDelayUsecs{ 0 }; - - paintDelayUsecs += displayPlugin->getPaintDelayUsecs(); - - static const int PAINT_DELAY_THROTTLE = 1000; - if (++paintDelaySamples % PAINT_DELAY_THROTTLE == 0) { - qCDebug(interfaceapp).nospace() << - "Paint delay (" << paintDelaySamples << " samples): " << - (float)paintDelaySamples / paintDelayUsecs << "us"; - } -#endif - - // Throttle if requested - if (displayPlugin->isThrottled() && (_lastTimeRendered.elapsed() < THROTTLED_SIM_FRAME_PERIOD_MS)) { - return false; - } - - // Sync up the _renderedFrameIndex - _renderedFrameIndex = displayPlugin->presentCount(); - return true; -} - #ifdef Q_OS_WIN #include #include @@ -4714,7 +4670,8 @@ void Application::idle() { // Update the deadlock watchdog updateHeartbeat(); - auto offscreenUi = DependencyManager::get(); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); // These tasks need to be done on our first idle, because we don't want the showing of // overlay subwindows to do a showDesktop() until after the first time through @@ -4723,6 +4680,7 @@ void Application::idle() { firstIdle = false; connect(offscreenUi.data(), &OffscreenUi::showDesktop, this, &Application::showDesktop); } +#endif #ifdef Q_OS_WIN // If tracing is enabled then monitor the CPU in a separate thread @@ -4739,6 +4697,7 @@ void Application::idle() { #endif auto displayPlugin = getActiveDisplayPlugin(); +#if !defined(DISABLE_QML) if (displayPlugin) { auto uiSize = displayPlugin->getRecommendedUiSize(); // Bit of a hack since there's no device pixel ratio change event I can find. @@ -4747,30 +4706,18 @@ void Application::idle() { offscreenUi->resize(fromGlm(uiSize)); } } +#endif if (displayPlugin) { PROFILE_COUNTER_IF_CHANGED(app, "present", float, displayPlugin->presentRate()); } - PROFILE_COUNTER_IF_CHANGED(app, "renderLoopRate", float, _renderLoopCounter.rate()); - PROFILE_COUNTER_IF_CHANGED(app, "currentDownloads", uint32_t, ResourceCache::getLoadingRequestCount()); + PROFILE_COUNTER_IF_CHANGED(app, "renderLoopRate", float, getRenderLoopRate()); + PROFILE_COUNTER_IF_CHANGED(app, "currentDownloads", uint32_t, ResourceCache::getLoadingRequests().length()); PROFILE_COUNTER_IF_CHANGED(app, "pendingDownloads", uint32_t, ResourceCache::getPendingRequestCount()); PROFILE_COUNTER_IF_CHANGED(app, "currentProcessing", int, DependencyManager::get()->getStat("Processing").toInt()); PROFILE_COUNTER_IF_CHANGED(app, "pendingProcessing", int, DependencyManager::get()->getStat("PendingProcessing").toInt()); - auto renderConfig = _renderEngine->getConfiguration(); - PROFILE_COUNTER_IF_CHANGED(render, "gpuTime", float, (float)_gpuContext->getFrameTimerGPUAverage()); - auto opaqueRangeTimer = renderConfig->getConfig("OpaqueRangeTimer"); - auto linearDepth = renderConfig->getConfig("LinearDepth"); - auto surfaceGeometry = renderConfig->getConfig("SurfaceGeometry"); - auto renderDeferred = renderConfig->getConfig("RenderDeferred"); - auto toneAndPostRangeTimer = renderConfig->getConfig("ToneAndPostRangeTimer"); - - PROFILE_COUNTER(render_detail, "gpuTimes", { - { "OpaqueRangeTimer", opaqueRangeTimer ? opaqueRangeTimer->property("gpuRunTime") : 0 }, - { "LinearDepth", linearDepth ? linearDepth->property("gpuRunTime") : 0 }, - { "SurfaceGeometry", surfaceGeometry ? surfaceGeometry->property("gpuRunTime") : 0 }, - { "RenderDeferred", renderDeferred ? renderDeferred->property("gpuRunTime") : 0 }, - { "ToneAndPostRangeTimer", toneAndPostRangeTimer ? toneAndPostRangeTimer->property("gpuRunTime") : 0 } - }); + auto renderConfig = _graphicsEngine.getRenderEngine()->getConfiguration(); + PROFILE_COUNTER_IF_CHANGED(render, "gpuTime", float, (float)_graphicsEngine.getGPUContext()->getFrameTimerGPUAverage()); PROFILE_RANGE(app, __FUNCTION__); @@ -4781,6 +4728,7 @@ void Application::idle() { float secondsSinceLastUpdate = (float)_lastTimeUpdated.nsecsElapsed() / NSECS_PER_MSEC / MSECS_PER_SECOND; _lastTimeUpdated.start(); +#if !defined(DISABLE_QML) // If the offscreen Ui has something active that is NOT the root, then assume it has keyboard focus. if (offscreenUi && offscreenUi->getWindow()) { auto activeFocusItem = offscreenUi->getWindow()->activeFocusItem(); @@ -4792,9 +4740,11 @@ void Application::idle() { _keyboardDeviceHasFocus = true; } } +#endif checkChangeCursor(); +#if !defined(DISABLE_QML) auto stats = Stats::getInstance(); if (stats) { stats->updateStats(); @@ -4803,6 +4753,7 @@ void Application::idle() { if (animStats) { animStats->updateStats(); } +#endif // Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing // details if we're in ExtraDebugging mode. However, the ::update() and its subcomponents will show their timing @@ -5138,10 +5089,9 @@ QVector Application::pasteEntities(float x, float y, float z) { void Application::init() { // Make sure Login state is up to date +#if !defined(DISABLE_QML) DependencyManager::get()->toggleLoginDialog(); - if (!DISABLE_DEFERRED) { - DependencyManager::get()->init(); - } +#endif DependencyManager::get()->init(); _timerStart.start(); @@ -5210,7 +5160,7 @@ void Application::init() { } }, Qt::QueuedConnection); - _gameWorkload.startup(getEntities()->getWorkloadSpace(), _main3DScene, _entitySimulation); + _gameWorkload.startup(getEntities()->getWorkloadSpace(), _graphicsEngine.getRenderScene(), _entitySimulation); _entitySimulation->setWorkloadSpace(getEntities()->getWorkloadSpace()); } @@ -5244,7 +5194,7 @@ void Application::updateLOD(float deltaTime) const { // adjust it unless we were asked to disable this feature, or if we're currently in throttleRendering mode if (!isThrottleRendering()) { float presentTime = getActiveDisplayPlugin()->getAveragePresentTime(); - float engineRunTime = (float)(_renderEngine->getConfiguration().get()->getCPURunTime()); + float engineRunTime = (float)(_graphicsEngine.getRenderEngine()->getConfiguration().get()->getCPURunTime()); float gpuTime = getGPUContext()->getFrameTimerGPUAverage(); float batchTime = getGPUContext()->getFrameTimerBatchAverage(); auto lodManager = DependencyManager::get(); @@ -5645,7 +5595,7 @@ void Application::updateSecondaryCameraViewFrustum() { // camera should be. // Code based on SecondaryCameraJob - auto renderConfig = _renderEngine->getConfiguration(); + auto renderConfig = _graphicsEngine.getRenderEngine()->getConfiguration(); assert(renderConfig); auto camera = dynamic_cast(renderConfig->getConfig("SecondaryCamera")); @@ -5714,7 +5664,7 @@ void Application::updateSecondaryCameraViewFrustum() { static bool domainLoadingInProgress = false; void Application::update(float deltaTime) { - PROFILE_RANGE_EX(app, __FUNCTION__, 0xffff0000, (uint64_t)_renderFrameCount + 1); + PROFILE_RANGE_EX(app, __FUNCTION__, 0xffff0000, (uint64_t)_graphicsEngine._renderFrameCount + 1); if (_aboutToQuit) { return; @@ -5732,6 +5682,7 @@ void Application::update(float deltaTime) { quint64 now = usecTimestampNow(); if (isServerlessMode() || _octreeProcessor.isLoadSequenceComplete()) { bool enableInterstitial = DependencyManager::get()->getDomainHandler().getInterstitialModeEnabled(); + if (gpuTextureMemSizeStable() || !enableInterstitial) { // we've received a new full-scene octree stats packet, or it's been long enough to try again anyway _lastPhysicsCheckTime = now; @@ -6129,7 +6080,7 @@ void Application::update(float deltaTime) { // TODO: Fix this by modeling the way the secondary camera works on how the main camera works // ie. Use a camera object stored in the game logic and informs the Engine on where the secondary // camera should be. - updateSecondaryCameraViewFrustum(); + // updateSecondaryCameraViewFrustum(); } quint64 now = usecTimestampNow(); @@ -6205,13 +6156,6 @@ void Application::update(float deltaTime) { updateRenderArgs(deltaTime); - // HACK - // load the view frustum - // FIXME: This preDisplayRender call is temporary until we create a separate render::scene for the mirror rendering. - // Then we can move this logic into the Avatar::simulate call. - myAvatar->preDisplaySide(&_appRenderArgs._renderArgs); - - { PerformanceTimer perfTimer("AnimDebugDraw"); AnimDebugDraw::getInstance().update(); @@ -6222,10 +6166,15 @@ void Application::update(float deltaTime) { PerformanceTimer perfTimer("enqueueFrame"); getMain3DScene()->enqueueFrame(); } + + // If the display plugin is inactive then the frames won't be processed so process them here. + if (!getActiveDisplayPlugin()->isActive()) { + getMain3DScene()->processTransactionQueue(); + } } void Application::updateRenderArgs(float deltaTime) { - editRenderArgs([this, deltaTime](AppRenderArgs& appRenderArgs) { + _graphicsEngine.editRenderArgs([this, deltaTime](AppRenderArgs& appRenderArgs) { PerformanceTimer perfTimer("editRenderArgs"); appRenderArgs._headPose = getHMDSensorPose(); @@ -6254,7 +6203,7 @@ void Application::updateRenderArgs(float deltaTime) { _viewFrustum.setProjection(adjustedProjection); _viewFrustum.calculate(); } - appRenderArgs._renderArgs = RenderArgs(_gpuContext, lodManager->getOctreeSizeScale(), + appRenderArgs._renderArgs = RenderArgs(_graphicsEngine.getGPUContext(), lodManager->getOctreeSizeScale(), lodManager->getBoundaryLevelAdjust(), lodManager->getLODAngleHalfTan(), RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE); appRenderArgs._renderArgs._scene = getMain3DScene(); @@ -6339,6 +6288,13 @@ void Application::updateRenderArgs(float deltaTime) { QMutexLocker viewLocker(&_viewMutex); appRenderArgs._renderArgs.setViewFrustum(_displayViewFrustum); } + + + // HACK + // load the view frustum + // FIXME: This preDisplayRender call is temporary until we create a separate render::scene for the mirror rendering. + // Then we can move this logic into the Avatar::simulate call. + myAvatar->preDisplaySide(&appRenderArgs._renderArgs); }); } @@ -6548,11 +6504,16 @@ void Application::resetSensors(bool andReload) { } void Application::hmdVisibleChanged(bool visible) { + // TODO + // calling start and stop will change audio input and ouput to default audio devices. + // we need to add a pause/unpause functionality to AudioClient for this to work properly +#if 0 if (visible) { QMetaObject::invokeMethod(DependencyManager::get().data(), "start", Qt::QueuedConnection); } else { QMetaObject::invokeMethod(DependencyManager::get().data(), "stop", Qt::QueuedConnection); } +#endif } void Application::updateWindowTitle() const { @@ -6663,15 +6624,22 @@ void Application::resettingDomain() { } void Application::nodeAdded(SharedNodePointer node) const { - // nothing to do here + if (node->getType() == NodeType::EntityServer) { + if (!_failedToConnectToEntityServer) { + _entityServerConnectionTimer.stop(); + _entityServerConnectionTimer.setInterval(ENTITY_SERVER_CONNECTION_TIMEOUT); + _entityServerConnectionTimer.start(); + } + } } void Application::nodeActivated(SharedNodePointer node) { if (node->getType() == NodeType::AssetServer) { // asset server just connected - check if we have the asset browser showing - auto offscreenUi = DependencyManager::get(); - auto assetDialog = offscreenUi->getRootItem()->findChild("AssetServer"); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); + auto assetDialog = offscreenUi ? offscreenUi->getRootItem()->findChild("AssetServer") : nullptr; if (assetDialog) { auto nodeList = DependencyManager::get(); @@ -6684,6 +6652,7 @@ void Application::nodeActivated(SharedNodePointer node) { assetDialog->setVisible(false); } } +#endif } // If we get a new EntityServer activated, reset lastQueried time @@ -6691,6 +6660,10 @@ void Application::nodeActivated(SharedNodePointer node) { if (node->getType() == NodeType::EntityServer) { _queryExpiry = SteadyClock::now(); _octreeQuery.incrementConnectionID(); + + if (!_failedToConnectToEntityServer) { + _entityServerConnectionTimer.stop(); + } } if (node->getType() == NodeType::AudioMixer && !isInterstitialMode()) { @@ -6737,13 +6710,15 @@ void Application::nodeKilled(SharedNodePointer node) { } else if (node->getType() == NodeType::AssetServer) { // asset server going away - check if we have the asset browser showing - auto offscreenUi = DependencyManager::get(); - auto assetDialog = offscreenUi->getRootItem()->findChild("AssetServer"); +#if !defined(DISABLE_QML) + auto offscreenUi = getOffscreenUI(); + auto assetDialog = offscreenUi ? offscreenUi->getRootItem()->findChild("AssetServer") : nullptr; if (assetDialog) { // call reload on the shown asset browser dialog QMetaObject::invokeMethod(assetDialog, "clear"); } +#endif } } @@ -6850,8 +6825,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe qScriptRegisterMetaType(scriptEngine.data(), RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue); - scriptEngine->registerGlobalObject("OffscreenFlags", DependencyManager::get()->getFlags()); +#if !defined(DISABLE_QML) + scriptEngine->registerGlobalObject("OffscreenFlags", getOffscreenUI()->getFlags()); scriptEngine->registerGlobalObject("Desktop", DependencyManager::get().data()); +#endif qScriptRegisterMetaType(scriptEngine.data(), wrapperToScriptValue, wrapperFromScriptValue); qScriptRegisterMetaType(scriptEngine.data(), @@ -6877,14 +6854,16 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe bool clientScript = scriptEngine->isClientScript(); scriptEngine->registerFunction("OverlayWindow", clientScript ? QmlWindowClass::constructor : QmlWindowClass::restricted_constructor); -#if !defined(Q_OS_ANDROID) +#if !defined(Q_OS_ANDROID) && !defined(DISABLE_QML) scriptEngine->registerFunction("OverlayWebWindow", clientScript ? QmlWebWindowClass::constructor : QmlWebWindowClass::restricted_constructor); #endif scriptEngine->registerFunction("QmlFragment", clientScript ? QmlFragmentClass::constructor : QmlFragmentClass::restricted_constructor); scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("DesktopPreviewProvider", DependencyManager::get().data()); +#if !defined(DISABLE_QML) scriptEngine->registerGlobalObject("Stats", Stats::getInstance()); +#endif scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Snapshot", DependencyManager::get().data()); scriptEngine->registerGlobalObject("AudioStats", DependencyManager::get()->getStats().data()); @@ -6925,7 +6904,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); scriptEngine->registerGlobalObject("Scene", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("Render", _renderEngine->getConfiguration().get()); + scriptEngine->registerGlobalObject("Render", _graphicsEngine.getRenderEngine()->getConfiguration().get()); scriptEngine->registerGlobalObject("Workload", _gameWorkload._engine->getConfiguration().get()); GraphicsScriptingInterface::registerMetaTypes(scriptEngine.data()); @@ -7080,7 +7059,7 @@ bool Application::askToSetAvatarUrl(const QString& url) { qCDebug(interfaceapp) << "Declined to agree to avatar license"; } - //auto offscreenUi = DependencyManager::get(); + //auto offscreenUi = getOffscreenUI(); }); } else { setAvatar(url, modelName); @@ -7278,7 +7257,9 @@ void Application::showDialog(const QUrl& widgetUrl, const QUrl& tabletUrl, const toggleTabletUI(true); } } else { - DependencyManager::get()->show(widgetUrl, name); +#if !defined(DISABLE_QML) + getOffscreenUI()->show(widgetUrl, name); +#endif } } @@ -7303,10 +7284,10 @@ void Application::showAssetServerWidget(QString filePath) { auto tablet = dynamic_cast(tabletScriptingInterface->getTablet(SYSTEM_TABLET)); auto hmd = DependencyManager::get(); if (tablet->getToolbarMode()) { - DependencyManager::get()->show(url, "AssetServer", startUpload); + getOffscreenUI()->show(url, "AssetServer", startUpload); } else { if (!hmd->getShouldShowTablet() && !isHMDMode()) { - DependencyManager::get()->show(url, "AssetServer", startUpload); + getOffscreenUI()->show(url, "AssetServer", startUpload); } else { static const QUrl url("hifi/dialogs/TabletAssetServer.qml"); if (!tablet->isPathLoaded(url)) { @@ -7661,7 +7642,7 @@ void Application::addAssetToWorldInfo(QString modelName, QString infoText) { if (!_addAssetToWorldErrorTimer.isActive()) { if (!_addAssetToWorldMessageBox) { - _addAssetToWorldMessageBox = DependencyManager::get()->createMessageBox(OffscreenUi::ICON_INFORMATION, + _addAssetToWorldMessageBox = getOffscreenUI()->createMessageBox(OffscreenUi::ICON_INFORMATION, "Downloading Model", "", QMessageBox::NoButton, QMessageBox::NoButton); connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed())); } @@ -7744,7 +7725,7 @@ void Application::addAssetToWorldError(QString modelName, QString errorText) { addAssetToWorldInfoClear(modelName); if (!_addAssetToWorldMessageBox) { - _addAssetToWorldMessageBox = DependencyManager::get()->createMessageBox(OffscreenUi::ICON_INFORMATION, + _addAssetToWorldMessageBox = getOffscreenUI()->createMessageBox(OffscreenUi::ICON_INFORMATION, "Downloading Model", "", QMessageBox::NoButton, QMessageBox::NoButton); connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed())); } @@ -8238,6 +8219,8 @@ DisplayPluginPointer Application::getActiveDisplayPlugin() const { return _displayPlugin; } + +#if !defined(DISABLE_QML) static const char* EXCLUSION_GROUP_KEY = "exclusionGroup"; static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, int index, bool active) { @@ -8278,6 +8261,7 @@ static void addDisplayPluginToMenu(const DisplayPluginPointer& displayPlugin, in action->setProperty(EXCLUSION_GROUP_KEY, QVariant::fromValue(displayPluginGroup)); Q_ASSERT(menu->menuItemExists(MenuOption::OutputMenu, name)); } +#endif void Application::updateDisplayMode() { // Unsafe to call this method from anything but the main thread @@ -8322,8 +8306,8 @@ void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) { // instead emit a signal that the display plugin is changing and let // the desktop lock itself. Reduces coupling between the UI and display // plugins - auto offscreenUi = DependencyManager::get(); - auto desktop = offscreenUi->getDesktop(); + auto offscreenUi = getOffscreenUI(); + auto desktop = offscreenUi ? offscreenUi->getDesktop() : nullptr; auto menu = Menu::getInstance(); // Make the switch atomic from the perspective of other threads @@ -8369,7 +8353,9 @@ void Application::setDisplayPlugin(DisplayPluginPointer newDisplayPlugin) { } } - offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize())); + if (offscreenUi) { + offscreenUi->resize(fromGlm(newDisplayPlugin->getRecommendedUiSize())); + } getApplicationCompositor().setDisplayPlugin(newDisplayPlugin); _displayPlugin = newDisplayPlugin; connect(_displayPlugin.get(), &DisplayPlugin::presented, this, &Application::onPresent, Qt::DirectConnection); diff --git a/interface/src/Application.h b/interface/src/Application.h index 9b8aac425a..ead7231ffc 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -70,11 +70,11 @@ #include "ui/overlays/Overlays.h" #include "workload/GameWorkload.h" +#include "graphics/GraphicsEngine.h" #include #include #include -#include "FrameTimingsScriptingInterface.h" #include "Sound.h" @@ -153,7 +153,6 @@ public: void updateSecondaryCameraViewFrustum(); void updateCamera(RenderArgs& renderArgs, float deltaTime); - void paintGL(); void resizeGL(); bool event(QEvent* event) override; @@ -203,8 +202,8 @@ public: Overlays& getOverlays() { return _overlays; } - size_t getRenderFrameCount() const { return _renderFrameCount; } - float getRenderLoopRate() const { return _renderLoopCounter.rate(); } + size_t getRenderFrameCount() const { return _graphicsEngine.getRenderFrameCount(); } + float getRenderLoopRate() const { return _graphicsEngine.getRenderLoopRate(); } float getNumCollisionObjects() const; float getTargetRenderFrameRate() const; // frames/second @@ -275,10 +274,10 @@ public: void setMaxOctreePacketsPerSecond(int maxOctreePPS); int getMaxOctreePacketsPerSecond() const; - render::ScenePointer getMain3DScene() override { return _main3DScene; } - const render::ScenePointer& getMain3DScene() const { return _main3DScene; } - render::EnginePointer getRenderEngine() override { return _renderEngine; } - gpu::ContextPointer getGPUContext() const { return _gpuContext; } + render::ScenePointer getMain3DScene() override { return _graphicsEngine.getRenderScene(); } + render::EnginePointer getRenderEngine() override { return _graphicsEngine.getRenderEngine(); } + gpu::ContextPointer getGPUContext() const { return _graphicsEngine.getGPUContext(); } + const GameWorkload& getGameWorkload() const { return _gameWorkload; } @@ -310,6 +309,7 @@ public: bool isServerlessMode() const; bool isInterstitialMode() const { return _interstitialMode; } + bool failedToConnectToEntityServer() const { return _failedToConnectToEntityServer; } void replaceDomainContent(const QString& url); @@ -467,6 +467,7 @@ private slots: void loadSettings(); void saveSettings() const; + void setFailedToConnectToEntityServer() { _failedToConnectToEntityServer = true; } bool acceptSnapshot(const QString& urlString); bool askToSetAvatarUrl(const QString& url); @@ -513,7 +514,6 @@ private: bool handleFileOpenEvent(QFileOpenEvent* event); void cleanupBeforeQuit(); - bool shouldPaint() const; void idle(); void update(float deltaTime); @@ -533,8 +533,6 @@ private: void initializeAcceptedFiles(); - void runRenderFrame(RenderArgs* renderArgs/*, Camera& whichCamera, bool selfAvatarOnly = false*/); - bool importJSONFromURL(const QString& urlString); bool importSVOFromURL(const QString& urlString); bool importFromZIP(const QString& filePath); @@ -584,18 +582,12 @@ private: bool _activatingDisplayPlugin { false }; - uint32_t _renderFrameCount { 0 }; - // Frame Rate Measurement - RateCounter<500> _renderLoopCounter; RateCounter<500> _gameLoopCounter; - FrameTimingsScriptingInterface _frameTimingsScriptingInterface; - QTimer _minimizedWindowTimer; QElapsedTimer _timerStart; QElapsedTimer _lastTimeUpdated; - QElapsedTimer _lastTimeRendered; int _minimumGPUTextureMemSizeStabilityCount { 30 }; @@ -681,29 +673,9 @@ private: quint64 _lastFaceTrackerUpdate; - render::ScenePointer _main3DScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) }; - render::EnginePointer _renderEngine{ new render::RenderEngine() }; - gpu::ContextPointer _gpuContext; // initialized during window creation - GameWorkload _gameWorkload; - mutable QMutex _renderArgsMutex{ QMutex::Recursive }; - struct AppRenderArgs { - render::Args _renderArgs; - glm::mat4 _eyeToWorld; - glm::mat4 _view; - glm::mat4 _eyeOffsets[2]; - glm::mat4 _eyeProjections[2]; - glm::mat4 _headPose; - glm::mat4 _sensorToWorld; - float _sensorToWorldScale { 1.0f }; - bool _isStereo{ false }; - }; - AppRenderArgs _appRenderArgs; - - - using RenderArgsEditor = std::function ; - void editRenderArgs(RenderArgsEditor editor); + GraphicsEngine _graphicsEngine; void updateRenderArgs(float deltaTime); @@ -719,6 +691,7 @@ private: bool _isForeground = true; // starts out assumed to be in foreground bool _isGLInitialized { false }; bool _physicsEnabled { false }; + bool _failedToConnectToEntityServer { false }; bool _reticleClickPressed { false }; @@ -748,8 +721,6 @@ private: bool _keyboardDeviceHasFocus { true }; - QString _returnFromFullScreenMirrorTo; - ConnectionMonitor _connectionMonitor; QTimer _addAssetToWorldResizeTimer; @@ -765,6 +736,7 @@ private: QStringList _addAssetToWorldInfoMessages; // Info message QTimer _addAssetToWorldInfoTimer; QTimer _addAssetToWorldErrorTimer; + mutable QTimer _entityServerConnectionTimer; FileScriptingInterface* _fileDownload; AudioInjectorPointer _snapshotSoundInjector; @@ -782,12 +754,8 @@ private: QUrl _avatarOverrideUrl; bool _saveAvatarOverrideUrl { false }; - QObject* _renderEventHandler{ nullptr }; - - friend class RenderEventHandler; std::atomic _pendingIdleEvent { true }; - std::atomic _pendingRenderEvent { true }; bool quitWhenFinished { false }; diff --git a/interface/src/Application_render.cpp b/interface/src/Application_render.cpp index a87caeb9a8..5063f6118d 100644 --- a/interface/src/Application_render.cpp +++ b/interface/src/Application_render.cpp @@ -19,218 +19,207 @@ #include "Util.h" -// Statically provided display and input plugins -extern DisplayPluginList getDisplayPlugins(); - -void Application::editRenderArgs(RenderArgsEditor editor) { - QMutexLocker renderLocker(&_renderArgsMutex); - editor(_appRenderArgs); - -} - -void Application::paintGL() { - // Some plugins process message events, allowing paintGL to be called reentrantly. - - _renderFrameCount++; - _lastTimeRendered.start(); - - auto lastPaintBegin = usecTimestampNow(); - PROFILE_RANGE_EX(render, __FUNCTION__, 0xff0000ff, (uint64_t)_renderFrameCount); - PerformanceTimer perfTimer("paintGL"); - - if (nullptr == _displayPlugin) { - return; - } - - DisplayPluginPointer displayPlugin; - { - PROFILE_RANGE(render, "/getActiveDisplayPlugin"); - displayPlugin = getActiveDisplayPlugin(); - } - - { - PROFILE_RANGE(render, "/pluginBeginFrameRender"); - // If a display plugin loses it's underlying support, it - // needs to be able to signal us to not use it - if (!displayPlugin->beginFrameRender(_renderFrameCount)) { - QMetaObject::invokeMethod(this, "updateDisplayMode"); - return; - } - } - - RenderArgs renderArgs; - glm::mat4 HMDSensorPose; - glm::mat4 eyeToWorld; - glm::mat4 sensorToWorld; - - bool isStereo; - glm::mat4 stereoEyeOffsets[2]; - glm::mat4 stereoEyeProjections[2]; - - { - QMutexLocker viewLocker(&_renderArgsMutex); - renderArgs = _appRenderArgs._renderArgs; - - // don't render if there is no context. - if (!_appRenderArgs._renderArgs._context) { - return; - } - - HMDSensorPose = _appRenderArgs._headPose; - eyeToWorld = _appRenderArgs._eyeToWorld; - sensorToWorld = _appRenderArgs._sensorToWorld; - isStereo = _appRenderArgs._isStereo; - for_each_eye([&](Eye eye) { - stereoEyeOffsets[eye] = _appRenderArgs._eyeOffsets[eye]; - stereoEyeProjections[eye] = _appRenderArgs._eyeProjections[eye]; - }); - } - - { - PROFILE_RANGE(render, "/gpuContextReset"); - _gpuContext->beginFrame(_appRenderArgs._view, HMDSensorPose); - // Reset the gpu::Context Stages - // Back to the default framebuffer; - gpu::doInBatch("Application_render::gpuContextReset", _gpuContext, [&](gpu::Batch& batch) { - batch.resetStages(); - }); - } - - - { - PROFILE_RANGE(render, "/renderOverlay"); - PerformanceTimer perfTimer("renderOverlay"); - // NOTE: There is no batch associated with this renderArgs - // the ApplicationOverlay class assumes it's viewport is setup to be the device size - renderArgs._viewport = glm::ivec4(0, 0, getDeviceSize()); - _applicationOverlay.renderOverlay(&renderArgs); - } - - { - PROFILE_RANGE(render, "/updateCompositor"); - getApplicationCompositor().setFrameInfo(_renderFrameCount, eyeToWorld, sensorToWorld); - } - - gpu::FramebufferPointer finalFramebuffer; - QSize finalFramebufferSize; - { - PROFILE_RANGE(render, "/getOutputFramebuffer"); - // Primary rendering pass - auto framebufferCache = DependencyManager::get(); - finalFramebufferSize = framebufferCache->getFrameBufferSize(); - // Final framebuffer that will be handed to the display-plugin - finalFramebuffer = framebufferCache->getFramebuffer(); - } - - { - if (isStereo) { - renderArgs._context->enableStereo(true); - renderArgs._context->setStereoProjections(stereoEyeProjections); - renderArgs._context->setStereoViews(stereoEyeOffsets); - } - - renderArgs._hudOperator = displayPlugin->getHUDOperator(); - renderArgs._hudTexture = _applicationOverlay.getOverlayTexture(); - renderArgs._blitFramebuffer = finalFramebuffer; - runRenderFrame(&renderArgs); - } - - auto frame = _gpuContext->endFrame(); - frame->frameIndex = _renderFrameCount; - frame->framebuffer = finalFramebuffer; - frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer) { - auto frameBufferCache = DependencyManager::get(); - if (frameBufferCache) { - frameBufferCache->releaseFramebuffer(framebuffer); - } - }; - // deliver final scene rendering commands to the display plugin - { - PROFILE_RANGE(render, "/pluginOutput"); - PerformanceTimer perfTimer("pluginOutput"); - _renderLoopCounter.increment(); - displayPlugin->submitFrame(frame); - } - - // Reset the framebuffer and stereo state - renderArgs._blitFramebuffer.reset(); - renderArgs._context->enableStereo(false); - - { - auto stats = Stats::getInstance(); - if (stats) { - stats->setRenderDetails(renderArgs._details); - } - } - - uint64_t lastPaintDuration = usecTimestampNow() - lastPaintBegin; - _frameTimingsScriptingInterface.addValue(lastPaintDuration); -} +//void Application::paintGL() { +// // Some plugins process message events, allowing paintGL to be called reentrantly. +// +// _renderFrameCount++; +// // SG: Moved into the RenderEventHandler +// //_lastTimeRendered.start(); +// +// auto lastPaintBegin = usecTimestampNow(); +// PROFILE_RANGE_EX(render, __FUNCTION__, 0xff0000ff, (uint64_t)_renderFrameCount); +// PerformanceTimer perfTimer("paintGL"); +// +// if (nullptr == _displayPlugin) { +// return; +// } +// +// DisplayPluginPointer displayPlugin; +// { +// PROFILE_RANGE(render, "/getActiveDisplayPlugin"); +// displayPlugin = getActiveDisplayPlugin(); +// } +// +// { +// PROFILE_RANGE(render, "/pluginBeginFrameRender"); +// // If a display plugin loses it's underlying support, it +// // needs to be able to signal us to not use it +// if (!displayPlugin->beginFrameRender(_renderFrameCount)) { +// QMetaObject::invokeMethod(this, "updateDisplayMode"); +// return; +// } +// } +// +// RenderArgs renderArgs; +// glm::mat4 HMDSensorPose; +// glm::mat4 eyeToWorld; +// glm::mat4 sensorToWorld; +// +// bool isStereo; +// glm::mat4 stereoEyeOffsets[2]; +// glm::mat4 stereoEyeProjections[2]; +// +// { +// QMutexLocker viewLocker(&_renderArgsMutex); +// renderArgs = _appRenderArgs._renderArgs; +// +// // don't render if there is no context. +// if (!_appRenderArgs._renderArgs._context) { +// return; +// } +// +// HMDSensorPose = _appRenderArgs._headPose; +// eyeToWorld = _appRenderArgs._eyeToWorld; +// sensorToWorld = _appRenderArgs._sensorToWorld; +// isStereo = _appRenderArgs._isStereo; +// for_each_eye([&](Eye eye) { +// stereoEyeOffsets[eye] = _appRenderArgs._eyeOffsets[eye]; +// stereoEyeProjections[eye] = _appRenderArgs._eyeProjections[eye]; +// }); +// } +// +// { +// PROFILE_RANGE(render, "/gpuContextReset"); +// _graphicsEngine.getGPUContext()->beginFrame(_appRenderArgs._view, HMDSensorPose); +// // Reset the gpu::Context Stages +// // Back to the default framebuffer; +// gpu::doInBatch("Application_render::gpuContextReset", _graphicsEngine.getGPUContext(), [&](gpu::Batch& batch) { +// batch.resetStages(); +// }); +// } +// +// +// { +// PROFILE_RANGE(render, "/renderOverlay"); +// PerformanceTimer perfTimer("renderOverlay"); +// // NOTE: There is no batch associated with this renderArgs +// // the ApplicationOverlay class assumes it's viewport is setup to be the device size +// renderArgs._viewport = glm::ivec4(0, 0, getDeviceSize() * getRenderResolutionScale()); +// _applicationOverlay.renderOverlay(&renderArgs); +// } +// +// { +// PROFILE_RANGE(render, "/updateCompositor"); +// getApplicationCompositor().setFrameInfo(_renderFrameCount, eyeToWorld, sensorToWorld); +// } +// +// gpu::FramebufferPointer finalFramebuffer; +// QSize finalFramebufferSize; +// { +// PROFILE_RANGE(render, "/getOutputFramebuffer"); +// // Primary rendering pass +// auto framebufferCache = DependencyManager::get(); +// finalFramebufferSize = framebufferCache->getFrameBufferSize(); +// // Final framebuffer that will be handled to the display-plugin +// finalFramebuffer = framebufferCache->getFramebuffer(); +// } +// +// { +// if (isStereo) { +// renderArgs._context->enableStereo(true); +// renderArgs._context->setStereoProjections(stereoEyeProjections); +// renderArgs._context->setStereoViews(stereoEyeOffsets); +// } +// +// renderArgs._hudOperator = displayPlugin->getHUDOperator(); +// renderArgs._hudTexture = _applicationOverlay.getOverlayTexture(); +// renderArgs._blitFramebuffer = finalFramebuffer; +// _graphicsEngine.render_runRenderFrame(&renderArgs); +// } +// +// auto frame = _graphicsEngine.getGPUContext()->endFrame(); +// frame->frameIndex = _renderFrameCount; +// frame->framebuffer = finalFramebuffer; +// frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer) { +// auto frameBufferCache = DependencyManager::get(); +// if (frameBufferCache) { +// frameBufferCache->releaseFramebuffer(framebuffer); +// } +// }; +// // deliver final scene rendering commands to the display plugin +// { +// PROFILE_RANGE(render, "/pluginOutput"); +// PerformanceTimer perfTimer("pluginOutput"); +// _renderLoopCounter.increment(); +// displayPlugin->submitFrame(frame); +// } +// +// // Reset the framebuffer and stereo state +// renderArgs._blitFramebuffer.reset(); +// renderArgs._context->enableStereo(false); +// +// { +// Stats::getInstance()->setRenderDetails(renderArgs._details); +// } +// +// uint64_t lastPaintDuration = usecTimestampNow() - lastPaintBegin; +// _frameTimingsScriptingInterface.addValue(lastPaintDuration); +//} // WorldBox Render Data & rendering functions - -class WorldBoxRenderData { -public: - typedef render::Payload Payload; - typedef Payload::DataPointer Pointer; - - int _val = 0; - static render::ItemID _item; // unique WorldBoxRenderData -}; - -render::ItemID WorldBoxRenderData::_item{ render::Item::INVALID_ITEM_ID }; - -namespace render { - template <> const ItemKey payloadGetKey(const WorldBoxRenderData::Pointer& stuff) { return ItemKey::Builder::opaqueShape().withTagBits(ItemKey::TAG_BITS_0 | ItemKey::TAG_BITS_1); } - template <> const Item::Bound payloadGetBound(const WorldBoxRenderData::Pointer& stuff) { return Item::Bound(); } - template <> void payloadRender(const WorldBoxRenderData::Pointer& stuff, RenderArgs* args) { - if (Menu::getInstance()->isOptionChecked(MenuOption::WorldAxes)) { - PerformanceTimer perfTimer("worldBox"); - - auto& batch = *args->_batch; - DependencyManager::get()->bindSimpleProgram(batch); - renderWorldBox(args, batch); - } - } -} - -void Application::runRenderFrame(RenderArgs* renderArgs) { - PROFILE_RANGE(render, __FUNCTION__); - PerformanceTimer perfTimer("display"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::runRenderFrame()"); - - // The pending changes collecting the changes here - render::Transaction transaction; - - if (DependencyManager::get()->shouldRenderEntities()) { - // render models... - PerformanceTimer perfTimer("entities"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::runRenderFrame() ... entities..."); - - RenderArgs::DebugFlags renderDebugFlags = RenderArgs::RENDER_DEBUG_NONE; - - renderArgs->_debugFlags = renderDebugFlags; - } - - // Make sure the WorldBox is in the scene - // For the record, this one RenderItem is the first one we created and added to the scene. - // We could move that code elsewhere but you know... - if (!render::Item::isValidID(WorldBoxRenderData::_item)) { - auto worldBoxRenderData = std::make_shared(); - auto worldBoxRenderPayload = std::make_shared(worldBoxRenderData); - - WorldBoxRenderData::_item = _main3DScene->allocateID(); - - transaction.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload); - _main3DScene->enqueueTransaction(transaction); - } - - { - PerformanceTimer perfTimer("EngineRun"); - _renderEngine->getRenderContext()->args = renderArgs; - _renderEngine->run(); - } -} +// +//class WorldBoxRenderData { +//public: +// typedef render::Payload Payload; +// typedef Payload::DataPointer Pointer; +// +// int _val = 0; +// static render::ItemID _item; // unique WorldBoxRenderData +//}; +// +//render::ItemID WorldBoxRenderData::_item{ render::Item::INVALID_ITEM_ID }; +// +//namespace render { +// template <> const ItemKey payloadGetKey(const WorldBoxRenderData::Pointer& stuff) { return ItemKey::Builder::opaqueShape().withTagBits(ItemKey::TAG_BITS_0 | ItemKey::TAG_BITS_1); } +// template <> const Item::Bound payloadGetBound(const WorldBoxRenderData::Pointer& stuff) { return Item::Bound(); } +// template <> void payloadRender(const WorldBoxRenderData::Pointer& stuff, RenderArgs* args) { +// if (Menu::getInstance()->isOptionChecked(MenuOption::WorldAxes)) { +// PerformanceTimer perfTimer("worldBox"); +// +// auto& batch = *args->_batch; +// DependencyManager::get()->bindSimpleProgram(batch); +// renderWorldBox(args, batch); +// } +// } +//} +// +//void Application::runRenderFrame(RenderArgs* renderArgs) { +// PROFILE_RANGE(render, __FUNCTION__); +// PerformanceTimer perfTimer("display"); +// PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::runRenderFrame()"); +// +// // The pending changes collecting the changes here +// render::Transaction transaction; +// +// if (DependencyManager::get()->shouldRenderEntities()) { +// // render models... +// PerformanceTimer perfTimer("entities"); +// PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), +// "Application::runRenderFrame() ... entities..."); +// +// RenderArgs::DebugFlags renderDebugFlags = RenderArgs::RENDER_DEBUG_NONE; +// +// renderArgs->_debugFlags = renderDebugFlags; +// } +// +// // Make sure the WorldBox is in the scene +// // For the record, this one RenderItem is the first one we created and added to the scene. +// // We could move that code elsewhere but you know... +// if (!render::Item::isValidID(WorldBoxRenderData::_item)) { +// auto worldBoxRenderData = std::make_shared(); +// auto worldBoxRenderPayload = std::make_shared(worldBoxRenderData); +// +// WorldBoxRenderData::_item = _main3DScene->allocateID(); +// +// transaction.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload); +// _main3DScene->enqueueTransaction(transaction); +// } +// +// { +// PerformanceTimer perfTimer("EngineRun"); +// _renderEngine->getRenderContext()->args = renderArgs; +// _renderEngine->run(); +// } +//} diff --git a/interface/src/AvatarBookmarks.cpp b/interface/src/AvatarBookmarks.cpp index 534fb15d93..099171a427 100644 --- a/interface/src/AvatarBookmarks.cpp +++ b/interface/src/AvatarBookmarks.cpp @@ -247,25 +247,35 @@ QVariantMap AvatarBookmarks::getAvatarDataToBookmark() { bookmark.insert(ENTRY_AVATAR_URL, avatarUrl); bookmark.insert(ENTRY_AVATAR_SCALE, avatarScale); - QScriptEngine scriptEngine; QVariantList wearableEntities; auto treeRenderer = DependencyManager::get(); EntityTreePointer entityTree = treeRenderer ? treeRenderer->getTree() : nullptr; - auto avatarEntities = myAvatar->getAvatarEntityData(); - for (auto entityID : avatarEntities.keys()) { - auto entity = entityTree->findEntityByID(entityID); - if (!entity || !isWearableEntity(entity)) { - continue; + + if (entityTree) { + QScriptEngine scriptEngine; + auto avatarEntities = myAvatar->getAvatarEntityData(); + for (auto entityID : avatarEntities.keys()) { + auto entity = entityTree->findEntityByID(entityID); + if (!entity || !isWearableEntity(entity)) { + continue; + } + + QVariantMap avatarEntityData; + + EncodeBitstreamParams params; + auto desiredProperties = entity->getEntityProperties(params); + desiredProperties += PROP_LOCAL_POSITION; + desiredProperties += PROP_LOCAL_ROTATION; + desiredProperties -= PROP_JOINT_ROTATIONS_SET; + desiredProperties -= PROP_JOINT_ROTATIONS; + desiredProperties -= PROP_JOINT_TRANSLATIONS_SET; + desiredProperties -= PROP_JOINT_TRANSLATIONS; + + EntityItemProperties entityProperties = entity->getProperties(desiredProperties); + QScriptValue scriptProperties = EntityItemPropertiesToScriptValue(&scriptEngine, entityProperties); + avatarEntityData["properties"] = scriptProperties.toVariant(); + wearableEntities.append(QVariant(avatarEntityData)); } - QVariantMap avatarEntityData; - EncodeBitstreamParams params; - auto desiredProperties = entity->getEntityProperties(params); - desiredProperties += PROP_LOCAL_POSITION; - desiredProperties += PROP_LOCAL_ROTATION; - EntityItemProperties entityProperties = entity->getProperties(desiredProperties); - QScriptValue scriptProperties = EntityItemPropertiesToScriptValue(&scriptEngine, entityProperties); - avatarEntityData["properties"] = scriptProperties.toVariant(); - wearableEntities.append(QVariant(avatarEntityData)); } bookmark.insert(ENTRY_AVATAR_ENTITIES, wearableEntities); return bookmark; diff --git a/interface/src/ConnectionMonitor.cpp b/interface/src/ConnectionMonitor.cpp index e86061b090..33d9fddc1b 100644 --- a/interface/src/ConnectionMonitor.cpp +++ b/interface/src/ConnectionMonitor.cpp @@ -48,7 +48,9 @@ void ConnectionMonitor::init() { emit setRedirectErrorState(REDIRECT_HIFI_ADDRESS, "", 5); } else { qDebug() << "ConnectionMonitor: Showing connection failure window"; +#if !defined(DISABLE_QML) DependencyManager::get()->setDomainConnectionFailureVisibility(true); +#endif } }); } @@ -59,8 +61,10 @@ void ConnectionMonitor::startTimer() { void ConnectionMonitor::stopTimer() { _timer.stop(); +#if !defined(DISABLE_QML) bool enableInterstitial = DependencyManager::get()->getDomainHandler().getInterstitialModeEnabled(); if (!enableInterstitial) { DependencyManager::get()->setDomainConnectionFailureVisibility(false); } +#endif } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 9d2d266b5c..e9a44b1e87 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -141,7 +141,7 @@ Menu::Menu() { assetServerAction->setEnabled(nodeList->getThisNodeCanWriteAssets()); } - // Edit > Package Model as .fst... + // Edit > Package Avatar as .fst... addActionToQMenuAndActionHash(editMenu, MenuOption::PackageModel, 0, qApp, SLOT(packageModel())); @@ -364,8 +364,6 @@ Menu::Menu() { qApp->setHmdTabletBecomesToolbarSetting(action->isChecked()); }); - addCheckableActionToQMenuAndActionHash(uiOptionsMenu, MenuOption::Use3DKeyboard, 0, true); - // Developer > Render >>> MenuWrapper* renderOptionsMenu = developerMenu->addMenu("Render"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index d26879c816..7168b7294e 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -117,7 +117,7 @@ namespace MenuOption { const QString FrameTimer = "Show Timer"; const QString FullscreenMirror = "Mirror"; const QString Help = "Help..."; - const QString HomeLocation = "Home"; + const QString HomeLocation = "Home "; const QString IncreaseAvatarSize = "Increase Avatar Size"; const QString IndependentMode = "Independent Mode"; const QString ActionMotorControl = "Enable Default Motor Control"; @@ -141,7 +141,7 @@ namespace MenuOption { const QString OpenVrThreadedSubmit = "OpenVR Threaded Submit"; const QString OutputMenu = "Display"; const QString Overlays = "Show Overlays"; - const QString PackageModel = "Package Model as .fst..."; + const QString PackageModel = "Package Avatar as .fst..."; const QString Pair = "Pair"; const QString PhysicsShowOwned = "Highlight Simulation Ownership"; const QString VerboseLogging = "Verbose Logging"; @@ -213,7 +213,6 @@ namespace MenuOption { const QString TurnWithHead = "Turn using Head"; const QString UseAudioForMouth = "Use Audio for Mouth"; const QString UseCamera = "Use Camera"; - const QString Use3DKeyboard = "Use 3D Keyboard"; const QString VelocityFilter = "Velocity Filter"; const QString VisibleToEveryone = "Everyone"; const QString VisibleToFriends = "Friends"; diff --git a/interface/src/ModelPackager.cpp b/interface/src/ModelPackager.cpp index 2e7b84c17d..84325da473 100644 --- a/interface/src/ModelPackager.cpp +++ b/interface/src/ModelPackager.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "ModelSelector.h" @@ -68,7 +69,6 @@ bool ModelPackager::selectModel() { ModelSelector selector; if(selector.exec() == QDialog::Accepted) { _modelFile = selector.getFileInfo(); - _modelType = selector.getModelType(); return true; } return false; @@ -109,7 +109,7 @@ bool ModelPackager::loadModel() { qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath(); QByteArray fbxContents = fbx.readAll(); - _hfmModel.reset(readFBX(fbxContents, QVariantHash(), _fbxInfo.filePath())); + _hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath()); // make sure we have some basic mappings populateBasicMapping(_mapping, _fbxInfo.filePath(), *_hfmModel); @@ -122,28 +122,26 @@ bool ModelPackager::loadModel() { bool ModelPackager::editProperties() { // open the dialog to configure the rest - ModelPropertiesDialog properties(_modelType, _mapping, _modelFile.path(), *_hfmModel); + ModelPropertiesDialog properties(_mapping, _modelFile.path(), *_hfmModel); if (properties.exec() == QDialog::Rejected) { return false; } _mapping = properties.getMapping(); - if (_modelType == FSTReader::BODY_ONLY_MODEL || _modelType == FSTReader::HEAD_AND_BODY_MODEL) { - // Make sure that a mapping for the root joint has been specified - QVariantHash joints = _mapping.value(JOINT_FIELD).toHash(); - if (!joints.contains("jointRoot")) { - qWarning() << "root joint not configured for skeleton."; + // Make sure that a mapping for the root joint has been specified + QVariantHash joints = _mapping.value(JOINT_FIELD).toHash(); + if (!joints.contains("jointRoot")) { + qWarning() << "root joint not configured for skeleton."; - QString message = "Your did not configure a root joint for your skeleton model.\n\nPackaging will be canceled."; - QMessageBox msgBox; - msgBox.setWindowTitle("Model Packager"); - msgBox.setText(message); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Warning); - msgBox.exec(); + QString message = "Your did not configure a root joint for your skeleton model.\n\nPackaging will be canceled."; + QMessageBox msgBox; + msgBox.setWindowTitle("Model Packager"); + msgBox.setText(message); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Warning); + msgBox.exec(); - return false; - } + return false; } return true; @@ -237,8 +235,6 @@ bool ModelPackager::zipModel() { void ModelPackager::populateBasicMapping(QVariantHash& mapping, QString filename, const hfm::Model& hfmModel) { - bool isBodyType = _modelType == FSTReader::BODY_ONLY_MODEL || _modelType == FSTReader::HEAD_AND_BODY_MODEL; - // mixamo files - in the event that a mixamo file was edited by some other tool, it's likely the applicationName will // be rewritten, so we detect the existence of several different blendshapes which indicate we're likely a mixamo file bool likelyMixamoFile = hfmModel.applicationName == "mixamo.com" || @@ -279,19 +275,17 @@ void ModelPackager::populateBasicMapping(QVariantHash& mapping, QString filename joints.insert("jointNeck", hfmModel.jointIndices.contains("jointNeck") ? "jointNeck" : "Neck"); } - if (isBodyType) { - if (!joints.contains("jointRoot")) { - joints.insert("jointRoot", "Hips"); - } - if (!joints.contains("jointLean")) { - joints.insert("jointLean", "Spine"); - } - if (!joints.contains("jointLeftHand")) { - joints.insert("jointLeftHand", "LeftHand"); - } - if (!joints.contains("jointRightHand")) { - joints.insert("jointRightHand", "RightHand"); - } + if (!joints.contains("jointRoot")) { + joints.insert("jointRoot", "Hips"); + } + if (!joints.contains("jointLean")) { + joints.insert("jointLean", "Spine"); + } + if (!joints.contains("jointLeftHand")) { + joints.insert("jointLeftHand", "LeftHand"); + } + if (!joints.contains("jointRightHand")) { + joints.insert("jointRightHand", "RightHand"); } if (!joints.contains("jointHead")) { @@ -301,13 +295,11 @@ void ModelPackager::populateBasicMapping(QVariantHash& mapping, QString filename mapping.insert(JOINT_FIELD, joints); - if (isBodyType) { - if (!mapping.contains(FREE_JOINT_FIELD)) { - mapping.insertMulti(FREE_JOINT_FIELD, "LeftArm"); - mapping.insertMulti(FREE_JOINT_FIELD, "LeftForeArm"); - mapping.insertMulti(FREE_JOINT_FIELD, "RightArm"); - mapping.insertMulti(FREE_JOINT_FIELD, "RightForeArm"); - } + if (!mapping.contains(FREE_JOINT_FIELD)) { + mapping.insertMulti(FREE_JOINT_FIELD, "LeftArm"); + mapping.insertMulti(FREE_JOINT_FIELD, "LeftForeArm"); + mapping.insertMulti(FREE_JOINT_FIELD, "RightArm"); + mapping.insertMulti(FREE_JOINT_FIELD, "RightForeArm"); } // If there are no blendshape mappings, and we detect that this is likely a mixamo file, diff --git a/interface/src/ModelPackager.h b/interface/src/ModelPackager.h index 849f6ac3da..58d3d6bfee 100644 --- a/interface/src/ModelPackager.h +++ b/interface/src/ModelPackager.h @@ -41,12 +41,11 @@ private: QFileInfo _modelFile; QFileInfo _fbxInfo; - FSTReader::ModelType _modelType; QString _texDir; QString _scriptDir; QVariantHash _mapping; - std::unique_ptr _hfmModel; + std::shared_ptr _hfmModel; QStringList _textures; QStringList _scripts; }; diff --git a/interface/src/ModelPropertiesDialog.cpp b/interface/src/ModelPropertiesDialog.cpp index 49c57744a9..1bdb170b60 100644 --- a/interface/src/ModelPropertiesDialog.cpp +++ b/interface/src/ModelPropertiesDialog.cpp @@ -26,9 +26,8 @@ #include -ModelPropertiesDialog::ModelPropertiesDialog(FSTReader::ModelType modelType, const QVariantHash& originalMapping, +ModelPropertiesDialog::ModelPropertiesDialog(const QVariantHash& originalMapping, const QString& basePath, const HFMModel& hfmModel) : -_modelType(modelType), _originalMapping(originalMapping), _basePath(basePath), _hfmModel(hfmModel) @@ -50,36 +49,19 @@ _hfmModel(hfmModel) _scale->setMaximum(FLT_MAX); _scale->setSingleStep(0.01); - if (_modelType != FSTReader::ENTITY_MODEL) { - if (_modelType == FSTReader::ATTACHMENT_MODEL) { - QHBoxLayout* translation = new QHBoxLayout(); - form->addRow("Translation:", translation); - translation->addWidget(_translationX = createTranslationBox()); - translation->addWidget(_translationY = createTranslationBox()); - translation->addWidget(_translationZ = createTranslationBox()); - form->addRow("Pivot About Center:", _pivotAboutCenter = new QCheckBox()); - form->addRow("Pivot Joint:", _pivotJoint = createJointBox()); - connect(_pivotAboutCenter, SIGNAL(toggled(bool)), SLOT(updatePivotJoint())); - _pivotAboutCenter->setChecked(true); + form->addRow("Left Eye Joint:", _leftEyeJoint = createJointBox()); + form->addRow("Right Eye Joint:", _rightEyeJoint = createJointBox()); + form->addRow("Neck Joint:", _neckJoint = createJointBox()); + form->addRow("Root Joint:", _rootJoint = createJointBox()); + form->addRow("Lean Joint:", _leanJoint = createJointBox()); + form->addRow("Head Joint:", _headJoint = createJointBox()); + form->addRow("Left Hand Joint:", _leftHandJoint = createJointBox()); + form->addRow("Right Hand Joint:", _rightHandJoint = createJointBox()); - } else { - form->addRow("Left Eye Joint:", _leftEyeJoint = createJointBox()); - form->addRow("Right Eye Joint:", _rightEyeJoint = createJointBox()); - form->addRow("Neck Joint:", _neckJoint = createJointBox()); - } - if (_modelType == FSTReader::BODY_ONLY_MODEL || _modelType == FSTReader::HEAD_AND_BODY_MODEL) { - form->addRow("Root Joint:", _rootJoint = createJointBox()); - form->addRow("Lean Joint:", _leanJoint = createJointBox()); - form->addRow("Head Joint:", _headJoint = createJointBox()); - form->addRow("Left Hand Joint:", _leftHandJoint = createJointBox()); - form->addRow("Right Hand Joint:", _rightHandJoint = createJointBox()); - - form->addRow("Free Joints:", _freeJoints = new QVBoxLayout()); - QPushButton* newFreeJoint = new QPushButton("New Free Joint"); - _freeJoints->addWidget(newFreeJoint); - connect(newFreeJoint, SIGNAL(clicked(bool)), SLOT(createNewFreeJoint())); - } - } + form->addRow("Free Joints:", _freeJoints = new QVBoxLayout()); + QPushButton* newFreeJoint = new QPushButton("New Free Joint"); + _freeJoints->addWidget(newFreeJoint); + connect(newFreeJoint, SIGNAL(clicked(bool)), SLOT(createNewFreeJoint())); QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Reset); @@ -93,14 +75,9 @@ _hfmModel(hfmModel) reset(); } - -QString ModelPropertiesDialog::getType() const { - return FSTReader::getNameFromType(_modelType); -} - QVariantHash ModelPropertiesDialog::getMapping() const { QVariantHash mapping = _originalMapping; - mapping.insert(TYPE_FIELD, getType()); + mapping.insert(TYPE_FIELD, FSTReader::getNameFromType(FSTReader::HEAD_AND_BODY_MODEL)); mapping.insert(NAME_FIELD, _name->text()); mapping.insert(TEXDIR_FIELD, _textureDirectory->text()); mapping.insert(SCRIPT_FIELD, _scriptDirectory->text()); @@ -113,42 +90,24 @@ QVariantHash ModelPropertiesDialog::getMapping() const { } mapping.insert(JOINT_INDEX_FIELD, jointIndices); - if (_modelType != FSTReader::ENTITY_MODEL) { - QVariantHash joints = mapping.value(JOINT_FIELD).toHash(); - if (_modelType == FSTReader::ATTACHMENT_MODEL) { - glm::vec3 pivot; - if (_pivotAboutCenter->isChecked()) { - pivot = (_hfmModel.meshExtents.minimum + _hfmModel.meshExtents.maximum) * 0.5f; - - } else if (_pivotJoint->currentIndex() != 0) { - pivot = extractTranslation(_hfmModel.joints.at(_pivotJoint->currentIndex() - 1).transform); - } - mapping.insert(TRANSLATION_X_FIELD, -pivot.x * (float)_scale->value() + (float)_translationX->value()); - mapping.insert(TRANSLATION_Y_FIELD, -pivot.y * (float)_scale->value() + (float)_translationY->value()); - mapping.insert(TRANSLATION_Z_FIELD, -pivot.z * (float)_scale->value() + (float)_translationZ->value()); - - } else { - insertJointMapping(joints, "jointEyeLeft", _leftEyeJoint->currentText()); - insertJointMapping(joints, "jointEyeRight", _rightEyeJoint->currentText()); - insertJointMapping(joints, "jointNeck", _neckJoint->currentText()); - } + QVariantHash joints = mapping.value(JOINT_FIELD).toHash(); + insertJointMapping(joints, "jointEyeLeft", _leftEyeJoint->currentText()); + insertJointMapping(joints, "jointEyeRight", _rightEyeJoint->currentText()); + insertJointMapping(joints, "jointNeck", _neckJoint->currentText()); - if (_modelType == FSTReader::BODY_ONLY_MODEL || _modelType == FSTReader::HEAD_AND_BODY_MODEL) { - insertJointMapping(joints, "jointRoot", _rootJoint->currentText()); - insertJointMapping(joints, "jointLean", _leanJoint->currentText()); - insertJointMapping(joints, "jointHead", _headJoint->currentText()); - insertJointMapping(joints, "jointLeftHand", _leftHandJoint->currentText()); - insertJointMapping(joints, "jointRightHand", _rightHandJoint->currentText()); + insertJointMapping(joints, "jointRoot", _rootJoint->currentText()); + insertJointMapping(joints, "jointLean", _leanJoint->currentText()); + insertJointMapping(joints, "jointHead", _headJoint->currentText()); + insertJointMapping(joints, "jointLeftHand", _leftHandJoint->currentText()); + insertJointMapping(joints, "jointRightHand", _rightHandJoint->currentText()); - mapping.remove(FREE_JOINT_FIELD); - for (int i = 0; i < _freeJoints->count() - 1; i++) { - QComboBox* box = static_cast(_freeJoints->itemAt(i)->widget()->layout()->itemAt(0)->widget()); - mapping.insertMulti(FREE_JOINT_FIELD, box->currentText()); - } - } - mapping.insert(JOINT_FIELD, joints); + mapping.remove(FREE_JOINT_FIELD); + for (int i = 0; i < _freeJoints->count() - 1; i++) { + QComboBox* box = static_cast(_freeJoints->itemAt(i)->widget()->layout()->itemAt(0)->widget()); + mapping.insertMulti(FREE_JOINT_FIELD, box->currentText()); } + mapping.insert(JOINT_FIELD, joints); return mapping; } @@ -165,36 +124,23 @@ void ModelPropertiesDialog::reset() { QVariantHash jointHash = _originalMapping.value(JOINT_FIELD).toHash(); - if (_modelType != FSTReader::ENTITY_MODEL) { - if (_modelType == FSTReader::ATTACHMENT_MODEL) { - _translationX->setValue(_originalMapping.value(TRANSLATION_X_FIELD).toDouble()); - _translationY->setValue(_originalMapping.value(TRANSLATION_Y_FIELD).toDouble()); - _translationZ->setValue(_originalMapping.value(TRANSLATION_Z_FIELD).toDouble()); - _pivotAboutCenter->setChecked(true); - _pivotJoint->setCurrentIndex(0); + setJointText(_leftEyeJoint, jointHash.value("jointEyeLeft").toString()); + setJointText(_rightEyeJoint, jointHash.value("jointEyeRight").toString()); + setJointText(_neckJoint, jointHash.value("jointNeck").toString()); - } else { - setJointText(_leftEyeJoint, jointHash.value("jointEyeLeft").toString()); - setJointText(_rightEyeJoint, jointHash.value("jointEyeRight").toString()); - setJointText(_neckJoint, jointHash.value("jointNeck").toString()); - } + setJointText(_rootJoint, jointHash.value("jointRoot").toString()); + setJointText(_leanJoint, jointHash.value("jointLean").toString()); + setJointText(_headJoint, jointHash.value("jointHead").toString()); + setJointText(_leftHandJoint, jointHash.value("jointLeftHand").toString()); + setJointText(_rightHandJoint, jointHash.value("jointRightHand").toString()); - if (_modelType == FSTReader::BODY_ONLY_MODEL || _modelType == FSTReader::HEAD_AND_BODY_MODEL) { - setJointText(_rootJoint, jointHash.value("jointRoot").toString()); - setJointText(_leanJoint, jointHash.value("jointLean").toString()); - setJointText(_headJoint, jointHash.value("jointHead").toString()); - setJointText(_leftHandJoint, jointHash.value("jointLeftHand").toString()); - setJointText(_rightHandJoint, jointHash.value("jointRightHand").toString()); - - while (_freeJoints->count() > 1) { - delete _freeJoints->itemAt(0)->widget(); - } - foreach (const QVariant& joint, _originalMapping.values(FREE_JOINT_FIELD)) { - QString jointName = joint.toString(); - if (_hfmModel.jointIndices.contains(jointName)) { - createNewFreeJoint(jointName); - } - } + while (_freeJoints->count() > 1) { + delete _freeJoints->itemAt(0)->widget(); + } + foreach (const QVariant& joint, _originalMapping.values(FREE_JOINT_FIELD)) { + QString jointName = joint.toString(); + if (_hfmModel.jointIndices.contains(jointName)) { + createNewFreeJoint(jointName); } } } diff --git a/interface/src/ModelPropertiesDialog.h b/interface/src/ModelPropertiesDialog.h index 0bf8075197..7019d239ff 100644 --- a/interface/src/ModelPropertiesDialog.h +++ b/interface/src/ModelPropertiesDialog.h @@ -14,7 +14,7 @@ #include -#include +#include #include #include "ui/ModelsBrowser.h" @@ -29,7 +29,7 @@ class ModelPropertiesDialog : public QDialog { Q_OBJECT public: - ModelPropertiesDialog(FSTReader::ModelType modelType, const QVariantHash& originalMapping, + ModelPropertiesDialog(const QVariantHash& originalMapping, const QString& basePath, const HFMModel& hfmModel); QVariantHash getMapping() const; @@ -45,9 +45,7 @@ private: QComboBox* createJointBox(bool withNone = true) const; QDoubleSpinBox* createTranslationBox() const; void insertJointMapping(QVariantHash& joints, const QString& joint, const QString& name) const; - QString getType() const; - FSTReader::ModelType _modelType; QVariantHash _originalMapping; QString _basePath; HFMModel _hfmModel; @@ -71,4 +69,4 @@ private: QVBoxLayout* _freeJoints = nullptr; }; -#endif // hifi_ModelPropertiesDialog_h \ No newline at end of file +#endif // hifi_ModelPropertiesDialog_h diff --git a/interface/src/ModelSelector.cpp b/interface/src/ModelSelector.cpp index 7d91359a11..3223e3ab9c 100644 --- a/interface/src/ModelSelector.cpp +++ b/interface/src/ModelSelector.cpp @@ -19,7 +19,6 @@ #include static const QString AVATAR_HEAD_AND_BODY_STRING = "Avatar Body with Head"; -static const QString AVATAR_ATTACHEMENT_STRING = "Avatar Attachment"; static const QString ENTITY_MODEL_STRING = "Entity Model"; ModelSelector::ModelSelector() { @@ -27,18 +26,11 @@ ModelSelector::ModelSelector() { setWindowTitle("Select Model"); setLayout(form); - + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); _browseButton = new QPushButton("Browse", this); connect(_browseButton, &QPushButton::clicked, this, &ModelSelector::browse); form->addRow("Model File:", _browseButton); - _modelType = new QComboBox(this); - - _modelType->addItem(AVATAR_HEAD_AND_BODY_STRING); - _modelType->addItem(AVATAR_ATTACHEMENT_STRING); - _modelType->addItem(ENTITY_MODEL_STRING); - form->addRow("Model Type:", _modelType); - QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect(buttons, &QDialogButtonBox::accepted, this, &ModelSelector::accept); connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); @@ -49,19 +41,6 @@ QFileInfo ModelSelector::getFileInfo() const { return _modelFile; } -FSTReader::ModelType ModelSelector::getModelType() const { - QString text = _modelType->currentText(); - -if (text == AVATAR_HEAD_AND_BODY_STRING) { - return FSTReader::HEAD_AND_BODY_MODEL; - } else if (text == AVATAR_ATTACHEMENT_STRING) { - return FSTReader::ATTACHMENT_MODEL; - } else if (text == ENTITY_MODEL_STRING) { - return FSTReader::ENTITY_MODEL; - } - Q_UNREACHABLE(); -} - void ModelSelector::accept() { if (!_modelFile.isFile()) { return; diff --git a/interface/src/ModelSelector.h b/interface/src/ModelSelector.h index ee9e75c17a..5bbeb4665e 100644 --- a/interface/src/ModelSelector.h +++ b/interface/src/ModelSelector.h @@ -29,7 +29,6 @@ public: ModelSelector(); QFileInfo getFileInfo() const; - FSTReader::ModelType getModelType() const; public slots: virtual void accept() override; @@ -40,7 +39,6 @@ public: private: QFileInfo _modelFile; QPushButton* _browseButton; - QComboBox* _modelType; }; #endif // hifi_ModelSelector_h diff --git a/interface/src/SecondaryCamera.cpp b/interface/src/SecondaryCamera.cpp index f99a373259..e71602b271 100644 --- a/interface/src/SecondaryCamera.cpp +++ b/interface/src/SecondaryCamera.cpp @@ -171,7 +171,7 @@ void SecondaryCameraJobConfig::setOrientation(glm::quat orient) { } void SecondaryCameraJobConfig::enableSecondaryCameraRenderConfigs(bool enabled) { - qApp->getRenderEngine()->getConfiguration()->getConfig()->setEnabled(enabled); + qApp->getRenderEngine()->getConfiguration()->getConfig("SecondaryCameraJob")->setEnabled(enabled); setEnabled(enabled); } @@ -187,11 +187,13 @@ public: void run(const render::RenderContextPointer& renderContext, const RenderArgsPointer& cachedArgs) { auto args = renderContext->args; + if (cachedArgs) { args->_blitFramebuffer = cachedArgs->_blitFramebuffer; args->_viewport = cachedArgs->_viewport; - args->popViewFrustum(); args->_displayMode = cachedArgs->_displayMode; args->_renderMode = cachedArgs->_renderMode; + } + args->popViewFrustum(); gpu::doInBatch("EndSecondaryCameraFrame::run", args->_context, [&](gpu::Batch& batch) { batch.restoreContextStereo(); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index bc72c7d7c5..0670252406 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -36,114 +36,6 @@ using namespace std; -void renderWorldBox(RenderArgs* args, gpu::Batch& batch) { - auto geometryCache = DependencyManager::get(); - - // Show center of world - static const glm::vec3 RED(1.0f, 0.0f, 0.0f); - static const glm::vec3 GREEN(0.0f, 1.0f, 0.0f); - static const glm::vec3 BLUE(0.0f, 0.0f, 1.0f); - static const glm::vec3 GREY(0.5f, 0.5f, 0.5f); - static const glm::vec4 GREY4(0.5f, 0.5f, 0.5f, 1.0f); - - static const glm::vec4 DASHED_RED(1.0f, 0.0f, 0.0f, 1.0f); - static const glm::vec4 DASHED_GREEN(0.0f, 1.0f, 0.0f, 1.0f); - static const glm::vec4 DASHED_BLUE(0.0f, 0.0f, 1.0f, 1.0f); - static const float DASH_LENGTH = 1.0f; - static const float GAP_LENGTH = 1.0f; - auto transform = Transform{}; - static std::array geometryIds; - static std::once_flag initGeometryIds; - std::call_once(initGeometryIds, [&] { - for (size_t i = 0; i < geometryIds.size(); ++i) { - geometryIds[i] = geometryCache->allocateID(); - } - }); - - batch.setModelTransform(transform); - - geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(HALF_TREE_SCALE, 0.0f, 0.0f), RED, geometryIds[0]); - geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-HALF_TREE_SCALE, 0.0f, 0.0f), DASHED_RED, - DASH_LENGTH, GAP_LENGTH, geometryIds[1]); - - geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, HALF_TREE_SCALE, 0.0f), GREEN, geometryIds[2]); - geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -HALF_TREE_SCALE, 0.0f), DASHED_GREEN, - DASH_LENGTH, GAP_LENGTH, geometryIds[3]); - - geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, HALF_TREE_SCALE), BLUE, geometryIds[4]); - geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -HALF_TREE_SCALE), DASHED_BLUE, - DASH_LENGTH, GAP_LENGTH, geometryIds[5]); - - // X center boundaries - geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), - glm::vec3(HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), GREY, - geometryIds[6]); - geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), - glm::vec3(-HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), GREY, - geometryIds[7]); - geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), - glm::vec3(HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), GREY, - geometryIds[8]); - geometryCache->renderLine(batch, glm::vec3(HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), - glm::vec3(HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), GREY, - geometryIds[9]); - - // Z center boundaries - geometryCache->renderLine(batch, glm::vec3(0.0f, -HALF_TREE_SCALE, -HALF_TREE_SCALE), - glm::vec3(0.0f, -HALF_TREE_SCALE, HALF_TREE_SCALE), GREY, - geometryIds[10]); - geometryCache->renderLine(batch, glm::vec3(0.0f, -HALF_TREE_SCALE, -HALF_TREE_SCALE), - glm::vec3(0.0f, HALF_TREE_SCALE, -HALF_TREE_SCALE), GREY, - geometryIds[11]); - geometryCache->renderLine(batch, glm::vec3(0.0f, HALF_TREE_SCALE, -HALF_TREE_SCALE), - glm::vec3(0.0f, HALF_TREE_SCALE, HALF_TREE_SCALE), GREY, - geometryIds[12]); - geometryCache->renderLine(batch, glm::vec3(0.0f, -HALF_TREE_SCALE, HALF_TREE_SCALE), - glm::vec3(0.0f, HALF_TREE_SCALE, HALF_TREE_SCALE), GREY, - geometryIds[13]); - - // Center boundaries - geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), - glm::vec3(-HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), GREY, - geometryIds[14]); - geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), - glm::vec3(HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), GREY, - geometryIds[15]); - geometryCache->renderLine(batch, glm::vec3(HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), - glm::vec3(HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), GREY, - geometryIds[16]); - geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), - glm::vec3(HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), GREY, - geometryIds[17]); - - - geometryCache->renderWireCubeInstance(args, batch, GREY4); - - // Draw meter markers along the 3 axis to help with measuring things - const float MARKER_DISTANCE = 1.0f; - const float MARKER_RADIUS = 0.05f; - - transform = Transform().setScale(MARKER_RADIUS); - batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(args, batch, RED); - - transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, 0.0f)).setScale(MARKER_RADIUS); - batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(args, batch, RED); - - transform = Transform().setTranslation(glm::vec3(0.0f, MARKER_DISTANCE, 0.0f)).setScale(MARKER_RADIUS); - batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(args, batch, GREEN); - - transform = Transform().setTranslation(glm::vec3(0.0f, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); - batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(args, batch, BLUE); - - transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); - batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(args, batch, GREY); -} - // Do some basic timing tests and report the results void runTimingTests() { // How long does it take to make a call to get the time? diff --git a/interface/src/Util.h b/interface/src/Util.h index 976a26ce82..ef289f5416 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -15,14 +15,9 @@ #include #include -#include -#include - class ShapeEntityItem; class ShapeInfo; -void renderWorldBox(RenderArgs* args, gpu::Batch& batch); - void runTimingTests(); void runUnitTests(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index afebd0bb79..21a05576fd 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -139,7 +139,7 @@ MyAvatar::MyAvatar(QThread* thread) : _flyingHMDSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "flyingHMD", _flyingPrefHMD), _avatarEntityCountSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" << "size", 0) { - _clientTraitsHandler = std::unique_ptr(new ClientTraitsHandler(this)); + _clientTraitsHandler.reset(new ClientTraitsHandler(this)); // give the pointer to our head to inherited _headData variable from AvatarData _headData = new MyHead(this); @@ -807,46 +807,6 @@ void MyAvatar::simulate(float deltaTime) { // before we perform rig animations and IK. updateSensorToWorldMatrix(); - // if we detect the hand controller is at rest, i.e. lying on the table, or the hand is too far away from the hmd - // disable the associated hand controller input. - { - // NOTE: all poses are in sensor space. - auto leftHandIter = _controllerPoseMap.find(controller::Action::LEFT_HAND); - if (leftHandIter != _controllerPoseMap.end() && leftHandIter->second.isValid()) { - _leftHandAtRestDetector.update(leftHandIter->second.getTranslation(), leftHandIter->second.getRotation()); - if (_leftHandAtRestDetector.isAtRest()) { - leftHandIter->second.valid = false; - } - } else { - _leftHandAtRestDetector.invalidate(); - } - - auto rightHandIter = _controllerPoseMap.find(controller::Action::RIGHT_HAND); - if (rightHandIter != _controllerPoseMap.end() && rightHandIter->second.isValid()) { - _rightHandAtRestDetector.update(rightHandIter->second.getTranslation(), rightHandIter->second.getRotation()); - if (_rightHandAtRestDetector.isAtRest()) { - rightHandIter->second.valid = false; - } - } else { - _rightHandAtRestDetector.invalidate(); - } - - auto headIter = _controllerPoseMap.find(controller::Action::HEAD); - - // The 99th percentile man has a spine to fingertip to height ratio of 0.45. Lets increase that by about 10% to 0.5 - // then measure the distance the center of the eyes to the finger tips. To come up with this ratio. - // From "The Measure of Man and Woman: Human Factors in Design, Revised Edition" by Alvin R. Tilley, Henry Dreyfuss Associates - const float MAX_HEAD_TO_HAND_DISTANCE_RATIO = 0.52f; - - float maxHeadHandDistance = getUserHeight() * MAX_HEAD_TO_HAND_DISTANCE_RATIO; - if (glm::length(headIter->second.getTranslation() - leftHandIter->second.getTranslation()) > maxHeadHandDistance) { - leftHandIter->second.valid = false; - } - if (glm::length(headIter->second.getTranslation() - rightHandIter->second.getTranslation()) > maxHeadHandDistance) { - rightHandIter->second.valid = false; - } - } - { PerformanceTimer perfTimer("skeleton"); diff --git a/interface/src/graphics/GraphicsEngine.cpp b/interface/src/graphics/GraphicsEngine.cpp new file mode 100644 index 0000000000..aecaa74d12 --- /dev/null +++ b/interface/src/graphics/GraphicsEngine.cpp @@ -0,0 +1,301 @@ +// +// GraphicsEngine.cpp +// +// Created by Sam Gateau on 29/6/2018. +// Copyright 2018 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 +// +#include "GraphicsEngine.h" + +#include + +#include "WorldBox.h" +#include "LODManager.h" + +#include +#include +#include +#include +#include +#include + +#include "RenderEventHandler.h" + +#include +#include +#include +#include + +#include +#include +#include "ui/Stats.h" +#include "Application.h" + +GraphicsEngine::GraphicsEngine() { +} + +GraphicsEngine::~GraphicsEngine() { +} + +void GraphicsEngine::initializeGPU(GLWidget* glwidget) { + + _renderEventHandler = new RenderEventHandler( + [this]() { return this->shouldPaint(); }, + [this]() { this->render_performFrame(); } + ); + + // Requires the window context, because that's what's used in the actual rendering + // and the GPU backend will make things like the VAO which cannot be shared across + // contexts + glwidget->makeCurrent(); + gpu::Context::init(); + glwidget->makeCurrent(); + _gpuContext = std::make_shared(); + + DependencyManager::get()->setGPUContext(_gpuContext); +} + +void GraphicsEngine::initializeRender(bool disableDeferred) { + + // Set up the render engine + render::CullFunctor cullFunctor = LODManager::shouldRender; + _renderEngine->addJob("UpdateScene"); +#ifndef Q_OS_ANDROID + _renderEngine->addJob("SecondaryCameraJob", cullFunctor, !disableDeferred); +#endif + _renderEngine->addJob("RenderMainView", cullFunctor, !disableDeferred, render::ItemKey::TAG_BITS_0, render::ItemKey::TAG_BITS_0); + _renderEngine->load(); + _renderEngine->registerScene(_renderScene); + + // Now that OpenGL is initialized, we are sure we have a valid context and can create the various pipeline shaders with success. + DependencyManager::get()->initializeShapePipelines(); +} + +void GraphicsEngine::startup() { + static_cast(_renderEventHandler)->resumeThread(); +} + +void GraphicsEngine::shutdown() { + // The cleanup process enqueues the transactions but does not process them. Calling this here will force the actual + // removal of the items. + // See https://highfidelity.fogbugz.com/f/cases/5328 + _renderScene->enqueueFrame(); // flush all the transactions + _renderScene->processTransactionQueue(); // process and apply deletions + + _gpuContext->shutdown(); + + + // shutdown render engine + _renderScene = nullptr; + _renderEngine = nullptr; + + _renderEventHandler->deleteLater(); +} + + +void GraphicsEngine::render_runRenderFrame(RenderArgs* renderArgs) { + PROFILE_RANGE(render, __FUNCTION__); + PerformanceTimer perfTimer("render"); + + // Make sure the WorldBox is in the scene + // For the record, this one RenderItem is the first one we created and added to the scene. + // We could move that code elsewhere but you know... + if (!render::Item::isValidID(WorldBoxRenderData::_item)) { + render::Transaction transaction; + auto worldBoxRenderData = std::make_shared(); + auto worldBoxRenderPayload = std::make_shared(worldBoxRenderData); + + WorldBoxRenderData::_item = _renderScene->allocateID(); + + transaction.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload); + _renderScene->enqueueTransaction(transaction); + } + + { + _renderEngine->getRenderContext()->args = renderArgs; + _renderEngine->run(); + } +} + +static const unsigned int THROTTLED_SIM_FRAMERATE = 15; +static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE; + + + + +bool GraphicsEngine::shouldPaint() const { + + auto displayPlugin = qApp->getActiveDisplayPlugin(); + +#ifdef DEBUG_PAINT_DELAY + static uint64_t paintDelaySamples{ 0 }; + static uint64_t paintDelayUsecs{ 0 }; + + paintDelayUsecs += displayPlugin->getPaintDelayUsecs(); + + static const int PAINT_DELAY_THROTTLE = 1000; + if (++paintDelaySamples % PAINT_DELAY_THROTTLE == 0) { + qCDebug(interfaceapp).nospace() << + "Paint delay (" << paintDelaySamples << " samples): " << + (float)paintDelaySamples / paintDelayUsecs << "us"; + } +#endif + + // Throttle if requested + //if (displayPlugin->isThrottled() && (_graphicsEngine._renderEventHandler->_lastTimeRendered.elapsed() < THROTTLED_SIM_FRAME_PERIOD_MS)) { + if ( displayPlugin->isThrottled() && + (static_cast(_renderEventHandler)->_lastTimeRendered.elapsed() < THROTTLED_SIM_FRAME_PERIOD_MS)) { + return false; + } + + return true; +} + +bool GraphicsEngine::checkPendingRenderEvent() { + bool expected = false; + return (_renderEventHandler && static_cast(_renderEventHandler)->_pendingRenderEvent.compare_exchange_strong(expected, true)); +} + + + +void GraphicsEngine::render_performFrame() { + // Some plugins process message events, allowing paintGL to be called reentrantly. + + _renderFrameCount++; + + auto lastPaintBegin = usecTimestampNow(); + PROFILE_RANGE_EX(render, __FUNCTION__, 0xff0000ff, (uint64_t)_renderFrameCount); + PerformanceTimer perfTimer("paintGL"); + + DisplayPluginPointer displayPlugin; + { + PROFILE_RANGE(render, "/getActiveDisplayPlugin"); + displayPlugin = qApp->getActiveDisplayPlugin(); + } + + { + PROFILE_RANGE(render, "/pluginBeginFrameRender"); + // If a display plugin loses it's underlying support, it + // needs to be able to signal us to not use it + if (!displayPlugin->beginFrameRender(_renderFrameCount)) { + QMetaObject::invokeMethod(qApp, "updateDisplayMode"); + return; + } + } + + RenderArgs renderArgs; + glm::mat4 HMDSensorPose; + glm::mat4 eyeToWorld; + glm::mat4 sensorToWorld; + + bool isStereo; + glm::mat4 stereoEyeOffsets[2]; + glm::mat4 stereoEyeProjections[2]; + + { + QMutexLocker viewLocker(&_renderArgsMutex); + renderArgs = _appRenderArgs._renderArgs; + + // don't render if there is no context. + if (!_appRenderArgs._renderArgs._context) { + return; + } + + HMDSensorPose = _appRenderArgs._headPose; + eyeToWorld = _appRenderArgs._eyeToWorld; + sensorToWorld = _appRenderArgs._sensorToWorld; + isStereo = _appRenderArgs._isStereo; + for_each_eye([&](Eye eye) { + stereoEyeOffsets[eye] = _appRenderArgs._eyeOffsets[eye]; + stereoEyeProjections[eye] = _appRenderArgs._eyeProjections[eye]; + }); + } + + { + PROFILE_RANGE(render, "/gpuContextReset"); + getGPUContext()->beginFrame(_appRenderArgs._view, HMDSensorPose); + // Reset the gpu::Context Stages + // Back to the default framebuffer; + gpu::doInBatch("Application_render::gpuContextReset", getGPUContext(), [&](gpu::Batch& batch) { + batch.resetStages(); + }); + } + + + { + PROFILE_RANGE(render, "/renderOverlay"); + PerformanceTimer perfTimer("renderOverlay"); + // NOTE: There is no batch associated with this renderArgs + // the ApplicationOverlay class assumes it's viewport is setup to be the device size + renderArgs._viewport = glm::ivec4(0, 0, qApp->getDeviceSize()); + qApp->getApplicationOverlay().renderOverlay(&renderArgs); + } + + { + PROFILE_RANGE(render, "/updateCompositor"); + qApp->getApplicationCompositor().setFrameInfo(_renderFrameCount, eyeToWorld, sensorToWorld); + } + + gpu::FramebufferPointer finalFramebuffer; + QSize finalFramebufferSize; + { + PROFILE_RANGE(render, "/getOutputFramebuffer"); + // Primary rendering pass + auto framebufferCache = DependencyManager::get(); + finalFramebufferSize = framebufferCache->getFrameBufferSize(); + // Final framebuffer that will be handled to the display-plugin + finalFramebuffer = framebufferCache->getFramebuffer(); + } + + { + if (isStereo) { + renderArgs._context->enableStereo(true); + renderArgs._context->setStereoProjections(stereoEyeProjections); + renderArgs._context->setStereoViews(stereoEyeOffsets); + } + + renderArgs._hudOperator = displayPlugin->getHUDOperator(); + renderArgs._hudTexture = qApp->getApplicationOverlay().getOverlayTexture(); + renderArgs._blitFramebuffer = finalFramebuffer; + render_runRenderFrame(&renderArgs); + } + + auto frame = getGPUContext()->endFrame(); + frame->frameIndex = _renderFrameCount; + frame->framebuffer = finalFramebuffer; + frame->framebufferRecycler = [](const gpu::FramebufferPointer& framebuffer) { + auto frameBufferCache = DependencyManager::get(); + if (frameBufferCache) { + frameBufferCache->releaseFramebuffer(framebuffer); + } + }; + // deliver final scene rendering commands to the display plugin + { + PROFILE_RANGE(render, "/pluginOutput"); + PerformanceTimer perfTimer("pluginOutput"); + _renderLoopCounter.increment(); + displayPlugin->submitFrame(frame); + } + + // Reset the framebuffer and stereo state + renderArgs._blitFramebuffer.reset(); + renderArgs._context->enableStereo(false); + + { + auto stats = Stats::getInstance(); + if (stats) { + stats->setRenderDetails(renderArgs._details); + } + } + + uint64_t lastPaintDuration = usecTimestampNow() - lastPaintBegin; + _frameTimingsScriptingInterface.addValue(lastPaintDuration); +} + + +void GraphicsEngine::editRenderArgs(RenderArgsEditor editor) { + QMutexLocker renderLocker(&_renderArgsMutex); + editor(_appRenderArgs); +} diff --git a/interface/src/graphics/GraphicsEngine.h b/interface/src/graphics/GraphicsEngine.h new file mode 100644 index 0000000000..490f5312b5 --- /dev/null +++ b/interface/src/graphics/GraphicsEngine.h @@ -0,0 +1,90 @@ +// +// GraphicsEngine.h +// +// Created by Sam Gateau on 29/6/2018. +// Copyright 2018 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 +// +#ifndef hifi_GraphicsEngine_h +#define hifi_GraphicsEngine_h + +#include +#include +#include + +#include + +#include +#include + +#include "FrameTimingsScriptingInterface.h" + + +struct AppRenderArgs { + render::Args _renderArgs; + glm::mat4 _eyeToWorld; + glm::mat4 _view; + glm::mat4 _eyeOffsets[2]; + glm::mat4 _eyeProjections[2]; + glm::mat4 _headPose; + glm::mat4 _sensorToWorld; + float _sensorToWorldScale{ 1.0f }; + bool _isStereo{ false }; +}; + +using RenderArgsEditor = std::function ; + + +class GraphicsEngine { +public: + GraphicsEngine(); + ~GraphicsEngine(); + + void initializeGPU(GLWidget*); + void initializeRender(bool disableDeferred); + void startup(); + void shutdown(); + + render::ScenePointer getRenderScene() const { return _renderScene; } + render::EnginePointer getRenderEngine() const { return _renderEngine; } + gpu::ContextPointer getGPUContext() const { return _gpuContext; } + + // Same as the one in application + bool shouldPaint() const; + bool checkPendingRenderEvent(); + + size_t getRenderFrameCount() const { return _renderFrameCount; } + float getRenderLoopRate() const { return _renderLoopCounter.rate(); } + + // Feed GRaphics Engine with new frame configuration + void editRenderArgs(RenderArgsEditor editor); + +private: + // Thread specific calls + void render_performFrame(); + void render_runRenderFrame(RenderArgs* renderArgs); + +protected: + + mutable QMutex _renderArgsMutex{ QMutex::Recursive }; + AppRenderArgs _appRenderArgs; + + RateCounter<500> _renderLoopCounter; + + uint32_t _renderFrameCount{ 0 }; + render::ScenePointer _renderScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) }; + render::EnginePointer _renderEngine{ new render::RenderEngine() }; + + gpu::ContextPointer _gpuContext; // initialized during window creation + + QObject* _renderEventHandler{ nullptr }; + friend class RenderEventHandler; + + FrameTimingsScriptingInterface _frameTimingsScriptingInterface; + + friend class Application; +}; + +#endif // hifi_GraphicsEngine_h diff --git a/interface/src/graphics/RenderEventHandler.cpp b/interface/src/graphics/RenderEventHandler.cpp new file mode 100644 index 0000000000..bdb2cae060 --- /dev/null +++ b/interface/src/graphics/RenderEventHandler.cpp @@ -0,0 +1,58 @@ +// +// RenderEventHandler.cpp +// +// Created by Bradley Austin Davis on 29/6/2018. +// Copyright 2018 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 +// +#include "RenderEventHandler.h" + +#include "Application.h" +#include +#include + +#include "CrashHandler.h" + +RenderEventHandler::RenderEventHandler(CheckCall checkCall, RenderCall renderCall) : + _checkCall(checkCall), + _renderCall(renderCall) +{ + // Transfer to a new thread + moveToNewNamedThread(this, "RenderThread", [this](QThread* renderThread) { + hifi::qt::addBlockingForbiddenThread("Render", renderThread); + _lastTimeRendered.start(); + }, std::bind(&RenderEventHandler::initialize, this), QThread::HighestPriority); +} + +void RenderEventHandler::initialize() { + setObjectName("Render"); + PROFILE_SET_THREAD_NAME("Render"); + setCrashAnnotation("render_thread_id", std::to_string((size_t)QThread::currentThreadId())); +} + +void RenderEventHandler::resumeThread() { + _pendingRenderEvent = false; +} + +void RenderEventHandler::render() { + if (_checkCall()) { + _lastTimeRendered.start(); + _renderCall(); + } +} + +bool RenderEventHandler::event(QEvent* event) { + switch ((int)event->type()) { + case ApplicationEvent::Render: + render(); + _pendingRenderEvent.store(false); + return true; + + default: + break; + } + return Parent::event(event); +} + diff --git a/interface/src/graphics/RenderEventHandler.h b/interface/src/graphics/RenderEventHandler.h new file mode 100644 index 0000000000..93f8b548d0 --- /dev/null +++ b/interface/src/graphics/RenderEventHandler.h @@ -0,0 +1,52 @@ +// +// RenderEventHandler.h +// +// Created by Bradley Austin Davis on 29/6/2018. +// Copyright 2018 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 +// +#ifndef hifi_RenderEventHandler_h +#define hifi_RenderEventHandler_h + +#include +#include +#include "gl/OffscreenGLCanvas.h" + +enum ApplicationEvent { + // Execute a lambda function + Lambda = QEvent::User + 1, + // Trigger the next render + Render, + // Trigger the next idle + Idle, +}; + +class RenderEventHandler : public QObject { + using Parent = QObject; + Q_OBJECT +public: + + using CheckCall = std::function ; + using RenderCall = std::function ; + + CheckCall _checkCall; + RenderCall _renderCall; + + RenderEventHandler(CheckCall checkCall, RenderCall renderCall); + + QElapsedTimer _lastTimeRendered; + std::atomic _pendingRenderEvent{ true }; + + void resumeThread(); + +private: + void initialize(); + + void render(); + + bool event(QEvent* event) override; +}; + +#endif // #include hifi_RenderEventHandler_h \ No newline at end of file diff --git a/interface/src/graphics/WorldBox.cpp b/interface/src/graphics/WorldBox.cpp new file mode 100644 index 0000000000..908055e9c6 --- /dev/null +++ b/interface/src/graphics/WorldBox.cpp @@ -0,0 +1,138 @@ +// +// WorldBox.cpp +// +// Created by Sam Gateau on 01/07/2018. +// Copyright 2018 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 +// +#include "WorldBox.h" + +#include "OctreeConstants.h" + +render::ItemID WorldBoxRenderData::_item{ render::Item::INVALID_ITEM_ID }; + + +namespace render { + template <> const ItemKey payloadGetKey(const WorldBoxRenderData::Pointer& stuff) { return ItemKey::Builder::opaqueShape().withTagBits(ItemKey::TAG_BITS_0 | ItemKey::TAG_BITS_1); } + template <> const Item::Bound payloadGetBound(const WorldBoxRenderData::Pointer& stuff) { return Item::Bound(); } + template <> void payloadRender(const WorldBoxRenderData::Pointer& stuff, RenderArgs* args) { + if (Menu::getInstance()->isOptionChecked(MenuOption::WorldAxes)) { + PerformanceTimer perfTimer("worldBox"); + + auto& batch = *args->_batch; + DependencyManager::get()->bindSimpleProgram(batch); + WorldBoxRenderData::renderWorldBox(args, batch); + } + } +} + +void WorldBoxRenderData::renderWorldBox(RenderArgs* args, gpu::Batch& batch) { + auto geometryCache = DependencyManager::get(); + + // Show center of world + static const glm::vec3 RED(1.0f, 0.0f, 0.0f); + static const glm::vec3 GREEN(0.0f, 1.0f, 0.0f); + static const glm::vec3 BLUE(0.0f, 0.0f, 1.0f); + static const glm::vec3 GREY(0.5f, 0.5f, 0.5f); + static const glm::vec4 GREY4(0.5f, 0.5f, 0.5f, 1.0f); + + static const glm::vec4 DASHED_RED(1.0f, 0.0f, 0.0f, 1.0f); + static const glm::vec4 DASHED_GREEN(0.0f, 1.0f, 0.0f, 1.0f); + static const glm::vec4 DASHED_BLUE(0.0f, 0.0f, 1.0f, 1.0f); + static const float DASH_LENGTH = 1.0f; + static const float GAP_LENGTH = 1.0f; + auto transform = Transform{}; + static std::array geometryIds; + static std::once_flag initGeometryIds; + std::call_once(initGeometryIds, [&] { + for (size_t i = 0; i < geometryIds.size(); ++i) { + geometryIds[i] = geometryCache->allocateID(); + } + }); + + batch.setModelTransform(transform); + + geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(HALF_TREE_SCALE, 0.0f, 0.0f), RED, geometryIds[0]); + geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-HALF_TREE_SCALE, 0.0f, 0.0f), DASHED_RED, + DASH_LENGTH, GAP_LENGTH, geometryIds[1]); + + geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, HALF_TREE_SCALE, 0.0f), GREEN, geometryIds[2]); + geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, -HALF_TREE_SCALE, 0.0f), DASHED_GREEN, + DASH_LENGTH, GAP_LENGTH, geometryIds[3]); + + geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, HALF_TREE_SCALE), BLUE, geometryIds[4]); + geometryCache->renderDashedLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, -HALF_TREE_SCALE), DASHED_BLUE, + DASH_LENGTH, GAP_LENGTH, geometryIds[5]); + + // X center boundaries + geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), + glm::vec3(HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), GREY, + geometryIds[6]); + geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), + glm::vec3(-HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), GREY, + geometryIds[7]); + geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), + glm::vec3(HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), GREY, + geometryIds[8]); + geometryCache->renderLine(batch, glm::vec3(HALF_TREE_SCALE, -HALF_TREE_SCALE, 0.0f), + glm::vec3(HALF_TREE_SCALE, HALF_TREE_SCALE, 0.0f), GREY, + geometryIds[9]); + + // Z center boundaries + geometryCache->renderLine(batch, glm::vec3(0.0f, -HALF_TREE_SCALE, -HALF_TREE_SCALE), + glm::vec3(0.0f, -HALF_TREE_SCALE, HALF_TREE_SCALE), GREY, + geometryIds[10]); + geometryCache->renderLine(batch, glm::vec3(0.0f, -HALF_TREE_SCALE, -HALF_TREE_SCALE), + glm::vec3(0.0f, HALF_TREE_SCALE, -HALF_TREE_SCALE), GREY, + geometryIds[11]); + geometryCache->renderLine(batch, glm::vec3(0.0f, HALF_TREE_SCALE, -HALF_TREE_SCALE), + glm::vec3(0.0f, HALF_TREE_SCALE, HALF_TREE_SCALE), GREY, + geometryIds[12]); + geometryCache->renderLine(batch, glm::vec3(0.0f, -HALF_TREE_SCALE, HALF_TREE_SCALE), + glm::vec3(0.0f, HALF_TREE_SCALE, HALF_TREE_SCALE), GREY, + geometryIds[13]); + + // Center boundaries + geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), + glm::vec3(-HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), GREY, + geometryIds[14]); + geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), + glm::vec3(HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), GREY, + geometryIds[15]); + geometryCache->renderLine(batch, glm::vec3(HALF_TREE_SCALE, 0.0f, -HALF_TREE_SCALE), + glm::vec3(HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), GREY, + geometryIds[16]); + geometryCache->renderLine(batch, glm::vec3(-HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), + glm::vec3(HALF_TREE_SCALE, 0.0f, HALF_TREE_SCALE), GREY, + geometryIds[17]); + + + geometryCache->renderWireCubeInstance(args, batch, GREY4); + + // Draw meter markers along the 3 axis to help with measuring things + const float MARKER_DISTANCE = 1.0f; + const float MARKER_RADIUS = 0.05f; + + transform = Transform().setScale(MARKER_RADIUS); + batch.setModelTransform(transform); + geometryCache->renderSolidSphereInstance(args, batch, RED); + + transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, 0.0f)).setScale(MARKER_RADIUS); + batch.setModelTransform(transform); + geometryCache->renderSolidSphereInstance(args, batch, RED); + + transform = Transform().setTranslation(glm::vec3(0.0f, MARKER_DISTANCE, 0.0f)).setScale(MARKER_RADIUS); + batch.setModelTransform(transform); + geometryCache->renderSolidSphereInstance(args, batch, GREEN); + + transform = Transform().setTranslation(glm::vec3(0.0f, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); + batch.setModelTransform(transform); + geometryCache->renderSolidSphereInstance(args, batch, BLUE); + + transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); + batch.setModelTransform(transform); + geometryCache->renderSolidSphereInstance(args, batch, GREY); +} + diff --git a/interface/src/graphics/WorldBox.h b/interface/src/graphics/WorldBox.h new file mode 100644 index 0000000000..114777ba0f --- /dev/null +++ b/interface/src/graphics/WorldBox.h @@ -0,0 +1,43 @@ +// +// WorldBox.h +// +// Created by Sam Gateau on 01/07/2018. +// Copyright 2018 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 +// +#ifndef hifi_WorldBox_h +#define hifi_WorldBox_h + +#include + +#include +#include + +#include +#include +#include "Menu.h" + + + +class WorldBoxRenderData { +public: + typedef render::Payload Payload; + typedef Payload::DataPointer Pointer; + + int _val = 0; + static render::ItemID _item; // unique WorldBoxRenderData + + + + static void renderWorldBox(RenderArgs* args, gpu::Batch& batch); +}; + +namespace render { + template <> const ItemKey payloadGetKey(const WorldBoxRenderData::Pointer& stuff); + template <> const Item::Bound payloadGetBound(const WorldBoxRenderData::Pointer& stuff); + template <> void payloadRender(const WorldBoxRenderData::Pointer& stuff, RenderArgs* args); +} + +#endif // hifi_WorldBox_h \ No newline at end of file diff --git a/interface/src/octree/SafeLanding.cpp b/interface/src/octree/SafeLanding.cpp index db381d5350..9efad22d09 100644 --- a/interface/src/octree/SafeLanding.cpp +++ b/interface/src/octree/SafeLanding.cpp @@ -107,7 +107,7 @@ void SafeLanding::noteReceivedsequenceNumber(int sequenceNumber) { } bool SafeLanding::isLoadSequenceComplete() { - if (isEntityLoadingComplete() && isSequenceNumbersComplete()) { + if ((isEntityLoadingComplete() && isSequenceNumbersComplete()) || qApp->failedToConnectToEntityServer()) { Locker lock(_lock); _initialStart = INVALID_SEQUENCE; _initialEnd = INVALID_SEQUENCE; diff --git a/interface/src/raypick/CollisionPick.cpp b/interface/src/raypick/CollisionPick.cpp index dfb0db1da1..d30f98051e 100644 --- a/interface/src/raypick/CollisionPick.cpp +++ b/interface/src/raypick/CollisionPick.cpp @@ -149,7 +149,7 @@ void CollisionPick::computeShapeInfo(const CollisionRegion& pick, ShapeInfo& sha uint32_t numIndices = (uint32_t)meshPart.triangleIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += TRIANGLE_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.triangleIndices[j]]; @@ -170,7 +170,7 @@ void CollisionPick::computeShapeInfo(const CollisionRegion& pick, ShapeInfo& sha numIndices = (uint32_t)meshPart.quadIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % QUAD_STRIDE == 0); - numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += QUAD_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.quadIndices[j]]; @@ -305,7 +305,7 @@ void CollisionPick::computeShapeInfo(const CollisionRegion& pick, ShapeInfo& sha auto numIndices = meshPart.triangleIndices.count(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices% TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer auto indexItr = meshPart.triangleIndices.cbegin(); while (indexItr != meshPart.triangleIndices.cend()) { diff --git a/interface/src/scripting/KeyboardScriptingInterface.cpp b/interface/src/scripting/KeyboardScriptingInterface.cpp index b26e1ec378..d86bb56e64 100644 --- a/interface/src/scripting/KeyboardScriptingInterface.cpp +++ b/interface/src/scripting/KeyboardScriptingInterface.cpp @@ -32,3 +32,7 @@ void KeyboardScriptingInterface::setPassword(bool password) { void KeyboardScriptingInterface::loadKeyboardFile(const QString& keyboardFile) { DependencyManager::get()->loadKeyboardFile(keyboardFile); } + +bool KeyboardScriptingInterface::getUse3DKeyboard() { + return DependencyManager::get()->getUse3DKeyboard(); +} diff --git a/interface/src/scripting/KeyboardScriptingInterface.h b/interface/src/scripting/KeyboardScriptingInterface.h index 1ab91ea7c3..709dfe01de 100644 --- a/interface/src/scripting/KeyboardScriptingInterface.h +++ b/interface/src/scripting/KeyboardScriptingInterface.h @@ -30,6 +30,7 @@ class KeyboardScriptingInterface : public QObject, public Dependency { Q_OBJECT Q_PROPERTY(bool raised READ isRaised WRITE setRaised) Q_PROPERTY(bool password READ isPassword WRITE setPassword) + Q_PROPERTY(bool use3DKeyboard READ getUse3DKeyboard); public: Q_INVOKABLE void loadKeyboardFile(const QString& string); @@ -39,5 +40,7 @@ private: bool isPassword(); void setPassword(bool password); + + bool getUse3DKeyboard(); }; #endif diff --git a/interface/src/scripting/TestScriptingInterface.cpp b/interface/src/scripting/TestScriptingInterface.cpp index 52f6a3ebc0..a9ba165037 100644 --- a/interface/src/scripting/TestScriptingInterface.cpp +++ b/interface/src/scripting/TestScriptingInterface.cpp @@ -198,4 +198,14 @@ void TestScriptingInterface::setOtherAvatarsReplicaCount(int count) { int TestScriptingInterface::getOtherAvatarsReplicaCount() { return qApp->getOtherAvatarsReplicaCount(); -} \ No newline at end of file +} + +QString TestScriptingInterface::getOperatingSystemType() { +#ifdef Q_OS_WIN + return "WINDOWS"; +#elif defined Q_OS_MAC + return "MACOS"; +#else + return "UNKNOWN"; +#endif +} diff --git a/interface/src/scripting/TestScriptingInterface.h b/interface/src/scripting/TestScriptingInterface.h index 4a1d1a3eeb..26e967c9b5 100644 --- a/interface/src/scripting/TestScriptingInterface.h +++ b/interface/src/scripting/TestScriptingInterface.h @@ -163,6 +163,13 @@ public slots: */ Q_INVOKABLE int getOtherAvatarsReplicaCount(); + /**jsdoc + * Returns the Operating Sytem type + * @function Test.getOperatingSystemType + * @returns {string} "WINDOWS", "MACOS" or "UNKNOWN" + */ + QString getOperatingSystemType(); + private: bool waitForCondition(qint64 maxWaitMs, std::function condition); QString _testResultsLocation; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2fb40c8c30..3579776213 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -55,8 +55,6 @@ ApplicationOverlay::~ApplicationOverlay() { // Renders the overlays either to a texture or to the screen void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) { PROFILE_RANGE(render, __FUNCTION__); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); - buildFramebufferObject(); if (!_overlayFramebuffer) { @@ -83,7 +81,9 @@ void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) { // Now render the overlay components together into a single texture renderDomainConnectionStatusBorder(renderArgs); // renders the connected domain line renderOverlays(renderArgs); // renders Scripts Overlay and AudioScope +#if !defined(DISABLE_QML) renderQmlUi(renderArgs); // renders a unit quad with the QML UI texture, and the text overlays from scripts +#endif }); renderArgs->_batch = nullptr; // so future users of renderArgs don't try to use our batch diff --git a/interface/src/ui/Keyboard.cpp b/interface/src/ui/Keyboard.cpp index 5f83c095c8..d647851a80 100644 --- a/interface/src/ui/Keyboard.cpp +++ b/interface/src/ui/Keyboard.cpp @@ -45,6 +45,7 @@ #include "scripting/HMDScriptingInterface.h" #include "scripting/WindowScriptingInterface.h" #include "scripting/SelectionScriptingInterface.h" +#include "scripting/HMDScriptingInterface.h" #include "DependencyManager.h" #include "raypick/StylusPointer.h" @@ -54,25 +55,25 @@ static const int LEFT_HAND_CONTROLLER_INDEX = 0; static const int RIGHT_HAND_CONTROLLER_INDEX = 1; -static const float MALLET_LENGTH = 0.2f; -static const float MALLET_TOUCH_Y_OFFSET = 0.052f; -static const float MALLET_Y_OFFSET = 0.180f; +static const float MALLET_LENGTH = 0.18f; +static const float MALLET_TOUCH_Y_OFFSET = 0.050f; +static const float MALLET_Y_OFFSET = 0.160f; static const glm::quat MALLET_ROTATION_OFFSET{0.70710678f, 0.0f, -0.70710678f, 0.0f}; -static const glm::vec3 MALLET_MODEL_DIMENSIONS{0.03f, MALLET_LENGTH, 0.03f}; +static const glm::vec3 MALLET_MODEL_DIMENSIONS{0.01f, MALLET_LENGTH, 0.01f}; static const glm::vec3 MALLET_POSITION_OFFSET{0.0f, -MALLET_Y_OFFSET / 2.0f, 0.0f}; static const glm::vec3 MALLET_TIP_OFFSET{0.0f, MALLET_LENGTH - MALLET_TOUCH_Y_OFFSET, 0.0f}; static const glm::vec3 Z_AXIS {0.0f, 0.0f, 1.0f}; -static const glm::vec3 KEYBOARD_TABLET_OFFSET{0.28f, -0.3f, -0.05f}; +static const glm::vec3 KEYBOARD_TABLET_OFFSET{0.30f, -0.38f, -0.04f}; static const glm::vec3 KEYBOARD_TABLET_DEGREES_OFFSET{-45.0f, 0.0f, 0.0f}; static const glm::vec3 KEYBOARD_TABLET_LANDSCAPE_OFFSET{-0.2f, -0.27f, -0.05f}; static const glm::vec3 KEYBOARD_TABLET_LANDSCAPE_DEGREES_OFFSET{-45.0f, 0.0f, -90.0f}; static const glm::vec3 KEYBOARD_AVATAR_OFFSET{-0.6f, 0.3f, -0.7f}; static const glm::vec3 KEYBOARD_AVATAR_DEGREES_OFFSET{0.0f, 180.0f, 0.0f}; -static const QString SOUND_FILE = PathUtils::resourcesUrl() + "sounds/keyboard_key.mp3"; +static const QString SOUND_FILE = PathUtils::resourcesUrl() + "sounds/keyboardPress.mp3"; static const QString MALLET_MODEL_URL = PathUtils::resourcesUrl() + "meshes/drumstick.fbx"; static const float PULSE_STRENGTH = 0.6f; @@ -221,6 +222,7 @@ Keyboard::Keyboard() { auto pointerManager = DependencyManager::get(); auto windowScriptingInterface = DependencyManager::get(); auto myAvatar = DependencyManager::get()->getMyAvatar(); + auto hmdScriptingInterface = DependencyManager::get(); connect(pointerManager.data(), &PointerManager::triggerBeginOverlay, this, &Keyboard::handleTriggerBegin, Qt::QueuedConnection); connect(pointerManager.data(), &PointerManager::triggerContinueOverlay, this, &Keyboard::handleTriggerContinue, Qt::QueuedConnection); connect(pointerManager.data(), &PointerManager::triggerEndOverlay, this, &Keyboard::handleTriggerEnd, Qt::QueuedConnection); @@ -228,6 +230,7 @@ Keyboard::Keyboard() { connect(pointerManager.data(), &PointerManager::hoverEndOverlay, this, &Keyboard::handleHoverEnd, Qt::QueuedConnection); connect(myAvatar.get(), &MyAvatar::sensorToWorldScaleChanged, this, &Keyboard::scaleKeyboard, Qt::QueuedConnection); connect(windowScriptingInterface.data(), &WindowScriptingInterface::domainChanged, [&]() { setRaised(false); }); + connect(hmdScriptingInterface.data(), &HMDScriptingInterface::displayModeChanged, [&]() { setRaised(false); }); } void Keyboard::registerKeyboardHighlighting() { @@ -238,6 +241,17 @@ void Keyboard::registerKeyboardHighlighting() { selection->enableListToScene(KEY_PRESSED_HIGHLIGHT); } +bool Keyboard::getUse3DKeyboard() const { + return _use3DKeyboardLock.resultWithReadLock([&] { + return _use3DKeyboard.get(); + }); +} + +void Keyboard::setUse3DKeyboard(bool use) { + _use3DKeyboardLock.withWriteLock([&] { + _use3DKeyboard.set(use); + }); +} void Keyboard::createKeyboard() { auto pointerManager = DependencyManager::get(); @@ -483,7 +497,7 @@ void Keyboard::handleTriggerBegin(const OverlayID& overlayID, const PointerEvent AudioInjectorOptions audioOptions; audioOptions.localOnly = true; audioOptions.position = keyWorldPosition; - audioOptions.volume = 0.1f; + audioOptions.volume = 0.05f; AudioInjector::playSoundAndDelete(_keySound, audioOptions); @@ -835,8 +849,8 @@ void Keyboard::loadKeyboardFile(const QString& keyboardFile) { _textDisplay = textDisplay; _ignoreItemsLock.withWriteLock([&] { - _itemsToIgnore.push_back(_textDisplay.overlayID); - _itemsToIgnore.push_back(_anchor.overlayID); + _itemsToIgnore.append(_textDisplay.overlayID); + _itemsToIgnore.append(_anchor.overlayID); }); _layerIndex = 0; auto pointerManager = DependencyManager::get(); diff --git a/interface/src/ui/Keyboard.h b/interface/src/ui/Keyboard.h index 18db38b2ae..9c0c8c40f2 100644 --- a/interface/src/ui/Keyboard.h +++ b/interface/src/ui/Keyboard.h @@ -23,6 +23,7 @@ #include #include #include +#include #include "ui/overlays/Overlay.h" @@ -97,6 +98,9 @@ public: bool isPassword() const; void setPassword(bool password); + bool getUse3DKeyboard() const; + void setUse3DKeyboard(bool use); + void loadKeyboardFile(const QString& keyboardFile); QVector getKeysID(); @@ -143,6 +147,9 @@ private: SharedSoundPointer _keySound { nullptr }; std::shared_ptr _layerSwitchTimer { std::make_shared() }; + mutable ReadWriteLockable _use3DKeyboardLock; + Setting::Handle _use3DKeyboard { "use3DKeyboard", true }; + QString _typedCharacters; TextDisplay _textDisplay; Anchor _anchor; diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index da4fdaba44..8edd8ee3a5 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -74,6 +74,7 @@ void OverlayConductor::centerUI() { } void OverlayConductor::update(float dt) { +#if !defined(DISABLE_QML) auto offscreenUi = DependencyManager::get(); if (!offscreenUi) { return; @@ -115,4 +116,5 @@ void OverlayConductor::update(float dt) { if (shouldRecenter && !_suppressedByHead) { centerUI(); } +#endif } diff --git a/interface/src/ui/OverlayConductor.h b/interface/src/ui/OverlayConductor.h index b47e23d28a..6c3732cf3c 100644 --- a/interface/src/ui/OverlayConductor.h +++ b/interface/src/ui/OverlayConductor.h @@ -25,8 +25,10 @@ private: bool headOutsideOverlay() const; bool updateAvatarIsAtRest(); +#if !defined(DISABLE_QML) bool _suppressedByHead { false }; bool _hmdMode { false }; +#endif // used by updateAvatarIsAtRest uint64_t _desiredAtRestTimer { 0 }; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 5f8b191a4f..d1fbe02759 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -24,6 +24,7 @@ #include "Snapshot.h" #include "SnapshotAnimated.h" #include "UserActivityLogger.h" +#include "ui/Keyboard.h" void setupPreferences() { auto preferences = DependencyManager::get(); @@ -119,6 +120,12 @@ void setupPreferences() { preferences->addPreference(new CheckPreference(UI_CATEGORY, "Use reticle cursor instead of arrow", getter, setter)); } + { + auto getter = []()->bool { return DependencyManager::get()->getUse3DKeyboard(); }; + auto setter = [](bool value) { DependencyManager::get()->setUse3DKeyboard(value); }; + preferences->addPreference(new CheckPreference(UI_CATEGORY, "Use Virtual Keyboard", getter, setter)); + } + { auto getter = []()->bool { return qApp->getMiniTabletEnabled(); }; auto setter = [](bool value) { qApp->setMiniTabletEnabled(value); }; diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 7593e12e07..17b0895f47 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -232,11 +232,15 @@ OverlayID Overlays::addOverlay(const QString& type, const QVariant& properties) */ if (type == ImageOverlay::TYPE) { +#if !defined(DISABLE_QML) thisOverlay = Overlay::Pointer(new ImageOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); +#endif } else if (type == Image3DOverlay::TYPE || type == "billboard") { // "billboard" for backwards compatibility thisOverlay = Overlay::Pointer(new Image3DOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); } else if (type == TextOverlay::TYPE) { +#if !defined(DISABLE_QML) thisOverlay = Overlay::Pointer(new TextOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); +#endif } else if (type == Text3DOverlay::TYPE) { thisOverlay = Overlay::Pointer(new Text3DOverlay(), [](Overlay* ptr) { ptr->deleteLater(); }); } else if (type == Shape3DOverlay::TYPE) { @@ -535,7 +539,7 @@ RayToOverlayIntersectionResult Overlays::findRayIntersectionVector(const PickRay bool bestIsFront = false; bool bestIsTablet = false; auto tabletIDs = qApp->getTabletIDs(); - + const QVector keyboardKeysToDiscard = DependencyManager::get()->getKeysID(); QMutexLocker locker(&_mutex); RayToOverlayIntersectionResult result; QMapIterator i(_overlaysWorld); @@ -545,7 +549,8 @@ RayToOverlayIntersectionResult Overlays::findRayIntersectionVector(const PickRay auto thisOverlay = std::dynamic_pointer_cast(i.value()); if ((overlaysToDiscard.size() > 0 && overlaysToDiscard.contains(thisID)) || - (overlaysToInclude.size() > 0 && !overlaysToInclude.contains(thisID))) { + (overlaysToInclude.size() > 0 && !overlaysToInclude.contains(thisID)) || + (keyboardKeysToDiscard.size() > 0 && keyboardKeysToDiscard.contains(thisID))) { continue; } diff --git a/libraries/animation/src/AnimSkeleton.cpp b/libraries/animation/src/AnimSkeleton.cpp index 73a0891fbe..91ca2359b4 100644 --- a/libraries/animation/src/AnimSkeleton.cpp +++ b/libraries/animation/src/AnimSkeleton.cpp @@ -23,11 +23,39 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) { for (auto& joint : hfmModel.joints) { joints.push_back(joint); } - buildSkeletonFromJoints(joints); + buildSkeletonFromJoints(joints, hfmModel.jointRotationOffsets); + + // we make a copy of the inverseBindMatrices in order to prevent mutating the model bind pose + // when we are dealing with a joint offset in the model + for (int i = 0; i < (int)hfmModel.meshes.size(); i++) { + const HFMMesh& mesh = hfmModel.meshes.at(i); + std::vector dummyClustersList; + + for (int j = 0; j < mesh.clusters.size(); j++) { + std::vector bindMatrices; + // cast into a non-const reference, so we can mutate the FBXCluster + HFMCluster& cluster = const_cast(mesh.clusters.at(j)); + + HFMCluster localCluster; + localCluster.jointIndex = cluster.jointIndex; + localCluster.inverseBindMatrix = cluster.inverseBindMatrix; + localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix); + + // if we have a joint offset in the fst file then multiply its inverse by the + // model cluster inverse bind matrix + if (hfmModel.jointRotationOffsets.contains(cluster.jointIndex)) { + AnimPose localOffset(hfmModel.jointRotationOffsets[cluster.jointIndex], glm::vec3()); + localCluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * cluster.inverseBindMatrix; + localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix); + } + dummyClustersList.push_back(localCluster); + } + _clusterBindMatrixOriginalValues.push_back(dummyClustersList); + } } -AnimSkeleton::AnimSkeleton(const std::vector& joints) { - buildSkeletonFromJoints(joints); +AnimSkeleton::AnimSkeleton(const std::vector& joints, const QMap jointOffsets) { + buildSkeletonFromJoints(joints, jointOffsets); } int AnimSkeleton::nameToJointIndex(const QString& jointName) const { @@ -166,7 +194,8 @@ void AnimSkeleton::mirrorAbsolutePoses(AnimPoseVec& poses) const { } } -void AnimSkeleton::buildSkeletonFromJoints(const std::vector& joints) { +void AnimSkeleton::buildSkeletonFromJoints(const std::vector& joints, const QMap jointOffsets) { + _joints = joints; _jointsSize = (int)joints.size(); // build a cache of bind poses @@ -189,7 +218,7 @@ void AnimSkeleton::buildSkeletonFromJoints(const std::vector& joints) // build relative and absolute default poses glm::mat4 relDefaultMat = glm::translate(_joints[i].translation) * preRotationTransform * glm::mat4_cast(_joints[i].rotation) * postRotationTransform; AnimPose relDefaultPose(relDefaultMat); - _relativeDefaultPoses.push_back(relDefaultPose); + int parentIndex = getParentIndex(i); if (parentIndex >= 0) { _absoluteDefaultPoses.push_back(_absoluteDefaultPoses[parentIndex] * relDefaultPose); @@ -198,6 +227,16 @@ void AnimSkeleton::buildSkeletonFromJoints(const std::vector& joints) } } + for (int k = 0; k < _jointsSize; k++) { + if (jointOffsets.contains(k)) { + AnimPose localOffset(jointOffsets[k], glm::vec3()); + _absoluteDefaultPoses[k] = _absoluteDefaultPoses[k] * localOffset; + } + } + // re-compute relative poses + _relativeDefaultPoses = _absoluteDefaultPoses; + convertAbsolutePosesToRelative(_relativeDefaultPoses); + for (int i = 0; i < _jointsSize; i++) { _jointIndicesByName[_joints[i].name] = i; } diff --git a/libraries/animation/src/AnimSkeleton.h b/libraries/animation/src/AnimSkeleton.h index 3a384388d0..14f39eedbc 100644 --- a/libraries/animation/src/AnimSkeleton.h +++ b/libraries/animation/src/AnimSkeleton.h @@ -15,7 +15,7 @@ #include #include -#include +#include #include "AnimPose.h" class AnimSkeleton { @@ -24,7 +24,8 @@ public: using ConstPointer = std::shared_ptr; explicit AnimSkeleton(const HFMModel& hfmModel); - explicit AnimSkeleton(const std::vector& joints); + explicit AnimSkeleton(const std::vector& joints, const QMap jointOffsets); + int nameToJointIndex(const QString& jointName) const; const QString& getJointName(int jointIndex) const; int getNumJoints() const; @@ -62,9 +63,10 @@ public: void dump(const AnimPoseVec& poses) const; std::vector lookUpJointIndices(const std::vector& jointNames) const; + const HFMCluster getClusterBindMatricesOriginalValues(const int meshIndex, const int clusterIndex) const { return _clusterBindMatrixOriginalValues[meshIndex][clusterIndex]; } protected: - void buildSkeletonFromJoints(const std::vector& joints); + void buildSkeletonFromJoints(const std::vector& joints, const QMap jointOffsets); std::vector _joints; int _jointsSize { 0 }; @@ -76,6 +78,7 @@ protected: std::vector _nonMirroredIndices; std::vector _mirrorMap; QHash _jointIndicesByName; + std::vector> _clusterBindMatrixOriginalValues; // no copies AnimSkeleton(const AnimSkeleton&) = delete; diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 501b9e964d..ec26782d0e 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -71,7 +71,7 @@ void AnimationReader::run() { // Parse the FBX directly from the QNetworkReply HFMModel::Pointer hfmModel; if (_url.path().toLower().endsWith(".fbx")) { - hfmModel.reset(readFBX(_data, QVariantHash(), _url.path())); + hfmModel = FBXSerializer().read(_data, QVariantHash(), _url.path()); } else { QString errorStr("usupported format"); emit onError(299, errorStr); diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index 4423e8f18d..d4574d9d3b 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include class Animation; diff --git a/libraries/animation/src/AnimationObject.h b/libraries/animation/src/AnimationObject.h index 83880ed2ab..fc3a351832 100644 --- a/libraries/animation/src/AnimationObject.h +++ b/libraries/animation/src/AnimationObject.h @@ -15,7 +15,7 @@ #include #include -#include +#include class QScriptEngine; diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 8b7b0ba916..128ac05b81 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -360,8 +360,10 @@ void Rig::initJointStates(const HFMModel& hfmModel, const glm::mat4& modelOffset void Rig::reset(const HFMModel& hfmModel) { _geometryOffset = AnimPose(hfmModel.offset); _invGeometryOffset = _geometryOffset.inverse(); + _animSkeleton = std::make_shared(hfmModel); + _internalPoseSet._relativePoses.clear(); _internalPoseSet._relativePoses = _animSkeleton->getRelativeDefaultPoses(); diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 92f7a27853..9bad7e2f45 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -302,7 +302,6 @@ void AudioClient::customDeleter() { #if defined(Q_OS_ANDROID) _shouldRestartInputSetup = false; #endif - stop(); deleteLater(); } diff --git a/libraries/audio/src/AudioDynamics.h b/libraries/audio/src/AudioDynamics.h index 8dbc7a75cc..6bfd249bc9 100644 --- a/libraries/audio/src/AudioDynamics.h +++ b/libraries/audio/src/AudioDynamics.h @@ -51,7 +51,7 @@ #include // convert float to int using round-to-nearest FORCEINLINE static int32_t floatToInt(float x) { - return _mm_cvt_ss2si(_mm_load_ss(&x)); + return _mm_cvt_ss2si(_mm_set_ss(x)); } #else @@ -150,7 +150,7 @@ static const int IEEE754_EXPN_BIAS = 127; // // Peak detection and -log2(x) for float input (mono) // x < 2^(31-LOG2_HEADROOM) returns 0x7fffffff -// x > 2^LOG2_HEADROOM undefined +// x > 2^LOG2_HEADROOM returns 0 // FORCEINLINE static int32_t peaklog2(float* input) { @@ -161,12 +161,12 @@ FORCEINLINE static int32_t peaklog2(float* input) { uint32_t peak = u & IEEE754_FABS_MASK; // split into e and x - 1.0 - int e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; + int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff; - // saturate - if (e > 31) { - return 0x7fffffff; + // saturate when e > 31 or e < 0 + if ((uint32_t)e > 31) { + return 0x7fffffff & ~(e >> 31); } int k = x >> (31 - LOG2_TABBITS); @@ -186,7 +186,7 @@ FORCEINLINE static int32_t peaklog2(float* input) { // // Peak detection and -log2(x) for float input (stereo) // x < 2^(31-LOG2_HEADROOM) returns 0x7fffffff -// x > 2^LOG2_HEADROOM undefined +// x > 2^LOG2_HEADROOM returns 0 // FORCEINLINE static int32_t peaklog2(float* input0, float* input1) { @@ -200,12 +200,12 @@ FORCEINLINE static int32_t peaklog2(float* input0, float* input1) { uint32_t peak = MAX(u0, u1); // split into e and x - 1.0 - int e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; + int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff; - // saturate - if (e > 31) { - return 0x7fffffff; + // saturate when e > 31 or e < 0 + if ((uint32_t)e > 31) { + return 0x7fffffff & ~(e >> 31); } int k = x >> (31 - LOG2_TABBITS); @@ -225,7 +225,7 @@ FORCEINLINE static int32_t peaklog2(float* input0, float* input1) { // // Peak detection and -log2(x) for float input (quad) // x < 2^(31-LOG2_HEADROOM) returns 0x7fffffff -// x > 2^LOG2_HEADROOM undefined +// x > 2^LOG2_HEADROOM returns 0 // FORCEINLINE static int32_t peaklog2(float* input0, float* input1, float* input2, float* input3) { @@ -243,12 +243,12 @@ FORCEINLINE static int32_t peaklog2(float* input0, float* input1, float* input2, uint32_t peak = MAX(MAX(u0, u1), MAX(u2, u3)); // split into e and x - 1.0 - int e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; + int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM; int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff; - // saturate - if (e > 31) { - return 0x7fffffff; + // saturate when e > 31 or e < 0 + if ((uint32_t)e > 31) { + return 0x7fffffff & ~(e >> 31); } int k = x >> (31 - LOG2_TABBITS); diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 4af6e79caf..1581990e0c 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -447,9 +447,9 @@ AudioInjectorPointer AudioInjector::playSound(SharedSoundPointer sound, const A using AudioConstants::AudioSample; using AudioConstants::SAMPLE_RATE; const int standardRate = SAMPLE_RATE; - // limit to 4 octaves - const int pitch = glm::clamp(options.pitch, 1 / 16.0f, 16.0f); - const int resampledRate = SAMPLE_RATE / pitch; + // limit pitch to 4 octaves + const float pitch = glm::clamp(options.pitch, 1 / 16.0f, 16.0f); + const int resampledRate = glm::round(SAMPLE_RATE / pitch); auto audioData = sound->getAudioData(); auto numChannels = audioData->getNumChannels(); @@ -499,9 +499,9 @@ AudioInjectorPointer AudioInjector::playSound(AudioDataPointer audioData, const using AudioConstants::AudioSample; using AudioConstants::SAMPLE_RATE; const int standardRate = SAMPLE_RATE; - // limit to 4 octaves - const int pitch = glm::clamp(options.pitch, 1 / 16.0f, 16.0f); - const int resampledRate = SAMPLE_RATE / pitch; + // limit pitch to 4 octaves + const float pitch = glm::clamp(options.pitch, 1 / 16.0f, 16.0f); + const int resampledRate = glm::round(SAMPLE_RATE / pitch); auto numChannels = audioData->getNumChannels(); auto numFrames = audioData->getNumFrames(); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index d9d4b57c31..40555547e9 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -2103,8 +2103,9 @@ void AvatarData::setJointMappingsFromNetworkReply() { // before we process this update, make sure that the skeleton model URL hasn't changed // since we made the FST request - if (networkReply->url() != _skeletonModelURL) { + if (networkReply->error() != QNetworkReply::NoError || networkReply->url() != _skeletonModelURL) { qCDebug(avatars) << "Refusing to set joint mappings for FST URL that does not match the current URL"; + networkReply->deleteLater(); return; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 36c6ed6c50..7d88cab209 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -1490,7 +1490,7 @@ protected: bool _isClientAvatar { false }; // null unless MyAvatar or ScriptableAvatar sending traits data to mixer - std::unique_ptr _clientTraitsHandler; + std::unique_ptr _clientTraitsHandler; template T readLockWithNamedJointIndex(const QString& name, const T& defaultValue, F f) const { diff --git a/libraries/avatars/src/ClientTraitsHandler.cpp b/libraries/avatars/src/ClientTraitsHandler.cpp index f8247d9e52..a301341a8e 100644 --- a/libraries/avatars/src/ClientTraitsHandler.cpp +++ b/libraries/avatars/src/ClientTraitsHandler.cpp @@ -22,7 +22,7 @@ ClientTraitsHandler::ClientTraitsHandler(AvatarData* owningAvatar) : _owningAvatar(owningAvatar) { auto nodeList = DependencyManager::get(); - QObject::connect(nodeList.data(), &NodeList::nodeAdded, [this](SharedNodePointer addedNode){ + QObject::connect(nodeList.data(), &NodeList::nodeAdded, this, [this](SharedNodePointer addedNode) { if (addedNode->getType() == NodeType::AvatarMixer) { resetForNewMixer(); } diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index cef6c9b900..afaca1dd62 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -27,7 +27,7 @@ #include -#include +#include #include #include "ModelBakingLoggingCategory.h" @@ -187,10 +187,10 @@ void FBXBaker::importScene() { return; } - FBXReader reader; + FBXSerializer fbxSerializer; qCDebug(model_baking) << "Parsing" << _modelURL; - _rootNode = reader._rootNode = reader.parseFBX(&fbxFile); + _rootNode = fbxSerializer._rootNode = fbxSerializer.parseFBX(&fbxFile); #ifdef HIFI_DUMP_FBX { @@ -206,8 +206,8 @@ void FBXBaker::importScene() { } #endif - _hfmModel = reader.extractHFMModel({}, _modelURL.toString()); - _textureContentMap = reader._textureContent; + _hfmModel = fbxSerializer.extractHFMModel({}, _modelURL.toString()); + _textureContentMap = fbxSerializer._textureContent; } void FBXBaker::rewriteAndBakeSceneModels() { @@ -232,7 +232,7 @@ void FBXBaker::rewriteAndBakeSceneModels() { if (objectChild.name == "Geometry") { // TODO Pull this out of _hfmModel instead so we don't have to reprocess it - auto extractedMesh = FBXReader::extractMesh(objectChild, meshIndex, false); + auto extractedMesh = FBXSerializer::extractMesh(objectChild, meshIndex, false); // Callback to get MaterialID GetMaterialIDCallback materialIDcallback = [&extractedMesh](int partIndex) { diff --git a/libraries/baking/src/ModelBaker.cpp b/libraries/baking/src/ModelBaker.cpp index ca352cebae..34f302b501 100644 --- a/libraries/baking/src/ModelBaker.cpp +++ b/libraries/baking/src/ModelBaker.cpp @@ -13,7 +13,6 @@ #include -#include #include #ifdef _WIN32 diff --git a/libraries/baking/src/OBJBaker.cpp b/libraries/baking/src/OBJBaker.cpp index d9f56b393e..5a1239f88f 100644 --- a/libraries/baking/src/OBJBaker.cpp +++ b/libraries/baking/src/OBJBaker.cpp @@ -14,7 +14,7 @@ #include #include -#include "OBJReader.h" +#include "OBJSerializer.h" #include "FBXWriter.h" const double UNIT_SCALE_FACTOR = 100.0; @@ -143,9 +143,10 @@ void OBJBaker::bakeOBJ() { QByteArray objData = objFile.readAll(); - bool combineParts = true; // set true so that OBJReader reads material info from material library - OBJReader reader; - auto geometry = reader.readOBJ(objData, QVariantHash(), combineParts, _modelURL); + OBJSerializer serializer; + QVariantHash mapping; + mapping["combineParts"] = true; // set true so that OBJSerializer reads material info from material library + auto geometry = serializer.read(objData, mapping, _modelURL); // Write OBJ Data as FBX tree nodes createFBXNodeTree(_rootNode, *geometry); @@ -219,7 +220,7 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, HFMModel& hfmModel) { FBXNode materialNode; materialNode.name = MATERIAL_NODE_NAME; if (hfmModel.materials.size() == 1) { - // case when no material information is provided, OBJReader considers it as a single default material + // case when no material information is provided, OBJSerializer considers it as a single default material for (auto& materialID : hfmModel.materials.keys()) { setMaterialNodeProperties(materialNode, materialID, hfmModel); } diff --git a/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf b/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf index e70053dcd9..66acff616c 100644 --- a/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf +++ b/libraries/display-plugins/src/display-plugins/InterleavedSrgbToLinear.slf @@ -14,8 +14,6 @@ void main(void) { ivec2 texCoord = ivec2(floor(varTexCoord0 * vec2(textureData.textureSize))); texCoord.x /= 2; int row = int(floor(gl_FragCoord.y)); - if (row % 2 > 0) { - texCoord.x += (textureData.textureSize.x / 2); - } + texCoord.x += int(row % 2 > 0) * (textureData.textureSize.x / 2); outFragColor = vec4(pow(texelFetch(colorMap, texCoord, 0).rgb, vec3(2.2)), 1.0); } diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 190d4d4104..2d19a745e1 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -534,18 +534,26 @@ void OpenGLDisplayPlugin::updateFrameData() { } std::function OpenGLDisplayPlugin::getHUDOperator() { - return [this](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { - if (_hudPipeline && hudTexture) { + auto hudPipeline = _hudPipeline; + auto hudMirrorPipeline = _mirrorHUDPipeline; + auto hudStereo = isStereo(); + auto hudCompositeFramebufferSize = _compositeFramebuffer->getSize(); + std::array hudEyeViewports; + for_each_eye([&](Eye eye) { + hudEyeViewports[eye] = eyeViewport(eye); + }); + return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { + if (hudPipeline && hudTexture) { batch.enableStereo(false); - batch.setPipeline(mirror ? _mirrorHUDPipeline : _hudPipeline); + batch.setPipeline(mirror ? hudMirrorPipeline : hudPipeline); batch.setResourceTexture(0, hudTexture); - if (isStereo()) { + if (hudStereo) { for_each_eye([&](Eye eye) { - batch.setViewportTransform(eyeViewport(eye)); + batch.setViewportTransform(hudEyeViewports[eye]); batch.draw(gpu::TRIANGLE_STRIP, 4); }); } else { - batch.setViewportTransform(ivec4(uvec2(0), _compositeFramebuffer->getSize())); + batch.setViewportTransform(ivec4(uvec2(0), hudCompositeFramebufferSize)); batch.draw(gpu::TRIANGLE_STRIP, 4); } } diff --git a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf index aad9e71e0e..8b324c81a5 100644 --- a/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf +++ b/libraries/display-plugins/src/display-plugins/SrgbToLinear.slf @@ -9,7 +9,7 @@ layout(location=0) out vec4 outFragColor; float sRGBFloatToLinear(float value) { const float SRGB_ELBOW = 0.04045; - return (value <= SRGB_ELBOW) ? value / 12.92 : pow((value + 0.055) / 1.055, 2.4); + return mix(pow((value + 0.055) / 1.055, 2.4), value / 12.92, float(value <= SRGB_ELBOW)); } vec3 colorToLinearRGB(vec3 srgb) { diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index d76b211ede..321bcc3fd2 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -420,18 +420,26 @@ void HmdDisplayPlugin::HUDRenderer::updatePipeline() { std::function HmdDisplayPlugin::HUDRenderer::render(HmdDisplayPlugin& plugin) { updatePipeline(); - return [this](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { - if (pipeline && hudTexture) { - batch.setPipeline(pipeline); - batch.setInputFormat(format); - gpu::BufferView posView(vertices, VERTEX_OFFSET, vertices->getSize(), VERTEX_STRIDE, format->getAttributes().at(gpu::Stream::POSITION)._element); - gpu::BufferView uvView(vertices, TEXTURE_OFFSET, vertices->getSize(), VERTEX_STRIDE, format->getAttributes().at(gpu::Stream::TEXCOORD)._element); + auto hudPipeline = pipeline; + auto hudFormat = format; + auto hudVertices = vertices; + auto hudIndices = indices; + auto hudUniformBuffer = uniformsBuffer; + auto hudUniforms = uniforms; + auto hudIndexCount = indexCount; + return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { + if (hudPipeline && hudTexture) { + batch.setPipeline(hudPipeline); + + batch.setInputFormat(hudFormat); + gpu::BufferView posView(hudVertices, VERTEX_OFFSET, hudVertices->getSize(), VERTEX_STRIDE, hudFormat->getAttributes().at(gpu::Stream::POSITION)._element); + gpu::BufferView uvView(hudVertices, TEXTURE_OFFSET, hudVertices->getSize(), VERTEX_STRIDE, hudFormat->getAttributes().at(gpu::Stream::TEXCOORD)._element); batch.setInputBuffer(gpu::Stream::POSITION, posView); batch.setInputBuffer(gpu::Stream::TEXCOORD, uvView); - batch.setIndexBuffer(gpu::UINT16, indices, 0); - uniformsBuffer->setSubData(0, uniforms); - batch.setUniformBuffer(0, uniformsBuffer); + batch.setIndexBuffer(gpu::UINT16, hudIndices, 0); + hudUniformBuffer->setSubData(0, hudUniforms); + batch.setUniformBuffer(0, hudUniformBuffer); auto compositorHelper = DependencyManager::get(); glm::mat4 modelTransform = compositorHelper->getUiTransform(); @@ -441,7 +449,7 @@ std::function HmdDis batch.setModelTransform(modelTransform); batch.setResourceTexture(0, hudTexture); - batch.drawIndexed(gpu::TRIANGLES, indexCount); + batch.drawIndexed(gpu::TRIANGLES, hudIndexCount); } }; } diff --git a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp index c607f678b6..6451e873c9 100644 --- a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp @@ -126,7 +126,7 @@ void MaterialEntityRenderer::doRender(RenderArgs* args) { batch.setModelTransform(renderTransform); if (args->_renderMode != render::Args::RenderMode::SHADOW_RENDER_MODE) { - drawMaterial->setTextureTransforms(textureTransform); + drawMaterial->setTextureTransforms(textureTransform, MaterialMappingMode::UV, true); // bind the material RenderPipelines::bindMaterial(drawMaterial, batch, args->_enableTexturing); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 9a68f81b66..2b1d70f4d0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -421,7 +421,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { uint32_t numIndices = (uint32_t)meshPart.triangleIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += TRIANGLE_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.triangleIndices[j]]; @@ -442,7 +442,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { numIndices = (uint32_t)meshPart.quadIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % QUAD_STRIDE == 0); - numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += QUAD_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.quadIndices[j]]; @@ -595,7 +595,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { if (partItr->_topology == graphics::Mesh::TRIANGLES) { // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer auto indexItr = indices.cbegin() + partItr->_startIndex; auto indexEnd = indexItr + numIndices; @@ -652,7 +652,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { if (partItr->_topology == graphics::Mesh::TRIANGLES) { // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices% TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer auto indexItr = indices.cbegin() + partItr->_startIndex; auto indexEnd = indexItr + numIndices; diff --git a/libraries/entities-renderer/src/textured_particle.slv b/libraries/entities-renderer/src/textured_particle.slv index 4d17fe132b..98d25eae2e 100644 --- a/libraries/entities-renderer/src/textured_particle.slv +++ b/libraries/entities-renderer/src/textured_particle.slv @@ -80,10 +80,11 @@ float interpolate3Points(float y1, float y2, float y3, float u) { halfSlope = (y3 - y1) / 2.0f; float slope12 = y2 - y1; float slope23 = y3 - y2; - if (abs(halfSlope) > abs(slope12)) { - halfSlope = slope12; - } else if (abs(halfSlope) > abs(slope23)) { - halfSlope = slope23; + + { + float check = float(abs(halfSlope) > abs(slope12)); + halfSlope = mix(halfSlope, slope12, check); + halfSlope = mix(halfSlope, slope23, (1.0 - check) * float(abs(halfSlope) > abs(slope23))); } } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index c243f772e2..2b7135413d 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -385,6 +385,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_MATERIAL_MAPPING_SCALE, materialMappingScale); CHECK_PROPERTY_CHANGE(PROP_MATERIAL_MAPPING_ROT, materialMappingRot); CHECK_PROPERTY_CHANGE(PROP_MATERIAL_DATA, materialData); + CHECK_PROPERTY_CHANGE(PROP_MATERIAL_REPEAT, materialRepeat); CHECK_PROPERTY_CHANGE(PROP_VISIBLE_IN_SECONDARY_CAMERA, isVisibleInSecondaryCamera); CHECK_PROPERTY_CHANGE(PROP_PARTICLE_SPIN, particleSpin); CHECK_PROPERTY_CHANGE(PROP_SPIN_SPREAD, spinSpread); @@ -754,7 +755,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * Otherwise the property value is parsed as an unsigned integer, specifying the mesh index to modify. Invalid values are * parsed to 0. * @property {string} materialMappingMode="uv" - How the material is mapped to the entity. Either "uv" or - * "projected". Currently, only "uv" is supported. + * "projected". In "uv" mode, the material will be evaluated within the UV space of the mesh it is applied to. In + * "projected" mode, the 3D transform of the Material Entity will be used to evaluate the texture coordinates for the material. * @property {Vec2} materialMappingPos=0,0 - Offset position in UV-space of the top left of the material, range * { x: 0, y: 0 }{ x: 1, y: 1 }. * @property {Vec2} materialMappingScale=1,1 - How much to scale the material within the parent's UV-space. @@ -762,6 +764,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { * @property {string} materialData="" - Used to store {@link MaterialResource} data as a JSON string. You can use * JSON.parse() to parse the string into a JavaScript object which you can manipulate the properties of, and * use JSON.stringify() to convert the object into a string to put in the property. + * @property {boolean} materialRepeat=true - If true, the material will repeat. If false, fragments outside of texCoord 0 - 1 will be discarded. + * Works in both "uv" and "projected" modes. * @example Color a sphere using a Material entity. * var entityID = Entities.addEntity({ * type: "Sphere", @@ -1485,6 +1489,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_MAPPING_SCALE, materialMappingScale); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_MAPPING_ROT, materialMappingRot); COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_DATA, materialData); + COPY_PROPERTY_TO_QSCRIPTVALUE(PROP_MATERIAL_REPEAT, materialRepeat); } /**jsdoc @@ -1666,6 +1671,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object, bool COPY_PROPERTY_FROM_QSCRIPTVALUE(materialMappingScale, vec2, setMaterialMappingScale); COPY_PROPERTY_FROM_QSCRIPTVALUE(materialMappingRot, float, setMaterialMappingRot); COPY_PROPERTY_FROM_QSCRIPTVALUE(materialData, QString, setMaterialData); + COPY_PROPERTY_FROM_QSCRIPTVALUE(materialRepeat, bool, setMaterialRepeat); COPY_PROPERTY_FROM_QSCRIPTVALUE(isVisibleInSecondaryCamera, bool, setIsVisibleInSecondaryCamera); COPY_PROPERTY_FROM_QSCRIPTVALUE(particleSpin, float, setParticleSpin); COPY_PROPERTY_FROM_QSCRIPTVALUE(spinSpread, float, setSpinSpread); @@ -2061,6 +2067,7 @@ void EntityItemProperties::entityPropertyFlagsFromScriptValue(const QScriptValue ADD_PROPERTY_TO_MAP(PROP_MATERIAL_MAPPING_SCALE, MaterialMappingScale, materialMappingScale, vec2); ADD_PROPERTY_TO_MAP(PROP_MATERIAL_MAPPING_ROT, MaterialMappingRot, materialMappingRot, float); ADD_PROPERTY_TO_MAP(PROP_MATERIAL_DATA, MaterialData, materialData, QString); + ADD_PROPERTY_TO_MAP(PROP_MATERIAL_REPEAT, MaterialRepeat, materialRepeat, bool); ADD_PROPERTY_TO_MAP(PROP_VISIBLE_IN_SECONDARY_CAMERA, IsVisibleInSecondaryCamera, isVisibleInSecondaryCamera, bool); @@ -2511,6 +2518,7 @@ OctreeElement::AppendState EntityItemProperties::encodeEntityEditPacket(PacketTy APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_SCALE, properties.getMaterialMappingScale()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_ROT, properties.getMaterialMappingRot()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_DATA, properties.getMaterialData()); + APPEND_ENTITY_PROPERTY(PROP_MATERIAL_REPEAT, properties.getMaterialRepeat()); } APPEND_ENTITY_PROPERTY(PROP_NAME, properties.getName()); @@ -2898,6 +2906,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_MAPPING_SCALE, vec2, setMaterialMappingScale); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_MAPPING_ROT, float, setMaterialMappingRot); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_DATA, QString, setMaterialData); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MATERIAL_REPEAT, bool, setMaterialRepeat); } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NAME, QString, setName); @@ -3137,6 +3146,7 @@ void EntityItemProperties::markAllChanged() { _materialMappingScaleChanged = true; _materialMappingRotChanged = true; _materialDataChanged = true; + _materialRepeatChanged = true; // Certifiable Properties _itemNameChanged = true; @@ -3587,6 +3597,9 @@ QList EntityItemProperties::listChangedProperties() { if (materialDataChanged()) { out += "materialData"; } + if (materialRepeatChanged()) { + out += "materialRepeat"; + } if (isVisibleInSecondaryCameraChanged()) { out += "isVisibleInSecondaryCamera"; } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index c91ccda5aa..87fefb5c1b 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -241,6 +241,7 @@ public: DEFINE_PROPERTY_REF(PROP_MATERIAL_MAPPING_SCALE, MaterialMappingScale, materialMappingScale, glm::vec2, glm::vec2(1.0f)); DEFINE_PROPERTY_REF(PROP_MATERIAL_MAPPING_ROT, MaterialMappingRot, materialMappingRot, float, 0); DEFINE_PROPERTY_REF(PROP_MATERIAL_DATA, MaterialData, materialData, QString, ""); + DEFINE_PROPERTY_REF(PROP_MATERIAL_REPEAT, MaterialRepeat, materialRepeat, bool, true); DEFINE_PROPERTY(PROP_VISIBLE_IN_SECONDARY_CAMERA, IsVisibleInSecondaryCamera, isVisibleInSecondaryCamera, bool, ENTITY_ITEM_DEFAULT_VISIBLE_IN_SECONDARY_CAMERA); diff --git a/libraries/entities/src/EntityPropertyFlags.cpp b/libraries/entities/src/EntityPropertyFlags.cpp index c077b153b8..4f3c35ce0a 100644 --- a/libraries/entities/src/EntityPropertyFlags.cpp +++ b/libraries/entities/src/EntityPropertyFlags.cpp @@ -175,6 +175,7 @@ QDebug& operator<<(QDebug& dbg, const EntityPropertyFlags& f) { result = f.getHasProperty(PROP_MATERIAL_MAPPING_SCALE) ? result + "materialMappingScale " : result; result = f.getHasProperty(PROP_MATERIAL_MAPPING_ROT) ? result + "materialMappingRot " : result; result = f.getHasProperty(PROP_MATERIAL_DATA) ? result + "materialData " : result; + result = f.getHasProperty(PROP_MATERIAL_REPEAT) ? result + "materialRepeat " : result; result = f.getHasProperty(PROP_VISIBLE_IN_SECONDARY_CAMERA) ? result + "visibleInSecondaryCamera " : result; result = f.getHasProperty(PROP_PARTICLE_SPIN) ? result + "particleSpin " : result; result = f.getHasProperty(PROP_SPIN_START) ? result + "spinStart " : result; diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index d2f687fbd3..e6649f74aa 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -275,6 +275,8 @@ enum EntityPropertyList { PROP_GRAB_EQUIPPABLE_INDICATOR_SCALE, PROP_GRAB_EQUIPPABLE_INDICATOR_OFFSET, + PROP_MATERIAL_REPEAT, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties to end of list just ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 3491688588..5487ae33b0 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -486,6 +486,8 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties propertiesWithSimID.setLastEditedBy(sessionID); + propertiesWithSimID.setActionData(QByteArray()); + bool scalesWithParent = propertiesWithSimID.getScalesWithParent(); propertiesWithSimID = convertPropertiesFromScriptSemantics(propertiesWithSimID, scalesWithParent); @@ -830,6 +832,8 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& properties.setClientOnly(entity->getClientOnly()); properties.setOwningAvatarID(entity->getOwningAvatarID()); + properties.setActionData(entity->getDynamicData()); + // make sure the properties has a type, so that the encode can know which properties to include properties.setType(entity->getType()); @@ -954,11 +958,6 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { const QUuid myNodeID = nodeList->getSessionUUID(); if (entity->getClientOnly() && entity->getOwningAvatarID() != myNodeID) { // don't delete other avatar's avatarEntities - // If you actually own the entity but the onwership property is not set because of a domain switch - // The lines below makes sure the entity is deleted once its properties are set. - auto avatarHashMap = DependencyManager::get(); - AvatarSharedPointer myAvatar = avatarHashMap->getAvatarBySessionID(myNodeID); - myAvatar->insertDetachedEntityID(id); shouldSendDeleteToServer = false; return; } diff --git a/libraries/entities/src/MaterialEntityItem.cpp b/libraries/entities/src/MaterialEntityItem.cpp index 825dd83348..cec602a5e1 100644 --- a/libraries/entities/src/MaterialEntityItem.cpp +++ b/libraries/entities/src/MaterialEntityItem.cpp @@ -41,6 +41,7 @@ EntityItemProperties MaterialEntityItem::getProperties(const EntityPropertyFlags COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialMappingScale, getMaterialMappingScale); COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialMappingRot, getMaterialMappingRot); COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialData, getMaterialData); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(materialRepeat, getMaterialRepeat); return properties; } @@ -55,6 +56,7 @@ bool MaterialEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialMappingScale, setMaterialMappingScale); SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialMappingRot, setMaterialMappingRot); SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialData, setMaterialData); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(materialRepeat, setMaterialRepeat); if (somethingChanged) { bool wantDebug = false; @@ -85,6 +87,7 @@ int MaterialEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* da READ_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_SCALE, glm::vec2, setMaterialMappingScale); READ_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_ROT, float, setMaterialMappingRot); READ_ENTITY_PROPERTY(PROP_MATERIAL_DATA, QString, setMaterialData); + READ_ENTITY_PROPERTY(PROP_MATERIAL_REPEAT, bool, setMaterialRepeat); return bytesRead; } @@ -99,6 +102,7 @@ EntityPropertyFlags MaterialEntityItem::getEntityProperties(EncodeBitstreamParam requestedProperties += PROP_MATERIAL_MAPPING_SCALE; requestedProperties += PROP_MATERIAL_MAPPING_ROT; requestedProperties += PROP_MATERIAL_DATA; + requestedProperties += PROP_MATERIAL_REPEAT; return requestedProperties; } @@ -119,6 +123,7 @@ void MaterialEntityItem::appendSubclassData(OctreePacketData* packetData, Encode APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_SCALE, getMaterialMappingScale()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_MAPPING_ROT, getMaterialMappingRot()); APPEND_ENTITY_PROPERTY(PROP_MATERIAL_DATA, getMaterialData()); + APPEND_ENTITY_PROPERTY(PROP_MATERIAL_REPEAT, getMaterialRepeat()); } void MaterialEntityItem::debugDump() const { @@ -128,6 +133,7 @@ void MaterialEntityItem::debugDump() const { qCDebug(entities) << " material url:" << _materialURL; qCDebug(entities) << " current material name:" << _currentMaterialName.c_str(); qCDebug(entities) << " material mapping mode:" << _materialMappingMode; + qCDebug(entities) << " material repeat:" << _materialRepeat; qCDebug(entities) << " priority:" << _priority; qCDebug(entities) << " parent material name:" << _parentMaterialName; qCDebug(entities) << " material mapping pos:" << _materialMappingPos; @@ -140,7 +146,12 @@ void MaterialEntityItem::debugDump() const { } void MaterialEntityItem::setUnscaledDimensions(const glm::vec3& value) { - EntityItem::setUnscaledDimensions(ENTITY_ITEM_DEFAULT_DIMENSIONS); + _desiredDimensions = value; + if (_materialMappingMode == MaterialMappingMode::UV) { + EntityItem::setUnscaledDimensions(ENTITY_ITEM_DEFAULT_DIMENSIONS); + } else if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + EntityItem::setUnscaledDimensions(value); + } } std::shared_ptr MaterialEntityItem::getMaterial() const { @@ -208,6 +219,23 @@ void MaterialEntityItem::setMaterialData(const QString& materialData) { } } +void MaterialEntityItem::setMaterialMappingMode(MaterialMappingMode mode) { + if (_materialMappingMode != mode) { + removeMaterial(); + _materialMappingMode = mode; + setUnscaledDimensions(_desiredDimensions); + applyMaterial(); + } +} + +void MaterialEntityItem::setMaterialRepeat(bool repeat) { + if (_materialRepeat != repeat) { + removeMaterial(); + _materialRepeat = repeat; + applyMaterial(); + } +} + void MaterialEntityItem::setMaterialMappingPos(const glm::vec2& materialMappingPos) { if (_materialMappingPos != materialMappingPos) { removeMaterial(); @@ -256,6 +284,22 @@ void MaterialEntityItem::setParentID(const QUuid& parentID) { } } +void MaterialEntityItem::locationChanged(bool tellPhysics) { + EntityItem::locationChanged(); + if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + removeMaterial(); + applyMaterial(); + } +} + +void MaterialEntityItem::dimensionsChanged() { + EntityItem::dimensionsChanged(); + if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + removeMaterial(); + applyMaterial(); + } +} + void MaterialEntityItem::removeMaterial() { graphics::MaterialPointer material = getMaterial(); if (!material) { @@ -289,11 +333,19 @@ void MaterialEntityItem::applyMaterial() { if (!material || parentID.isNull()) { return; } + Transform textureTransform; - textureTransform.setTranslation(glm::vec3(_materialMappingPos, 0.0f)); - textureTransform.setRotation(glm::vec3(0.0f, 0.0f, glm::radians(_materialMappingRot))); - textureTransform.setScale(glm::vec3(_materialMappingScale, 1.0f)); - material->setTextureTransforms(textureTransform); + if (_materialMappingMode == MaterialMappingMode::UV) { + textureTransform.setTranslation(glm::vec3(_materialMappingPos, 0.0f)); + textureTransform.setRotation(glm::vec3(0.0f, 0.0f, glm::radians(_materialMappingRot))); + textureTransform.setScale(glm::vec3(_materialMappingScale, 1.0f)); + } else if (_materialMappingMode == MaterialMappingMode::PROJECTED) { + textureTransform = getTransform(); + textureTransform.postScale(getUnscaledDimensions()); + // Pass the inverse transform here so we don't need to compute it in the shaders + textureTransform.evalFromRawMatrix(textureTransform.getInverseMatrix()); + } + material->setTextureTransforms(textureTransform, _materialMappingMode, _materialRepeat); graphics::MaterialLayer materialLayer = graphics::MaterialLayer(material, getPriority()); diff --git a/libraries/entities/src/MaterialEntityItem.h b/libraries/entities/src/MaterialEntityItem.h index 8aaa833db9..ba142d7719 100644 --- a/libraries/entities/src/MaterialEntityItem.h +++ b/libraries/entities/src/MaterialEntityItem.h @@ -58,7 +58,10 @@ public: void setCurrentMaterialName(const std::string& currentMaterialName); MaterialMappingMode getMaterialMappingMode() const { return _materialMappingMode; } - void setMaterialMappingMode(MaterialMappingMode mode) { _materialMappingMode = mode; } + void setMaterialMappingMode(MaterialMappingMode mode); + + bool getMaterialRepeat() const { return _materialRepeat; } + void setMaterialRepeat(bool repeat); quint16 getPriority() const { return _priority; } void setPriority(quint16 priority); @@ -80,6 +83,9 @@ public: void setParentID(const QUuid& parentID) override; + void locationChanged(bool tellPhysics) override; + void dimensionsChanged() override; + void applyMaterial(); void removeMaterial(); @@ -104,8 +110,10 @@ private: // emissiveMap, albedoMap (set opacityMap = albedoMap for transparency), metallicMap or specularMap, roughnessMap or glossMap, // normalMap or bumpMap, occlusionMap, lightmapMap (broken, FIXME), scatteringMap (only works if normal mapped) QString _materialURL; - // Type of material. "uv" or "projected". NOT YET IMPLEMENTED, only UV is used + // Type of material. "uv" or "projected". MaterialMappingMode _materialMappingMode { UV }; + bool _materialRepeat { true }; + glm::vec3 _desiredDimensions; // Priority for this material when applying it to its parent. Only the highest priority material will be used. Materials with the same priority are (essentially) randomly sorted. // Base materials that come with models always have priority 0. quint16 _priority { 0 }; diff --git a/libraries/fbx/src/FBX.h b/libraries/fbx/src/FBX.h index 90de82e310..157ca5b282 100644 --- a/libraries/fbx/src/FBX.h +++ b/libraries/fbx/src/FBX.h @@ -33,7 +33,7 @@ using NormalType = glm::vec3; #define FBX_NORMAL_ELEMENT gpu::Element::VEC3F_XYZ #endif -// See comment in FBXReader::parseFBX(). +// See comment in FBXSerializer::parseFBX(). static const int FBX_HEADER_BYTES_BEFORE_VERSION = 23; static const QByteArray FBX_BINARY_PROLOG("Kaydara FBX Binary "); static const QByteArray FBX_BINARY_PROLOG2("\0\x1a\0", 3); diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXSerializer.cpp similarity index 96% rename from libraries/fbx/src/FBXReader.cpp rename to libraries/fbx/src/FBXSerializer.cpp index d5a372e093..a9887cde15 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1,6 +1,6 @@ // -// FBXReader.cpp -// interface/src/renderer +// FBXSerializer.cpp +// libraries/fbx/src // // Created by Andrzej Kapolka on 9/18/13. // Copyright 2013 High Fidelity, Inc. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -36,7 +36,7 @@ #include // TOOL: Uncomment the following line to enable the filtering of all the unkwnon fields of a node so we can break point easily while loading a model with problems... -//#define DEBUG_FBXREADER +//#define DEBUG_FBXSERIALIZER using namespace std; @@ -254,13 +254,13 @@ HFMBlendshape extractBlendshape(const FBXNode& object) { HFMBlendshape blendshape; foreach (const FBXNode& data, object.children) { if (data.name == "Indexes") { - blendshape.indices = FBXReader::getIntVector(data); + blendshape.indices = FBXSerializer::getIntVector(data); } else if (data.name == "Vertices") { - blendshape.vertices = FBXReader::createVec3Vector(FBXReader::getDoubleVector(data)); + blendshape.vertices = FBXSerializer::createVec3Vector(FBXSerializer::getDoubleVector(data)); } else if (data.name == "Normals") { - blendshape.normals = FBXReader::createVec3Vector(FBXReader::getDoubleVector(data)); + blendshape.normals = FBXSerializer::createVec3Vector(FBXSerializer::getDoubleVector(data)); } } return blendshape; @@ -384,7 +384,7 @@ HFMLight extractLight(const FBXNode& object) { if (propname == "Intensity") { light.intensity = 0.01f * property.properties.at(valIndex).value(); } else if (propname == "Color") { - light.color = FBXReader::getVec3(property.properties, valIndex); + light.color = FBXSerializer::getVec3(property.properties, valIndex); } } } @@ -392,7 +392,7 @@ HFMLight extractLight(const FBXNode& object) { || subobject.name == "TypeFlags") { } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) QString type = object.properties.at(0).toString(); type = object.properties.at(1).toString(); @@ -417,7 +417,31 @@ QByteArray fileOnUrl(const QByteArray& filepath, const QString& url) { return filepath.mid(filepath.lastIndexOf('/') + 1); } -HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& url) { +QMap getJointRotationOffsets(const QVariantHash& mapping) { + QMap jointRotationOffsets; + static const QString JOINT_ROTATION_OFFSET_FIELD = "jointRotationOffset"; + if (!mapping.isEmpty() && mapping.contains(JOINT_ROTATION_OFFSET_FIELD) && mapping[JOINT_ROTATION_OFFSET_FIELD].type() == QVariant::Hash) { + auto offsets = mapping[JOINT_ROTATION_OFFSET_FIELD].toHash(); + for (auto itr = offsets.begin(); itr != offsets.end(); itr++) { + QString jointName = itr.key(); + QString line = itr.value().toString(); + auto quatCoords = line.split(','); + if (quatCoords.size() == 4) { + float quatX = quatCoords[0].mid(1).toFloat(); + float quatY = quatCoords[1].toFloat(); + float quatZ = quatCoords[2].toFloat(); + float quatW = quatCoords[3].mid(0, quatCoords[3].size() - 1).toFloat(); + if (!isNaN(quatX) && !isNaN(quatY) && !isNaN(quatZ) && !isNaN(quatW)) { + glm::quat rotationOffset = glm::quat(quatW, quatX, quatY, quatZ); + jointRotationOffsets.insert(jointName, rotationOffset); + } + } + } + } + return jointRotationOffsets; +} + +HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QString& url) { const FBXNode& node = _rootNode; QMap meshes; QHash modelIDsToNames; @@ -488,7 +512,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } QMultiHash blendshapeChannelIndices; -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) int unknown = 0; #endif HFMModel* hfmModelPtr = new HFMModel; @@ -736,7 +760,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& extractBlendshape(subobject) }; blendshapes.append(blendshape); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else if (subobject.name == "TypeFlags") { QString attributetype = subobject.properties.at(0).toString(); if (!attributetype.empty()) { @@ -862,7 +886,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& tex.scaling.z = 1.0f; } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString propName = v; unknown++; @@ -871,7 +895,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { if (subobject.name == "Type") { } else if (subobject.name == "Version") { @@ -1044,7 +1068,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString propname = subobject.name.data(); int unknown = 0; @@ -1061,7 +1085,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } else if (object.name == "NodeAttribute") { -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) std::vector properties; foreach(const QVariant& v, object.properties) { properties.push_back(v.toString()); @@ -1124,7 +1148,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& animationCurves.insert(getID(object.properties), curve); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString objectname = object.name.data(); if ( objectname == "Pose" @@ -1215,7 +1239,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString objectname = child.name.data(); if ( objectname == "Pose" @@ -1793,20 +1817,27 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } } + + auto offsets = getJointRotationOffsets(mapping); + hfmModel.jointRotationOffsets.clear(); + for (auto itr = offsets.begin(); itr != offsets.end(); itr++) { + QString jointName = itr.key(); + glm::quat rotationOffset = itr.value(); + int jointIndex = hfmModel.getJointIndex(jointName); + if (jointIndex != -1) { + hfmModel.jointRotationOffsets.insert(jointIndex, rotationOffset); + } + qCDebug(modelformat) << "Joint Rotation Offset added to Rig._jointRotationOffsets : " << " jointName: " << jointName << " jointIndex: " << jointIndex << " rotation offset: " << rotationOffset; + } + return hfmModelPtr; } -HFMModel* readFBX(const QByteArray& data, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { +HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { QBuffer buffer(const_cast(&data)); buffer.open(QIODevice::ReadOnly); - return readFBX(&buffer, mapping, url, loadLightmaps, lightmapLevel); -} -HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { - FBXReader reader; - reader._rootNode = FBXReader::parseFBX(device); - reader._loadLightmaps = loadLightmaps; - reader._lightmapLevel = lightmapLevel; + _rootNode = parseFBX(&buffer); - return reader.extractHFMModel(mapping, url); + return HFMModel::Pointer(extractHFMModel(mapping, url.toString())); } diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXSerializer.h similarity index 85% rename from libraries/fbx/src/FBXReader.h rename to libraries/fbx/src/FBXSerializer.h index c74b4dc8ac..c69f75cc5c 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -1,6 +1,6 @@ // -// FBXReader.h -// interface/src/renderer +// FBXSerializer.h +// libraries/fbx/src // // Created by Andrzej Kapolka on 9/18/13. // Copyright 2013 High Fidelity, Inc. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_FBXReader_h -#define hifi_FBXReader_h +#ifndef hifi_FBXSerializer_h +#define hifi_FBXSerializer_h #include #include @@ -27,7 +27,7 @@ #include #include "FBX.h" -#include +#include #include #include @@ -35,14 +35,6 @@ class QIODevice; class FBXNode; -/// Reads HFMModel from the supplied model and mapping data. -/// \exception QString if an error occurs in parsing -HFMModel* readFBX(const QByteArray& data, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f); - -/// Reads HFMModel from the supplied model and mapping data. -/// \exception QString if an error occurs in parsing -HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f); - class TextureParam { public: glm::vec2 UVTranslation; @@ -102,9 +94,12 @@ public: class ExtractedMesh; -class FBXReader { +class FBXSerializer : public HFMSerializer { public: HFMModel* _hfmModel; + /// Reads HFMModel from the supplied model and mapping data. + /// \exception QString if an error occurs in parsing + HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; FBXNode _rootNode; static FBXNode parseFBX(QIODevice* device); @@ -147,9 +142,9 @@ public: void consolidateHFMMaterials(const QVariantHash& mapping); - bool _loadLightmaps = true; - float _lightmapOffset = 0.0f; - float _lightmapLevel; + bool _loadLightmaps { true }; + float _lightmapOffset { 0.0f }; + float _lightmapLevel { 1.0f }; QMultiMap _connectionParentMap; QMultiMap _connectionChildMap; @@ -166,4 +161,4 @@ public: static QVector getDoubleVector(const FBXNode& node); }; -#endif // hifi_FBXReader_h +#endif // hifi_FBXSerializer_h diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXSerializer_Material.cpp similarity index 98% rename from libraries/fbx/src/FBXReader_Material.cpp rename to libraries/fbx/src/FBXSerializer_Material.cpp index 2ec8cfde75..7713b36e57 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXSerializer_Material.cpp @@ -1,5 +1,5 @@ // -// FBXReader_Material.cpp +// FBXSerializer_Material.cpp // interface/src/fbx // // Created by Sam Gateau on 8/27/2015. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -27,7 +27,7 @@ #include -HFMTexture FBXReader::getTexture(const QString& textureID) { +HFMTexture FBXSerializer::getTexture(const QString& textureID) { HFMTexture texture; const QByteArray& filepath = _textureFilepaths.value(textureID); texture.content = _textureContent.value(filepath); @@ -69,7 +69,7 @@ HFMTexture FBXReader::getTexture(const QString& textureID) { return texture; } -void FBXReader::consolidateHFMMaterials(const QVariantHash& mapping) { +void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { QString materialMapString = mapping.value("materialMap").toString(); QJsonDocument materialMapDocument = QJsonDocument::fromJson(materialMapString.toUtf8()); diff --git a/libraries/fbx/src/FBXReader_Mesh.cpp b/libraries/fbx/src/FBXSerializer_Mesh.cpp similarity index 98% rename from libraries/fbx/src/FBXReader_Mesh.cpp rename to libraries/fbx/src/FBXSerializer_Mesh.cpp index 527e3aef75..38533dbc42 100644 --- a/libraries/fbx/src/FBXReader_Mesh.cpp +++ b/libraries/fbx/src/FBXSerializer_Mesh.cpp @@ -1,5 +1,5 @@ // -// FBXReader_Mesh.cpp +// FBXSerializer_Mesh.cpp // interface/src/fbx // // Created by Sam Gateau on 8/27/2015. @@ -33,7 +33,7 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" #include @@ -191,7 +191,7 @@ void appendIndex(MeshData& data, QVector& indices, int index, bool deduplic } } -ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIndex, bool deduplicate) { +ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& meshIndex, bool deduplicate) { MeshData data; data.extracted.mesh.meshIndex = meshIndex++; @@ -254,7 +254,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn data.colorsByVertex = true; } -#if defined(FBXREADER_KILL_BLACK_COLOR_ATTRIBUTE) +#if defined(FBXSERIALIZER_KILL_BLACK_COLOR_ATTRIBUTE) // Potential feature where we decide to kill the color attribute is to dark? // Tested with the model: // https://hifi-public.s3.amazonaws.com/ryan/gardenLight2.fbx @@ -281,7 +281,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn } else if (subdata.name == "Name") { attrib.name = subdata.properties.at(0).toString(); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { int unknown = 0; QString subname = subdata.name.data(); @@ -307,7 +307,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn } else if (subdata.name == "Name") { attrib.name = subdata.properties.at(0).toString(); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { int unknown = 0; QString subname = subdata.name.data(); @@ -557,7 +557,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn return data.extracted; } -glm::vec3 FBXReader::normalizeDirForPacking(const glm::vec3& dir) { +glm::vec3 FBXSerializer::normalizeDirForPacking(const glm::vec3& dir) { auto maxCoord = glm::max(fabsf(dir.x), glm::max(fabsf(dir.y), fabsf(dir.z))); if (maxCoord > 1e-6f) { return dir / maxCoord; @@ -565,7 +565,7 @@ glm::vec3 FBXReader::normalizeDirForPacking(const glm::vec3& dir) { return dir; } -void FBXReader::buildModelMesh(HFMMesh& extractedMesh, const QString& url) { +void FBXSerializer::buildModelMesh(HFMMesh& extractedMesh, const QString& url) { unsigned int totalSourceIndices = 0; foreach(const HFMMeshPart& part, extractedMesh.parts) { totalSourceIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size()); diff --git a/libraries/fbx/src/FBXReader_Node.cpp b/libraries/fbx/src/FBXSerializer_Node.cpp similarity index 94% rename from libraries/fbx/src/FBXReader_Node.cpp rename to libraries/fbx/src/FBXSerializer_Node.cpp index cd717998dd..c982dfc7cb 100644 --- a/libraries/fbx/src/FBXReader_Node.cpp +++ b/libraries/fbx/src/FBXSerializer_Node.cpp @@ -1,5 +1,5 @@ // -// FBXReader_Node.cpp +// FBXSerializer_Node.cpp // interface/src/fbx // // Created by Sam Gateau on 8/27/2015. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -345,7 +345,7 @@ FBXNode parseTextFBXNode(Tokenizer& tokenizer) { return node; } -FBXNode FBXReader::parseFBX(QIODevice* device) { +FBXNode FBXSerializer::parseFBX(QIODevice* device) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xff0000ff, device); // verify the prolog if (device->peek(FBX_BINARY_PROLOG.size()) != FBX_BINARY_PROLOG) { @@ -398,12 +398,12 @@ FBXNode FBXReader::parseFBX(QIODevice* device) { } -glm::vec3 FBXReader::getVec3(const QVariantList& properties, int index) { +glm::vec3 FBXSerializer::getVec3(const QVariantList& properties, int index) { return glm::vec3(properties.at(index).value(), properties.at(index + 1).value(), properties.at(index + 2).value()); } -QVector FBXReader::createVec4Vector(const QVector& doubleVector) { +QVector FBXSerializer::createVec4Vector(const QVector& doubleVector) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 4) * 4); it != end; ) { float x = *it++; @@ -416,7 +416,7 @@ QVector FBXReader::createVec4Vector(const QVector& doubleVect } -QVector FBXReader::createVec4VectorRGBA(const QVector& doubleVector, glm::vec4& average) { +QVector FBXSerializer::createVec4VectorRGBA(const QVector& doubleVector, glm::vec4& average) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 4) * 4); it != end; ) { float x = *it++; @@ -433,7 +433,7 @@ QVector FBXReader::createVec4VectorRGBA(const QVector& double return values; } -QVector FBXReader::createVec3Vector(const QVector& doubleVector) { +QVector FBXSerializer::createVec3Vector(const QVector& doubleVector) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 3) * 3); it != end; ) { float x = *it++; @@ -444,7 +444,7 @@ QVector FBXReader::createVec3Vector(const QVector& doubleVect return values; } -QVector FBXReader::createVec2Vector(const QVector& doubleVector) { +QVector FBXSerializer::createVec2Vector(const QVector& doubleVector) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 2) * 2); it != end; ) { float s = *it++; @@ -454,14 +454,14 @@ QVector FBXReader::createVec2Vector(const QVector& doubleVect return values; } -glm::mat4 FBXReader::createMat4(const QVector& doubleVector) { +glm::mat4 FBXSerializer::createMat4(const QVector& doubleVector) { return glm::mat4(doubleVector.at(0), doubleVector.at(1), doubleVector.at(2), doubleVector.at(3), doubleVector.at(4), doubleVector.at(5), doubleVector.at(6), doubleVector.at(7), doubleVector.at(8), doubleVector.at(9), doubleVector.at(10), doubleVector.at(11), doubleVector.at(12), doubleVector.at(13), doubleVector.at(14), doubleVector.at(15)); } -QVector FBXReader::getIntVector(const FBXNode& node) { +QVector FBXSerializer::getIntVector(const FBXNode& node) { foreach (const FBXNode& child, node.children) { if (child.name == "a") { return getIntVector(child); @@ -480,7 +480,7 @@ QVector FBXReader::getIntVector(const FBXNode& node) { return vector; } -QVector FBXReader::getFloatVector(const FBXNode& node) { +QVector FBXSerializer::getFloatVector(const FBXNode& node) { foreach (const FBXNode& child, node.children) { if (child.name == "a") { return getFloatVector(child); @@ -499,7 +499,7 @@ QVector FBXReader::getFloatVector(const FBXNode& node) { return vector; } -QVector FBXReader::getDoubleVector(const FBXNode& node) { +QVector FBXSerializer::getDoubleVector(const FBXNode& node) { foreach (const FBXNode& child, node.children) { if (child.name == "a") { return getDoubleVector(child); diff --git a/libraries/fbx/src/GLTFReader.cpp b/libraries/fbx/src/GLTFSerializer.cpp similarity index 93% rename from libraries/fbx/src/GLTFReader.cpp rename to libraries/fbx/src/GLTFSerializer.cpp index eb763cce90..28d377c605 100644 --- a/libraries/fbx/src/GLTFReader.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1,5 +1,5 @@ // -// GLTFReader.cpp +// GLTFSerializer.cpp // libraries/fbx/src // // Created by Luis Cuenca on 8/30/17. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "GLTFReader.h" +#include "GLTFSerializer.h" #include #include @@ -33,14 +33,14 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" -GLTFReader::GLTFReader() { +GLTFSerializer::GLTFSerializer() { } -bool GLTFReader::getStringVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getStringVal(const QJsonObject& object, const QString& fieldname, QString& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isString()); if (_defined) { @@ -50,7 +50,7 @@ bool GLTFReader::getStringVal(const QJsonObject& object, const QString& fieldnam return _defined; } -bool GLTFReader::getBoolVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getBoolVal(const QJsonObject& object, const QString& fieldname, bool& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isBool()); if (_defined) { @@ -60,7 +60,7 @@ bool GLTFReader::getBoolVal(const QJsonObject& object, const QString& fieldname, return _defined; } -bool GLTFReader::getIntVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getIntVal(const QJsonObject& object, const QString& fieldname, int& value, QMap& defined) { bool _defined = (object.contains(fieldname) && !object[fieldname].isNull()); if (_defined) { @@ -70,7 +70,7 @@ bool GLTFReader::getIntVal(const QJsonObject& object, const QString& fieldname, return _defined; } -bool GLTFReader::getDoubleVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getDoubleVal(const QJsonObject& object, const QString& fieldname, double& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isDouble()); if (_defined) { @@ -79,7 +79,7 @@ bool GLTFReader::getDoubleVal(const QJsonObject& object, const QString& fieldnam defined.insert(fieldname, _defined); return _defined; } -bool GLTFReader::getObjectVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getObjectVal(const QJsonObject& object, const QString& fieldname, QJsonObject& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isObject()); if (_defined) { @@ -89,7 +89,7 @@ bool GLTFReader::getObjectVal(const QJsonObject& object, const QString& fieldnam return _defined; } -bool GLTFReader::getIntArrayVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getIntArrayVal(const QJsonObject& object, const QString& fieldname, QVector& values, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isArray()); if (_defined) { @@ -104,7 +104,7 @@ bool GLTFReader::getIntArrayVal(const QJsonObject& object, const QString& fieldn return _defined; } -bool GLTFReader::getDoubleArrayVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getDoubleArrayVal(const QJsonObject& object, const QString& fieldname, QVector& values, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isArray()); if (_defined) { @@ -119,7 +119,7 @@ bool GLTFReader::getDoubleArrayVal(const QJsonObject& object, const QString& fie return _defined; } -bool GLTFReader::getObjectArrayVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getObjectArrayVal(const QJsonObject& object, const QString& fieldname, QJsonArray& objects, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isArray()); if (_defined) { @@ -129,7 +129,7 @@ bool GLTFReader::getObjectArrayVal(const QJsonObject& object, const QString& fie return _defined; } -int GLTFReader::getMeshPrimitiveRenderingMode(const QString& type) +int GLTFSerializer::getMeshPrimitiveRenderingMode(const QString& type) { if (type == "POINTS") { return GLTFMeshPrimitivesRenderingMode::POINTS; @@ -155,7 +155,7 @@ int GLTFReader::getMeshPrimitiveRenderingMode(const QString& type) return GLTFMeshPrimitivesRenderingMode::TRIANGLES; } -int GLTFReader::getAccessorType(const QString& type) +int GLTFSerializer::getAccessorType(const QString& type) { if (type == "SCALAR") { return GLTFAccessorType::SCALAR; @@ -181,7 +181,7 @@ int GLTFReader::getAccessorType(const QString& type) return GLTFAccessorType::SCALAR; } -int GLTFReader::getMaterialAlphaMode(const QString& type) +int GLTFSerializer::getMaterialAlphaMode(const QString& type) { if (type == "OPAQUE") { return GLTFMaterialAlphaMode::OPAQUE; @@ -195,7 +195,7 @@ int GLTFReader::getMaterialAlphaMode(const QString& type) return GLTFMaterialAlphaMode::OPAQUE; } -int GLTFReader::getCameraType(const QString& type) +int GLTFSerializer::getCameraType(const QString& type) { if (type == "orthographic") { return GLTFCameraTypes::ORTHOGRAPHIC; @@ -206,7 +206,7 @@ int GLTFReader::getCameraType(const QString& type) return GLTFCameraTypes::PERSPECTIVE; } -int GLTFReader::getImageMimeType(const QString& mime) +int GLTFSerializer::getImageMimeType(const QString& mime) { if (mime == "image/jpeg") { return GLTFImageMimetype::JPEG; @@ -217,7 +217,7 @@ int GLTFReader::getImageMimeType(const QString& mime) return GLTFImageMimetype::JPEG; } -int GLTFReader::getAnimationSamplerInterpolation(const QString& interpolation) +int GLTFSerializer::getAnimationSamplerInterpolation(const QString& interpolation) { if (interpolation == "LINEAR") { return GLTFAnimationSamplerInterpolation::LINEAR; @@ -225,7 +225,7 @@ int GLTFReader::getAnimationSamplerInterpolation(const QString& interpolation) return GLTFAnimationSamplerInterpolation::LINEAR; } -bool GLTFReader::setAsset(const QJsonObject& object) { +bool GLTFSerializer::setAsset(const QJsonObject& object) { QJsonObject jsAsset; bool isAssetDefined = getObjectVal(object, "asset", jsAsset, _file.defined); if (isAssetDefined) { @@ -239,7 +239,7 @@ bool GLTFReader::setAsset(const QJsonObject& object) { return isAssetDefined; } -bool GLTFReader::addAccessor(const QJsonObject& object) { +bool GLTFSerializer::addAccessor(const QJsonObject& object) { GLTFAccessor accessor; getIntVal(object, "bufferView", accessor.bufferView, accessor.defined); @@ -259,7 +259,7 @@ bool GLTFReader::addAccessor(const QJsonObject& object) { return true; } -bool GLTFReader::addAnimation(const QJsonObject& object) { +bool GLTFSerializer::addAnimation(const QJsonObject& object) { GLTFAnimation animation; QJsonArray channels; @@ -297,7 +297,7 @@ bool GLTFReader::addAnimation(const QJsonObject& object) { return true; } -bool GLTFReader::addBufferView(const QJsonObject& object) { +bool GLTFSerializer::addBufferView(const QJsonObject& object) { GLTFBufferView bufferview; getIntVal(object, "buffer", bufferview.buffer, bufferview.defined); @@ -310,7 +310,7 @@ bool GLTFReader::addBufferView(const QJsonObject& object) { return true; } -bool GLTFReader::addBuffer(const QJsonObject& object) { +bool GLTFSerializer::addBuffer(const QJsonObject& object) { GLTFBuffer buffer; getIntVal(object, "byteLength", buffer.byteLength, buffer.defined); @@ -324,7 +324,7 @@ bool GLTFReader::addBuffer(const QJsonObject& object) { return true; } -bool GLTFReader::addCamera(const QJsonObject& object) { +bool GLTFSerializer::addCamera(const QJsonObject& object) { GLTFCamera camera; QJsonObject jsPerspective; @@ -352,7 +352,7 @@ bool GLTFReader::addCamera(const QJsonObject& object) { return true; } -bool GLTFReader::addImage(const QJsonObject& object) { +bool GLTFSerializer::addImage(const QJsonObject& object) { GLTFImage image; QString mime; @@ -367,7 +367,7 @@ bool GLTFReader::addImage(const QJsonObject& object) { return true; } -bool GLTFReader::getIndexFromObject(const QJsonObject& object, const QString& field, +bool GLTFSerializer::getIndexFromObject(const QJsonObject& object, const QString& field, int& outidx, QMap& defined) { QJsonObject subobject; if (getObjectVal(object, field, subobject, defined)) { @@ -377,7 +377,7 @@ bool GLTFReader::getIndexFromObject(const QJsonObject& object, const QString& fi return false; } -bool GLTFReader::addMaterial(const QJsonObject& object) { +bool GLTFSerializer::addMaterial(const QJsonObject& object) { GLTFMaterial material; getStringVal(object, "name", material.name, material.defined); @@ -413,7 +413,7 @@ bool GLTFReader::addMaterial(const QJsonObject& object) { return true; } -bool GLTFReader::addMesh(const QJsonObject& object) { +bool GLTFSerializer::addMesh(const QJsonObject& object) { GLTFMesh mesh; getStringVal(object, "name", mesh.name, mesh.defined); @@ -467,7 +467,7 @@ bool GLTFReader::addMesh(const QJsonObject& object) { return true; } -bool GLTFReader::addNode(const QJsonObject& object) { +bool GLTFSerializer::addNode(const QJsonObject& object) { GLTFNode node; getStringVal(object, "name", node.name, node.defined); @@ -487,7 +487,7 @@ bool GLTFReader::addNode(const QJsonObject& object) { return true; } -bool GLTFReader::addSampler(const QJsonObject& object) { +bool GLTFSerializer::addSampler(const QJsonObject& object) { GLTFSampler sampler; getIntVal(object, "magFilter", sampler.magFilter, sampler.defined); @@ -501,7 +501,7 @@ bool GLTFReader::addSampler(const QJsonObject& object) { } -bool GLTFReader::addScene(const QJsonObject& object) { +bool GLTFSerializer::addScene(const QJsonObject& object) { GLTFScene scene; getStringVal(object, "name", scene.name, scene.defined); @@ -511,7 +511,7 @@ bool GLTFReader::addScene(const QJsonObject& object) { return true; } -bool GLTFReader::addSkin(const QJsonObject& object) { +bool GLTFSerializer::addSkin(const QJsonObject& object) { GLTFSkin skin; getIntVal(object, "inverseBindMatrices", skin.inverseBindMatrices, skin.defined); @@ -523,7 +523,7 @@ bool GLTFReader::addSkin(const QJsonObject& object) { return true; } -bool GLTFReader::addTexture(const QJsonObject& object) { +bool GLTFSerializer::addTexture(const QJsonObject& object) { GLTFTexture texture; getIntVal(object, "sampler", texture.sampler, texture.defined); getIntVal(object, "source", texture.source, texture.defined); @@ -533,7 +533,7 @@ bool GLTFReader::addTexture(const QJsonObject& object) { return true; } -bool GLTFReader::parseGLTF(const QByteArray& data) { +bool GLTFSerializer::parseGLTF(const QByteArray& data) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); QJsonDocument d = QJsonDocument::fromJson(data); @@ -664,7 +664,7 @@ bool GLTFReader::parseGLTF(const QByteArray& data) { return true; } -glm::mat4 GLTFReader::getModelTransform(const GLTFNode& node) { +glm::mat4 GLTFSerializer::getModelTransform(const GLTFNode& node) { glm::mat4 tmat = glm::mat4(1.0); if (node.defined["matrix"] && node.matrix.size() == 16) { @@ -697,7 +697,7 @@ glm::mat4 GLTFReader::getModelTransform(const GLTFNode& node) { return tmat; } -bool GLTFReader::buildGeometry(HFMModel& hfmModel, const QUrl& url) { +bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) { //Build dependencies QVector> nodeDependencies(_file.nodes.size()); @@ -899,7 +899,7 @@ bool GLTFReader::buildGeometry(HFMModel& hfmModel, const QUrl& url) { } mesh.meshIndex = hfmModel.meshes.size(); - FBXReader::buildModelMesh(mesh, url.toString()); + FBXSerializer::buildModelMesh(mesh, url.toString()); } } @@ -910,13 +910,12 @@ bool GLTFReader::buildGeometry(HFMModel& hfmModel, const QUrl& url) { return true; } -HFMModel* GLTFReader::readGLTF(QByteArray& data, const QVariantHash& mapping, - const QUrl& url, bool loadLightmaps, float lightmapLevel) { +HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { _url = url; // Normalize url for local files - QUrl normalizeUrl = DependencyManager::get()->normalizeURL(url); + QUrl normalizeUrl = DependencyManager::get()->normalizeURL(_url); if (normalizeUrl.scheme().isEmpty() || (normalizeUrl.scheme() == "file")) { QString localFileName = PathUtils::expandToLocalDataAbsolutePath(normalizeUrl).toLocalFile(); _url = QUrl(QFileInfo(localFileName).absoluteFilePath()); @@ -924,17 +923,17 @@ HFMModel* GLTFReader::readGLTF(QByteArray& data, const QVariantHash& mapping, parseGLTF(data); //_file.dump(); - HFMModel* hfmModelPtr = new HFMModel(); + auto hfmModelPtr = std::make_shared(); HFMModel& hfmModel = *hfmModelPtr; - buildGeometry(hfmModel, url); + buildGeometry(hfmModel, _url); //hfmDebugDump(data); return hfmModelPtr; } -bool GLTFReader::readBinary(const QString& url, QByteArray& outdata) { +bool GLTFSerializer::readBinary(const QString& url, QByteArray& outdata) { QUrl binaryUrl = _url.resolved(url); bool success; @@ -943,7 +942,7 @@ bool GLTFReader::readBinary(const QString& url, QByteArray& outdata) { return success; } -bool GLTFReader::doesResourceExist(const QString& url) { +bool GLTFSerializer::doesResourceExist(const QString& url) { if (_url.isEmpty()) { return false; } @@ -951,9 +950,9 @@ bool GLTFReader::doesResourceExist(const QString& url) { return DependencyManager::get()->resourceExists(candidateUrl); } -std::tuple GLTFReader::requestData(QUrl& url) { +std::tuple GLTFSerializer::requestData(QUrl& url) { auto request = DependencyManager::get()->createResourceRequest( - nullptr, url, true, -1, "GLTFReader::requestData"); + nullptr, url, true, -1, "GLTFSerializer::requestData"); if (!request) { return std::make_tuple(false, QByteArray()); @@ -972,7 +971,7 @@ std::tuple GLTFReader::requestData(QUrl& url) { } -QNetworkReply* GLTFReader::request(QUrl& url, bool isTest) { +QNetworkReply* GLTFSerializer::request(QUrl& url, bool isTest) { if (!qApp) { return nullptr; } @@ -996,7 +995,7 @@ QNetworkReply* GLTFReader::request(QUrl& url, bool isTest) { return netReply; // trying to sync later on. } -HFMTexture GLTFReader::getHFMTexture(const GLTFTexture& texture) { +HFMTexture GLTFSerializer::getHFMTexture(const GLTFTexture& texture) { HFMTexture fbxtex = HFMTexture(); fbxtex.texcoordSet = 0; @@ -1011,7 +1010,7 @@ HFMTexture GLTFReader::getHFMTexture(const GLTFTexture& texture) { return fbxtex; } -void GLTFReader::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& material) { +void GLTFSerializer::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& material) { if (material.defined["name"]) { @@ -1074,7 +1073,7 @@ void GLTFReader::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& materia } template -bool GLTFReader::readArray(const QByteArray& bin, int byteOffset, int count, +bool GLTFSerializer::readArray(const QByteArray& bin, int byteOffset, int count, QVector& outarray, int accessorType) { QDataStream blobstream(bin); @@ -1131,7 +1130,7 @@ bool GLTFReader::readArray(const QByteArray& bin, int byteOffset, int count, return true; } template -bool GLTFReader::addArrayOfType(const QByteArray& bin, int byteOffset, int count, +bool GLTFSerializer::addArrayOfType(const QByteArray& bin, int byteOffset, int count, QVector& outarray, int accessorType, int componentType) { switch (componentType) { @@ -1155,7 +1154,7 @@ bool GLTFReader::addArrayOfType(const QByteArray& bin, int byteOffset, int count return false; } -void GLTFReader::retriangulate(const QVector& inIndices, const QVector& in_vertices, +void GLTFSerializer::retriangulate(const QVector& inIndices, const QVector& in_vertices, const QVector& in_normals, QVector& outIndices, QVector& out_vertices, QVector& out_normals) { for (int i = 0; i < inIndices.size(); i = i + 3) { @@ -1178,7 +1177,7 @@ void GLTFReader::retriangulate(const QVector& inIndices, const QVector +#include "FBXSerializer.h" struct GLTFAsset { @@ -699,12 +700,11 @@ struct GLTFFile { } }; -class GLTFReader : public QObject { +class GLTFSerializer : public QObject, public HFMSerializer { Q_OBJECT public: - GLTFReader(); - HFMModel* readGLTF(QByteArray& data, const QVariantHash& mapping, - const QUrl& url, bool loadLightmaps = true, float lightmapLevel = 1.0f); + GLTFSerializer(); + HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; private: GLTFFile _file; QUrl _url; @@ -780,4 +780,4 @@ private: void hfmDebugDump(const HFMModel& hfmModel); }; -#endif // hifi_GLTFReader_h \ No newline at end of file +#endif // hifi_GLTFSerializer_h \ No newline at end of file diff --git a/libraries/fbx/src/OBJReader.cpp b/libraries/fbx/src/OBJSerializer.cpp similarity index 92% rename from libraries/fbx/src/OBJReader.cpp rename to libraries/fbx/src/OBJSerializer.cpp index e140f1b0b3..af8dfb5562 100644 --- a/libraries/fbx/src/OBJReader.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -1,5 +1,5 @@ // -// OBJReader.cpp +// OBJSerializer.cpp // libraries/fbx/src/ // // Created by Seth Alves on 3/7/15. @@ -12,7 +12,7 @@ // http://www.scratchapixel.com/old/lessons/3d-advanced-lessons/obj-file-format/obj-file-format/ // http://paulbourke.net/dataformats/obj/ -#include "OBJReader.h" +#include "OBJSerializer.h" #include // .obj files are not locale-specific. The C/ASCII charset applies. #include @@ -27,7 +27,7 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -238,7 +238,7 @@ void OBJFace::addFrom(const OBJFace* face, int index) { // add using data from f } } -bool OBJReader::isValidTexture(const QByteArray &filename) { +bool OBJSerializer::isValidTexture(const QByteArray &filename) { if (_url.isEmpty()) { return false; } @@ -247,7 +247,7 @@ bool OBJReader::isValidTexture(const QByteArray &filename) { return DependencyManager::get()->resourceExists(candidateUrl); } -void OBJReader::parseMaterialLibrary(QIODevice* device) { +void OBJSerializer::parseMaterialLibrary(QIODevice* device) { OBJTokenizer tokenizer(device); QString matName = SMART_DEFAULT_MATERIAL_NAME; OBJMaterial& currentMaterial = materials[matName]; @@ -255,7 +255,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { switch (tokenizer.nextToken()) { case OBJTokenizer::COMMENT_TOKEN: #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader MTLLIB comment:" << tokenizer.getComment(); + qCDebug(modelformat) << "OBJSerializer MTLLIB comment:" << tokenizer.getComment(); #endif break; case OBJTokenizer::DATUM_TOKEN: @@ -264,7 +264,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { materials[matName] = currentMaterial; #ifdef WANT_DEBUG qCDebug(modelformat) << - "OBJ Reader Last material illumination model:" << currentMaterial.illuminationModel << + "OBJSerializer Last material illumination model:" << currentMaterial.illuminationModel << " shininess:" << currentMaterial.shininess << " opacity:" << currentMaterial.opacity << " diffuse color:" << currentMaterial.diffuseColor << @@ -287,7 +287,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { matName = tokenizer.getDatum(); currentMaterial = materials[matName]; #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Starting new material definition " << matName; + qCDebug(modelformat) << "OBJSerializer Starting new material definition " << matName; #endif currentMaterial.diffuseTextureFilename = ""; currentMaterial.emissiveTextureFilename = ""; @@ -299,7 +299,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { currentMaterial.shininess = tokenizer.getFloat(); } else if (token == "Ni") { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Ignoring material Ni " << tokenizer.getFloat(); + qCDebug(modelformat) << "OBJSerializer Ignoring material Ni " << tokenizer.getFloat(); #else tokenizer.getFloat(); #endif @@ -311,13 +311,13 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { currentMaterial.illuminationModel = tokenizer.getFloat(); } else if (token == "Tf") { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Ignoring material Tf " << tokenizer.getVec3(); + qCDebug(modelformat) << "OBJSerializer Ignoring material Tf " << tokenizer.getVec3(); #else tokenizer.getVec3(); #endif } else if (token == "Ka") { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Ignoring material Ka " << tokenizer.getVec3();; + qCDebug(modelformat) << "OBJSerializer Ignoring material Ka " << tokenizer.getVec3();; #else tokenizer.getVec3(); #endif @@ -334,7 +334,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { parseTextureLine(textureLine, filename, textureOptions); if (filename.endsWith(".tga")) { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader WARNING: currently ignoring tga texture " << filename << " in " << _url; + qCDebug(modelformat) << "OBJSerializer WARNING: currently ignoring tga texture " << filename << " in " << _url; #endif break; } @@ -354,7 +354,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { } } -void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& filename, OBJMaterialTextureOptions& textureOptions) { +void OBJSerializer::parseTextureLine(const QByteArray& textureLine, QByteArray& filename, OBJMaterialTextureOptions& textureOptions) { // Texture options reference http://paulbourke.net/dataformats/mtl/ // and https://wikivisually.com/wiki/Material_Template_Library @@ -368,7 +368,7 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file if (option == "-blendu" || option == "-blendv") { #ifdef WANT_DEBUG const std::string& onoff = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); #endif } else if (option == "-bm") { const std::string& bm = parser[i++]; @@ -377,22 +377,22 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file #ifdef WANT_DEBUG const std::string& boost = parser[i++]; float boostFloat = std::stof(boost); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << boost.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << boost.c_str(); #endif } else if (option == "-cc") { #ifdef WANT_DEBUG const std::string& onoff = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); #endif } else if (option == "-clamp") { #ifdef WANT_DEBUG const std::string& onoff = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); #endif } else if (option == "-imfchan") { #ifdef WANT_DEBUG const std::string& imfchan = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << imfchan.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << imfchan.c_str(); #endif } else if (option == "-mm") { if (i + 1 < parser.size()) { @@ -401,7 +401,7 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file const std::string& mmGain = parser[i++]; float mmBaseFloat = std::stof(mmBase); float mmGainFloat = std::stof(mmGain); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << mmBase.c_str() << mmGain.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << mmBase.c_str() << mmGain.c_str(); #endif } } else if (option == "-o" || option == "-s" || option == "-t") { @@ -413,23 +413,23 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file float uFloat = std::stof(u); float vFloat = std::stof(v); float wFloat = std::stof(w); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << u.c_str() << v.c_str() << w.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << u.c_str() << v.c_str() << w.c_str(); #endif } } else if (option == "-texres") { #ifdef WANT_DEBUG const std::string& texres = parser[i++]; float texresFloat = std::stof(texres); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << texres.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << texres.c_str(); #endif } else if (option == "-type") { #ifdef WANT_DEBUG const std::string& type = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << type.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << type.c_str(); #endif } else if (option[0] == '-') { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring unsupported texture option" << option.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring unsupported texture option" << option.c_str(); #endif } } else { // assume filename at end when no more options @@ -444,7 +444,7 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file std::tuple requestData(QUrl& url) { auto request = DependencyManager::get()->createResourceRequest( - nullptr, url, true, -1, "(OBJReader) requestData"); + nullptr, url, true, -1, "(OBJSerializer) requestData"); if (!request) { return std::make_tuple(false, QByteArray()); @@ -488,7 +488,7 @@ QNetworkReply* request(QUrl& url, bool isTest) { } -bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, HFMModel& hfmModel, +bool OBJSerializer::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, HFMModel& hfmModel, float& scaleGuess, bool combineParts) { FaceGroup faces; HFMMesh& mesh = hfmModel.meshes[0]; @@ -557,7 +557,7 @@ bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mappi currentMaterialName = nextName; } #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader new current material:" << currentMaterialName; + qCDebug(modelformat) << "OBJSerializer new current material:" << currentMaterialName; #endif } } else if (token == "v") { @@ -652,12 +652,12 @@ done: } -HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mapping, bool combineParts, const QUrl& url) { +HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); - QBuffer buffer { &data }; + QBuffer buffer { const_cast(&data) }; buffer.open(QIODevice::ReadOnly); - auto hfmModelPtr { std::make_shared() }; + auto hfmModelPtr = std::make_shared(); HFMModel& hfmModel { *hfmModelPtr }; OBJTokenizer tokenizer { &buffer }; float scaleGuess = 1.0f; @@ -665,6 +665,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi bool needsMaterialLibrary = false; _url = url; + bool combineParts = mapping.value("combineParts").toBool(); hfmModel.meshExtents.reset(); hfmModel.meshes.append(HFMMesh()); @@ -720,7 +721,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi QString groupMaterialName = face.materialName; if (groupMaterialName.isEmpty() && specifiesUV) { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader WARNING: " << url + qCDebug(modelformat) << "OBJSerializer WARNING: " << url << " needs a texture that isn't specified. Using default mechanism."; #endif groupMaterialName = SMART_DEFAULT_MATERIAL_NAME; @@ -822,11 +823,11 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi } // Build the single mesh. - FBXReader::buildModelMesh(mesh, url.toString()); + FBXSerializer::buildModelMesh(mesh, _url.toString()); // hfmDebugDump(hfmModel); } catch(const std::exception& e) { - qCDebug(modelformat) << "OBJ reader fail: " << e.what(); + qCDebug(modelformat) << "OBJSerializer fail: " << e.what(); } QString queryPart = _url.query(); @@ -838,14 +839,14 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi } // Some .obj files use the convention that a group with uv coordinates that doesn't define a material, should use // a texture with the same basename as the .obj file. - if (preDefinedMaterial.userSpecifiesUV && !url.isEmpty()) { - QString filename = url.fileName(); + if (preDefinedMaterial.userSpecifiesUV && !_url.isEmpty()) { + QString filename = _url.fileName(); int extIndex = filename.lastIndexOf('.'); // by construction, this does not fail QString basename = filename.remove(extIndex + 1, sizeof("obj")); preDefinedMaterial.diffuseColor = glm::vec3(1.0f); QVector extensions = { "jpg", "jpeg", "png", "tga" }; QByteArray base = basename.toUtf8(), textName = ""; - qCDebug(modelformat) << "OBJ Reader looking for default texture"; + qCDebug(modelformat) << "OBJSerializer looking for default texture"; for (int i = 0; i < extensions.count(); i++) { QByteArray candidateString = base + extensions[i]; if (isValidTexture(candidateString)) { @@ -856,7 +857,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi if (!textName.isEmpty()) { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader found a default texture: " << textName; + qCDebug(modelformat) << "OBJSerializer found a default texture: " << textName; #endif preDefinedMaterial.diffuseTextureFilename = textName; } @@ -866,7 +867,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi foreach (QString libraryName, librariesSeen.keys()) { // Throw away any path part of libraryName, and merge against original url. QUrl libraryUrl = _url.resolved(QUrl(libraryName).fileName()); - qCDebug(modelformat) << "OBJ Reader material library" << libraryName; + qCDebug(modelformat) << "OBJSerializer material library" << libraryName; bool success; QByteArray data; std::tie(success, data) = requestData(libraryUrl); @@ -875,7 +876,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi buffer.open(QIODevice::ReadOnly); parseMaterialLibrary(&buffer); } else { - qCDebug(modelformat) << "OBJ Reader WARNING:" << libraryName << "did not answer"; + qCDebug(modelformat) << "OBJSerializer WARNING:" << libraryName << "did not answer"; } } } diff --git a/libraries/fbx/src/OBJReader.h b/libraries/fbx/src/OBJSerializer.h similarity index 85% rename from libraries/fbx/src/OBJReader.h rename to libraries/fbx/src/OBJSerializer.h index 0088e8e9d7..a6fe3817ca 100644 --- a/libraries/fbx/src/OBJReader.h +++ b/libraries/fbx/src/OBJSerializer.h @@ -1,6 +1,20 @@ +// +// OBJSerializer.h +// libraries/fbx/src/ +// +// Created by Seth Alves on 3/6/15. +// Copyright 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 +// + +#ifndef hifi_OBJSerializer_h +#define hifi_OBJSerializer_h #include -#include "FBXReader.h" +#include +#include "FBXSerializer.h" class OBJTokenizer { public: @@ -75,7 +89,7 @@ public: OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f), illuminationModel(-1) {} }; -class OBJReader: public QObject { // QObject so we can make network requests. +class OBJSerializer: public QObject, public HFMSerializer { // QObject so we can make network requests. Q_OBJECT public: typedef QVector FaceGroup; @@ -86,8 +100,8 @@ public: QVector faceGroups; QString currentMaterialName; QHash materials; - - HFMModel::Pointer readOBJ(QByteArray& data, const QVariantHash& mapping, bool combineParts, const QUrl& url = QUrl()); + + HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; private: QUrl _url; @@ -105,3 +119,5 @@ private: // What are these utilities doing here? One is used by fbx loading code in VHACD Utils, and the other a general debugging utility. void setMeshPartDefaults(HFMMeshPart& meshPart, QString materialID); void hfmDebugDump(const HFMModel& hfmModel); + +#endif // hifi_OBJSerializer_h diff --git a/libraries/gpu/src/gpu/Noise.slh b/libraries/gpu/src/gpu/Noise.slh index d300e71ba9..a6a658cbd1 100644 --- a/libraries/gpu/src/gpu/Noise.slh +++ b/libraries/gpu/src/gpu/Noise.slh @@ -231,7 +231,8 @@ float snoise(vec2 v) { // Other corners vec2 i1; - i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); + float check = float(x0.x > x0.y); + i1 = vec2(check, 1.0 - check); vec4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1; diff --git a/libraries/graphics/src/graphics/Material.cpp b/libraries/graphics/src/graphics/Material.cpp index 1b0e7ee67e..be99cea681 100755 --- a/libraries/graphics/src/graphics/Material.cpp +++ b/libraries/graphics/src/graphics/Material.cpp @@ -130,9 +130,11 @@ void Material::setTextureMap(MapChannel channel, const TextureMapPointer& textur if (channel == MaterialKey::LIGHTMAP_MAP) { // update the texcoord1 with lightmap _schemaBuffer.edit()._texcoordTransforms[1] = (textureMap ? textureMap->getTextureTransform().getMatrix() : glm::mat4()); - _schemaBuffer.edit()._lightmapParams = (textureMap ? glm::vec4(textureMap->getLightmapOffsetScale(), 0.0, 0.0) : glm::vec4(0.0, 1.0, 0.0, 0.0)); + _schemaBuffer.edit()._lightmapParams = (textureMap ? glm::vec2(textureMap->getLightmapOffsetScale()) : glm::vec2(0.0, 1.0)); } + _schemaBuffer.edit()._materialParams = (textureMap ? glm::vec2(textureMap->getMappingMode(), textureMap->getRepeat()) : glm::vec2(MaterialMappingMode::UV, 1.0)); + _schemaBuffer.edit()._key = (uint32)_key._flags.to_ulong(); } @@ -211,13 +213,16 @@ bool Material::calculateMaterialInfo() const { return _hasCalculatedTextureInfo; } -void Material::setTextureTransforms(const Transform& transform) { +void Material::setTextureTransforms(const Transform& transform, MaterialMappingMode mode, bool repeat) { for (auto &textureMapItem : _textureMaps) { if (textureMapItem.second) { textureMapItem.second->setTextureTransform(transform); + textureMapItem.second->setMappingMode(mode); + textureMapItem.second->setRepeat(repeat); } } for (int i = 0; i < NUM_TEXCOORD_TRANSFORMS; i++) { _schemaBuffer.edit()._texcoordTransforms[i] = transform.getMatrix(); } -} \ No newline at end of file + _schemaBuffer.edit()._materialParams = glm::vec2(mode, repeat); +} diff --git a/libraries/graphics/src/graphics/Material.h b/libraries/graphics/src/graphics/Material.h index 914a36d055..9711bd9000 100755 --- a/libraries/graphics/src/graphics/Material.h +++ b/libraries/graphics/src/graphics/Material.h @@ -22,6 +22,8 @@ #include #include +#include "MaterialMappingMode.h" + class Transform; namespace graphics { @@ -330,7 +332,11 @@ public: // Texture Coord Transform Array glm::mat4 _texcoordTransforms[NUM_TEXCOORD_TRANSFORMS]; - glm::vec4 _lightmapParams{ 0.0, 1.0, 0.0, 0.0 }; + glm::vec2 _lightmapParams { 0.0, 1.0 }; + + // x: material mode (0 for UV, 1 for PROJECTED) + // y: 1 for texture repeat, 0 for discard outside of 0 - 1 + glm::vec2 _materialParams { 0.0, 1.0 }; Schema() {} }; @@ -353,7 +359,7 @@ public: size_t getTextureSize() const { calculateMaterialInfo(); return _textureSize; } bool hasTextureInfo() const { return _hasCalculatedTextureInfo; } - void setTextureTransforms(const Transform& transform); + void setTextureTransforms(const Transform& transform, MaterialMappingMode mode, bool repeat); const std::string& getName() const { return _name; } diff --git a/libraries/graphics/src/graphics/Material.slh b/libraries/graphics/src/graphics/Material.slh index 62632f993b..dfd4a8eec4 100644 --- a/libraries/graphics/src/graphics/Material.slh +++ b/libraries/graphics/src/graphics/Material.slh @@ -19,20 +19,25 @@ const int MAX_TEXCOORDS = 2; struct TexMapArray { mat4 _texcoordTransforms0; mat4 _texcoordTransforms1; - vec4 _lightmapParams; + vec2 _lightmapParams; + vec2 _materialParams; }; <@func declareMaterialTexMapArrayBuffer()@> -<@func evalTexMapArrayTexcoord0(texMapArray, inTexcoord0, outTexcoord0)@> +<@func evalTexMapArrayTexcoord0(texMapArray, inTexcoord0, worldPosition, outTexcoord0)@> { - <$outTexcoord0$> = (<$texMapArray$>._texcoordTransforms0 * vec4(<$inTexcoord0$>.st, 0.0, 1.0)).st; + <$outTexcoord0$> = mix(<$texMapArray$>._texcoordTransforms0 * vec4(<$inTexcoord0$>.st, 0.0, 1.0), + <$texMapArray$>._texcoordTransforms0 * <$worldPosition$> + vec4(0.5), + <$texMapArray$>._materialParams.x).st; } <@endfunc@> -<@func evalTexMapArrayTexcoord1(texMapArray, inTexcoord1, outTexcoord1)@> +<@func evalTexMapArrayTexcoord1(texMapArray, inTexcoord1, worldPosition, outTexcoord1)@> { - <$outTexcoord1$> = (<$texMapArray$>._texcoordTransforms1 * vec4(<$inTexcoord1$>.st, 0.0, 1.0)).st; + <$outTexcoord1$> = mix(<$texMapArray$>._texcoordTransforms1 * vec4(<$inTexcoord1$>.st, 0.0, 1.0), + <$texMapArray$>._texcoordTransforms1 * <$worldPosition$> + vec4(0.5), + <$texMapArray$>._materialParams.x).st; } <@endfunc@> diff --git a/libraries/graphics/src/graphics/MaterialTextures.slh b/libraries/graphics/src/graphics/MaterialTextures.slh index 20b117132c..1cbee33238 100644 --- a/libraries/graphics/src/graphics/MaterialTextures.slh +++ b/libraries/graphics/src/graphics/MaterialTextures.slh @@ -151,29 +151,32 @@ float fetchScatteringMap(vec2 uv) { <@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, scattering)@> + if (getTexMapArray()._materialParams.y != 1.0 && clamp(<$texcoord0$>, vec2(0.0), vec2(1.0)) != <$texcoord0$>) { + discard; + } <@if albedo@> - vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0)); + vec4 <$albedo$> = mix(vec4(1.0), fetchAlbedoMap(<$texcoord0$>), float((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0)); <@endif@> <@if roughness@> - float <$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? fetchRoughnessMap(<$texcoord0$>) : 1.0); + float <$roughness$> = mix(1.0, fetchRoughnessMap(<$texcoord0$>), float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0)); <@endif@> <@if normal@> - vec3 <$normal$> = (((<$matKey$> & NORMAL_MAP_BIT) != 0) ? fetchNormalMap(<$texcoord0$>) : vec3(0.0, 1.0, 0.0)); + vec3 <$normal$> = mix(vec3(0.0, 1.0, 0.0), fetchNormalMap(<$texcoord0$>), float((<$matKey$> & NORMAL_MAP_BIT) != 0)); <@endif@> <@if metallic@> - float <$metallic$> = (((<$matKey$> & METALLIC_MAP_BIT) != 0) ? fetchMetallicMap(<$texcoord0$>) : 0.0); + float <$metallic$> = float((<$matKey$> & METALLIC_MAP_BIT) != 0) * fetchMetallicMap(<$texcoord0$>); <@endif@> <@if emissive@> - vec3 <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? fetchEmissiveMap(<$texcoord0$>) : vec3(0.0)); + vec3 <$emissive$> = float((<$matKey$> & EMISSIVE_MAP_BIT) != 0) * fetchEmissiveMap(<$texcoord0$>); <@endif@> <@if scattering@> - float <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? fetchScatteringMap(<$texcoord0$>) : 0.0); + float <$scattering$> = float((<$matKey$> & SCATTERING_MAP_BIT) != 0) * fetchScatteringMap(<$texcoord0$>); <@endif@> <@endfunc@> <@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmap)@> <@if occlusion@> - float <$occlusion$> = (((<$matKey$> & OCCLUSION_MAP_BIT) != 0) ? fetchOcclusionMap(<$texcoord1$>) : 1.0); + float <$occlusion$> = mix(1.0, fetchOcclusionMap(<$texcoord1$>), float((<$matKey$> & OCCLUSION_MAP_BIT) != 0)); <@endif@> <@if lightmap@> vec3 <$lightmap$> = fetchLightmapMap(<$texcoord1$>); @@ -188,7 +191,7 @@ float fetchScatteringMap(vec2 uv) { LAYOUT(binding=GRAPHICS_TEXTURE_MATERIAL_EMISSIVE_LIGHTMAP) uniform sampler2D emissiveMap; vec3 fetchLightmapMap(vec2 uv) { - vec2 lightmapParams = getTexMapArray()._lightmapParams.xy; + vec2 lightmapParams = getTexMapArray()._lightmapParams; return (vec3(lightmapParams.x) + lightmapParams.y * texture(emissiveMap, uv).rgb); } <@endfunc@> @@ -207,20 +210,19 @@ vec3 fetchLightmapMap(vec2 uv) { <@func evalMaterialAlbedo(fetchedAlbedo, materialAlbedo, matKey, albedo)@> { - <$albedo$>.xyz = (((<$matKey$> & ALBEDO_VAL_BIT) != 0) ? <$materialAlbedo$> : vec3(1.0)); - - if (((<$matKey$> & ALBEDO_MAP_BIT) != 0)) { - <$albedo$>.xyz *= <$fetchedAlbedo$>.xyz; - } + <$albedo$>.xyz = mix(vec3(1.0), <$materialAlbedo$>, float((<$matKey$> & ALBEDO_VAL_BIT) != 0)); + <$albedo$>.xyz *= mix(vec3(1.0), <$fetchedAlbedo$>.xyz, float((<$matKey$> & ALBEDO_MAP_BIT) != 0)); } <@endfunc@> <@func evalMaterialOpacity(fetchedOpacity, materialOpacity, matKey, opacity)@> { const float OPACITY_MASK_THRESHOLD = 0.5; - <$opacity$> = (((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0) ? - (((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0) ? step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>) : <$fetchedOpacity$>) : - 1.0) * <$materialOpacity$>; + <$opacity$> = mix(1.0, + mix(<$fetchedOpacity$>, + step(OPACITY_MASK_THRESHOLD, <$fetchedOpacity$>), + float((<$matKey$> & OPACITY_MASK_MAP_BIT) != 0)), + float((<$matKey$> & (OPACITY_TRANSLUCENT_MAP_BIT | OPACITY_MASK_MAP_BIT)) != 0)) * <$materialOpacity$>; } <@endfunc@> @@ -241,19 +243,19 @@ vec3 fetchLightmapMap(vec2 uv) { <@func evalMaterialRoughness(fetchedRoughness, materialRoughness, matKey, roughness)@> { - <$roughness$> = (((<$matKey$> & ROUGHNESS_MAP_BIT) != 0) ? <$fetchedRoughness$> : <$materialRoughness$>); + <$roughness$> = mix(<$materialRoughness$>, <$fetchedRoughness$>, float((<$matKey$> & ROUGHNESS_MAP_BIT) != 0)); } <@endfunc@> <@func evalMaterialMetallic(fetchedMetallic, materialMetallic, matKey, metallic)@> { - <$metallic$> = (((<$matKey$> & METALLIC_MAP_BIT) != 0) ? <$fetchedMetallic$> : <$materialMetallic$>); + <$metallic$> = mix(<$materialMetallic$>, <$fetchedMetallic$>, float((<$matKey$> & METALLIC_MAP_BIT) != 0)); } <@endfunc@> <@func evalMaterialEmissive(fetchedEmissive, materialEmissive, matKey, emissive)@> { - <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? <$fetchedEmissive$> : <$materialEmissive$>); + <$emissive$> = mix(<$materialEmissive$>, <$fetchedEmissive$>, float((<$matKey$> & EMISSIVE_MAP_BIT) != 0)); } <@endfunc@> @@ -265,7 +267,7 @@ vec3 fetchLightmapMap(vec2 uv) { <@func evalMaterialScattering(fetchedScattering, materialScattering, matKey, scattering)@> { - <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? <$fetchedScattering$> : <$materialScattering$>); + <$scattering$> = mix(<$materialScattering$>, <$fetchedScattering$>, float((<$matKey$> & SCATTERING_MAP_BIT) != 0)); } <@endfunc@> diff --git a/libraries/graphics/src/graphics/Stage.cpp b/libraries/graphics/src/graphics/Stage.cpp index 312ece6889..21929a61dd 100644 --- a/libraries/graphics/src/graphics/Stage.cpp +++ b/libraries/graphics/src/graphics/Stage.cpp @@ -223,8 +223,8 @@ void SunSkyStage::setSunDirection(const Vec3& direction) { } } -// THe sun declinaison calculus is taken from https://en.wikipedia.org/wiki/Position_of_the_Sun -double evalSunDeclinaison(double dayNumber) { +// The sun declination calculus is taken from https://en.wikipedia.org/wiki/Position_of_the_Sun +double evalSunDeclination(double dayNumber) { return -(23.0 + 44.0/60.0)*cos(glm::radians((360.0/365.0)*(dayNumber + 10.0))); } @@ -235,8 +235,8 @@ void SunSkyStage::updateGraphicsObject() const { float sunLongitude = _earthSunModel.getLongitude() + (MAX_LONGITUDE * signedNormalizedDayTime); _earthSunModel.setSunLongitude(sunLongitude); - // And update the sunLAtitude as the declinaison depending of the time of the year - _earthSunModel.setSunLatitude(evalSunDeclinaison(_yearTime)); + // And update the sunLatitude as the declination depending of the time of the year + _earthSunModel.setSunLatitude(evalSunDeclination(_yearTime)); if (isSunModelEnabled()) { Vec3d sunLightDir = -_earthSunModel.getSurfaceSunDir(); diff --git a/libraries/graphics/src/graphics/TextureMap.h b/libraries/graphics/src/graphics/TextureMap.h index 1678d9df98..eea9d2b31b 100755 --- a/libraries/graphics/src/graphics/TextureMap.h +++ b/libraries/graphics/src/graphics/TextureMap.h @@ -14,6 +14,7 @@ #include "gpu/Texture.h" #include "Transform.h" +#include "MaterialMappingMode.h" namespace graphics { @@ -30,6 +31,12 @@ public: void setTextureTransform(const Transform& texcoordTransform); const Transform& getTextureTransform() const { return _texcoordTransform; } + void setMappingMode(MaterialMappingMode mode) { _mappingMode = mode; } + MaterialMappingMode getMappingMode() const { return _mappingMode; } + + void setRepeat(bool repeat) { _repeat = repeat; } + bool getRepeat() const { return _repeat; } + void setUseAlphaChannel(bool useAlpha) { _useAlphaChannel = useAlpha; } bool useAlphaChannel() const { return _useAlphaChannel; } @@ -41,6 +48,8 @@ protected: Transform _texcoordTransform; glm::vec2 _lightmapOffsetScale{ 0.0f, 1.0f }; + MaterialMappingMode _mappingMode { MaterialMappingMode::UV }; + bool _repeat { true }; bool _useAlphaChannel{ false }; }; diff --git a/libraries/graphics/src/graphics/skybox.slf b/libraries/graphics/src/graphics/skybox.slf index b24bf0f583..c20dd94bf4 100755 --- a/libraries/graphics/src/graphics/skybox.slf +++ b/libraries/graphics/src/graphics/skybox.slf @@ -30,11 +30,9 @@ void main(void) { vec3 color = skybox.color.rgb; // blend is only set if there is a cubemap - if (skybox.color.a > 0.0) { - color = texture(cubeMap, coord).rgb; - if (skybox.color.a < 1.0) { - color *= skybox.color.rgb; - } - } + float check = float(skybox.color.a > 0.0); + color = mix(color, texture(cubeMap, coord).rgb, check); + color *= mix(vec3(1.0), skybox.color.rgb, check * float(skybox.color.a < 1.0)); + _fragColor = vec4(color, 0.0); } diff --git a/libraries/hfm/src/hfm/HFM.h b/libraries/hfm/src/hfm/HFM.h index 7d4479e681..05e48b6534 100644 --- a/libraries/hfm/src/hfm/HFM.h +++ b/libraries/hfm/src/hfm/HFM.h @@ -311,6 +311,8 @@ public: QString getModelNameOfMesh(int meshIndex) const; QList blendshapeChannelNames; + + QMap jointRotationOffsets; }; }; diff --git a/libraries/hfm/src/hfm/HFMSerializer.h b/libraries/hfm/src/hfm/HFMSerializer.h new file mode 100644 index 0000000000..db18f21e06 --- /dev/null +++ b/libraries/hfm/src/hfm/HFMSerializer.h @@ -0,0 +1,29 @@ +// +// FBXSerializer.h +// libraries/hfm/src/hfm +// +// Created by Sabrina Shanman on 2018/11/07. +// Copyright 2018 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 +// + +#ifndef hifi_HFMSerializer_h +#define hifi_HFMSerializer_h + +#include + +#include "HFM.h" + +namespace hfm { + +class Serializer { + virtual Model::Pointer read(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url = hifi::URL()) = 0; +}; + +}; + +using HFMSerializer = hfm::Serializer; + +#endif // hifi_HFMSerializer_h diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index e3edf7bc53..254f61eba9 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -12,9 +12,9 @@ #include "ModelCache.h" #include #include -#include "FBXReader.h" -#include "OBJReader.h" -#include "GLTFReader.h" +#include "FBXSerializer.h" +#include "OBJSerializer.h" +#include "GLTFSerializer.h" #include #include @@ -193,24 +193,26 @@ void GeometryReader::run() { HFMModel::Pointer hfmModel; + QVariantHash serializerMapping = _mapping; + serializerMapping["combineParts"] = _combineParts; + if (_url.path().toLower().endsWith(".fbx")) { - hfmModel.reset(readFBX(_data, _mapping, _url.path())); + hfmModel = FBXSerializer().read(_data, serializerMapping, _url); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported FBX version"); } } else if (_url.path().toLower().endsWith(".obj")) { - hfmModel = OBJReader().readOBJ(_data, _mapping, _combineParts, _url); + hfmModel = OBJSerializer().read(_data, serializerMapping, _url); } else if (_url.path().toLower().endsWith(".obj.gz")) { QByteArray uncompressedData; if (gunzip(_data, uncompressedData)){ - hfmModel = OBJReader().readOBJ(uncompressedData, _mapping, _combineParts, _url); + hfmModel = OBJSerializer().read(uncompressedData, serializerMapping, _url); } else { throw QString("failed to decompress .obj.gz"); } } else if (_url.path().toLower().endsWith(".gltf")) { - std::shared_ptr glreader = std::make_shared(); - hfmModel.reset(glreader->readGLTF(_data, _mapping, _url)); + hfmModel = GLTFSerializer().read(_data, serializerMapping, _url); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported GLTF version"); } @@ -243,6 +245,13 @@ void GeometryReader::run() { QMetaObject::invokeMethod(resource.data(), "finishedLoading", Q_ARG(bool, false)); } + } catch (QString& e) { + qCWarning(modelnetworking) << "Exception while loading model --" << e; + auto resource = _resource.toStrongRef(); + if (resource) { + QMetaObject::invokeMethod(resource.data(), "finishedLoading", + Q_ARG(bool, false)); + } } } diff --git a/libraries/model-networking/src/model-networking/ModelCache.h b/libraries/model-networking/src/model-networking/ModelCache.h index 1bb340b83c..9d458e7512 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.h +++ b/libraries/model-networking/src/model-networking/ModelCache.h @@ -18,7 +18,7 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" #include "TextureCache.h" // Alias instead of derive to avoid copying diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index c0c5a4d059..620ffb9641 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -234,7 +234,7 @@ private: #ifdef Q_OS_ANDROID Setting::Handle _enableInterstitialMode{ "enableInterstitialMode", false }; #else - Setting::Handle _enableInterstitialMode { "enableInterstitialMode", true }; + Setting::Handle _enableInterstitialMode { "enableInterstitialMode", false }; #endif QSet _domainConnectionRefusals; diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index 18e439aa77..cab3ba3211 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -33,7 +33,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketType::EntityEdit: case PacketType::EntityData: case PacketType::EntityPhysics: - return static_cast(EntityVersion::FixedLightSerialization); + return static_cast(EntityVersion::MaterialRepeat); case PacketType::EntityQuery: return static_cast(EntityQueryPacketVersion::ConicalFrustums); case PacketType::AvatarIdentity: diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index f3bc115410..4c61bdfec9 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -244,7 +244,8 @@ enum class EntityVersion : PacketVersion { BloomEffect, GrabProperties, ScriptGlmVectors, - FixedLightSerialization + FixedLightSerialization, + MaterialRepeat }; enum class EntityScriptCallMethodVersion : PacketVersion { diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 9cba4970ac..3178217a36 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -134,6 +134,7 @@ void SendQueue::stop() { } int SendQueue::sendPacket(const Packet& packet) { + _lastPacketSentAt = std::chrono::high_resolution_clock::now(); return _socket->writeDatagram(packet.getData(), packet.getDataSize(), _destination); } @@ -501,12 +502,31 @@ bool SendQueue::isInactive(bool attemptedToSendPacket) { // We think the client is still waiting for data (based on the sequence number gap) // Let's wait either for a response from the client or until the estimated timeout // (plus the sync interval to allow the client to respond) has elapsed - auto waitDuration = std::chrono::microseconds(_estimatedTimeout + _syncInterval); - + + auto estimatedTimeout = std::chrono::microseconds(_estimatedTimeout); + + // cap our maximum estimated timeout to the already unreasonable 5 seconds + const auto MAXIMUM_ESTIMATED_TIMEOUT = std::chrono::seconds(5); + + if (estimatedTimeout > MAXIMUM_ESTIMATED_TIMEOUT) { + estimatedTimeout = MAXIMUM_ESTIMATED_TIMEOUT; + } + // use our condition_variable_any to wait - auto cvStatus = _emptyCondition.wait_for(locker, waitDuration); - - if (cvStatus == std::cv_status::timeout && (_packets.isEmpty() || isFlowWindowFull()) && _naks.isEmpty() + auto cvStatus = _emptyCondition.wait_for(locker, estimatedTimeout); + + // when we wake-up check if we're "stuck" either if we've slept for the estimated timeout + // or it has been that long since the last time we sent a packet + + // we are stuck if all of the following are true + // - there are no new packets to send or the flow window is full and we can't send any new packets + // - there are no packets to resend + // - the client has yet to ACK some sent packets + auto now = std::chrono::high_resolution_clock::now(); + + if ((cvStatus == std::cv_status::timeout || (now - _lastPacketSentAt > estimatedTimeout)) + && (_packets.isEmpty() || isFlowWindowFull()) + && _naks.isEmpty() && SequenceNumber(_lastACKSequenceNumber) < _currentSequenceNumber) { // after a timeout if we still have sent packets that the client hasn't ACKed we // add them to the loss list diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index 65b1b89c7e..c1faac3b22 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -68,7 +68,6 @@ public: void setPacketSendPeriod(int newPeriod) { _packetSendPeriod = newPeriod; } void setEstimatedTimeout(int estimatedTimeout) { _estimatedTimeout = estimatedTimeout; } - void setSyncInterval(int syncInterval) { _syncInterval = syncInterval; } public slots: void stop(); @@ -124,7 +123,6 @@ private: std::atomic _state { State::NotStarted }; std::atomic _estimatedTimeout { 0 }; // Estimated timeout, set from CC - std::atomic _syncInterval { udt::DEFAULT_SYN_INTERVAL_USECS }; // Sync interval, set from CC std::atomic _flowWindowSize { 0 }; // Flow control window size (number of packets that can be on wire) - set from CC @@ -140,6 +138,8 @@ private: std::condition_variable _handshakeACKCondition; std::condition_variable_any _emptyCondition; + + std::chrono::high_resolution_clock::time_point _lastPacketSentAt; }; } diff --git a/libraries/octree/src/OctreeEntitiesFileParser.cpp b/libraries/octree/src/OctreeEntitiesFileParser.cpp index 873eaff0e1..962f744c34 100644 --- a/libraries/octree/src/OctreeEntitiesFileParser.cpp +++ b/libraries/octree/src/OctreeEntitiesFileParser.cpp @@ -46,8 +46,13 @@ bool OctreeEntitiesFileParser::parseEntities(QVariantMap& parsedEntities) { bool gotId = false; bool gotVersion = false; - while (!(gotDataVersion && gotEntities && gotId && gotVersion)) { - if (nextToken() != '"') { + int token = nextToken(); + + while (true) { + if (token == '}') { + break; + } + else if (token != '"') { _errorString = "Incorrect key string"; return false; } @@ -144,15 +149,13 @@ bool OctreeEntitiesFileParser::parseEntities(QVariantMap& parsedEntities) { return false; } - if (gotDataVersion && gotEntities && gotId && gotVersion) { - break; - } else if (nextToken() != ',') { - _errorString = "Id/value incorrectly terminated"; - return false; + token = nextToken(); + if (token == ',') { + token = nextToken(); } } - if (nextToken() != '}' || nextToken() != -1) { + if (nextToken() != -1) { _errorString = "Ill-formed end of object"; return false; } diff --git a/libraries/plugins/src/plugins/PluginUtils.cpp b/libraries/plugins/src/plugins/PluginUtils.cpp index ce67f7c585..f6419ccba0 100644 --- a/libraries/plugins/src/plugins/PluginUtils.cpp +++ b/libraries/plugins/src/plugins/PluginUtils.cpp @@ -65,6 +65,6 @@ bool PluginUtils::isOculusTouchControllerAvailable() { }; bool PluginUtils::isXboxControllerAvailable() { - return isSubdeviceContainingNameAvailable("X360 Controller"); + return isSubdeviceContainingNameAvailable("X360 Controller") || isSubdeviceContainingNameAvailable("XInput Controller"); }; diff --git a/libraries/qml/src/qml/OffscreenSurface.cpp b/libraries/qml/src/qml/OffscreenSurface.cpp index 91532534e3..abab5391e2 100644 --- a/libraries/qml/src/qml/OffscreenSurface.cpp +++ b/libraries/qml/src/qml/OffscreenSurface.cpp @@ -389,6 +389,10 @@ void OffscreenSurface::finishQmlLoad(QQmlComponent* qmlComponent, } // Allow child windows to be destroyed from JS QQmlEngine::setObjectOwnership(newObject, QQmlEngine::JavaScriptOwnership); + + // add object to the manual deletion list + _sharedObject->addToDeletionList(newObject); + newObject->setParent(parent); newItem->setParentItem(parent); } else { diff --git a/libraries/qml/src/qml/impl/SharedObject.cpp b/libraries/qml/src/qml/impl/SharedObject.cpp index 259defdb48..5bcca0821f 100644 --- a/libraries/qml/src/qml/impl/SharedObject.cpp +++ b/libraries/qml/src/qml/impl/SharedObject.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -96,6 +97,15 @@ SharedObject::~SharedObject() { } #endif + // already deleted objects will be reset to null by QPointer so it should be safe just iterate here + for (auto qmlObject : _deletionList) { + if (qmlObject) { + // manually delete not-deleted-yet qml items + QQmlEngine::setObjectOwnership(qmlObject, QQmlEngine::CppOwnership); + delete qmlObject; + } + } + if (_rootItem) { delete _rootItem; _rootItem = nullptr; @@ -412,6 +422,11 @@ bool SharedObject::fetchTexture(TextureAndFence& textureAndFence) { return true; } +void hifi::qml::impl::SharedObject::addToDeletionList(QObject * object) +{ + _deletionList.append(QPointer(object)); +} + void SharedObject::setProxyWindow(QWindow* window) { #ifndef DISABLE_QML _proxyWindow = window; diff --git a/libraries/qml/src/qml/impl/SharedObject.h b/libraries/qml/src/qml/impl/SharedObject.h index 002679c44d..ce9fcd46d2 100644 --- a/libraries/qml/src/qml/impl/SharedObject.h +++ b/libraries/qml/src/qml/impl/SharedObject.h @@ -66,7 +66,7 @@ public: void resume(); bool isPaused() const; bool fetchTexture(TextureAndFence& textureAndFence); - + void addToDeletionList(QObject* object); private: bool event(QEvent* e) override; @@ -91,6 +91,8 @@ private: void onAboutToQuit(); void updateTextureAndFence(const TextureAndFence& newTextureAndFence); + QList> _deletionList; + // Texture management TextureAndFence _latestTextureAndFence{ 0, 0 }; QQuickItem* _item{ nullptr }; diff --git a/libraries/recording/src/recording/Deck.cpp b/libraries/recording/src/recording/Deck.cpp index 69a8587581..4d65f0eb1b 100644 --- a/libraries/recording/src/recording/Deck.cpp +++ b/libraries/recording/src/recording/Deck.cpp @@ -180,9 +180,7 @@ void Deck::processFrames() { #ifdef WANT_RECORDING_DEBUG qCDebug(recordingLog) << "Setting timer for next processing " << nextInterval; #endif - _timer.singleShot(nextInterval, [this] { - processFrames(); - }); + _timer.singleShot(nextInterval, this, &Deck::processFrames); } void Deck::removeClip(const ClipConstPointer& clip) { diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index 0e380b6c02..bbb370010e 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -303,7 +303,7 @@ AmbientOcclusionEffect::AmbientOcclusionEffect() { } void AmbientOcclusionEffect::configure(const Config& config) { - DependencyManager::get()->setAmbientOcclusionEnabled(config.enabled); + DependencyManager::get()->setAmbientOcclusionEnabled(config.isEnabled()); bool shouldUpdateBlurs = false; bool shouldUpdateTechnique = false; diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index 864aef09e4..af6f6b21a3 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -78,7 +78,6 @@ using AmbientOcclusionFramebufferPointer = std::shared_ptr(blurName); - blurConfig->setProperty("filterScale", 1.0f); + blurConfig->filterScale = 1.0f; } } diff --git a/libraries/render-utils/src/CauterizedModel.cpp b/libraries/render-utils/src/CauterizedModel.cpp index c31345bc55..86d4793aa5 100644 --- a/libraries/render-utils/src/CauterizedModel.cpp +++ b/libraries/render-utils/src/CauterizedModel.cpp @@ -114,18 +114,22 @@ void CauterizedModel::updateClusterMatrices() { for (int i = 0; i < (int)_meshStates.size(); i++) { Model::MeshState& state = _meshStates[i]; const HFMMesh& mesh = hfmModel.meshes.at(i); + int meshIndex = i; + for (int j = 0; j < mesh.clusters.size(); j++) { const HFMCluster& cluster = mesh.clusters.at(j); + int clusterIndex = j; + if (_useDualQuaternionSkinning) { auto jointPose = _rig.getJointPose(cluster.jointIndex); Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans()); Transform clusterTransform; - Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform); + Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindTransform); state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform); state.clusterDualQuaternions[j].setCauterizationParameters(0.0f, jointPose.trans()); } else { auto jointMatrix = _rig.getJointTransform(cluster.jointIndex); - glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]); + glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]); } } } @@ -146,9 +150,11 @@ void CauterizedModel::updateClusterMatrices() { for (int i = 0; i < _cauterizeMeshStates.size(); i++) { Model::MeshState& state = _cauterizeMeshStates[i]; const HFMMesh& mesh = hfmModel.meshes.at(i); + int meshIndex = i; for (int j = 0; j < mesh.clusters.size(); j++) { const HFMCluster& cluster = mesh.clusters.at(j); + int clusterIndex = j; if (_useDualQuaternionSkinning) { if (_cauterizeBoneSet.find(cluster.jointIndex) == _cauterizeBoneSet.end()) { @@ -157,7 +163,7 @@ void CauterizedModel::updateClusterMatrices() { } else { Transform jointTransform(cauterizePose.rot(), cauterizePose.scale(), cauterizePose.trans()); Transform clusterTransform; - Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform); + Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindTransform); state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform); state.clusterDualQuaternions[j].setCauterizationParameters(1.0f, cauterizePose.trans()); } @@ -166,7 +172,7 @@ void CauterizedModel::updateClusterMatrices() { // not cauterized so just copy the value from the non-cauterized version. state.clusterMatrices[j] = _meshStates[i].clusterMatrices[j]; } else { - glm_mat4u_mul(cauterizeMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]); + glm_mat4u_mul(cauterizeMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]); } } } diff --git a/libraries/render-utils/src/DebugDeferredBuffer.h b/libraries/render-utils/src/DebugDeferredBuffer.h index 166366e65b..8afccfca13 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.h +++ b/libraries/render-utils/src/DebugDeferredBuffer.h @@ -25,7 +25,6 @@ class DebugDeferredBufferConfig : public render::Job::Config { Q_OBJECT - Q_PROPERTY(bool enabled MEMBER enabled) Q_PROPERTY(int mode MEMBER mode WRITE setMode) Q_PROPERTY(glm::vec4 size MEMBER size NOTIFY dirty) public: diff --git a/libraries/render-utils/src/DeferredBufferRead.slh b/libraries/render-utils/src/DeferredBufferRead.slh index f3b8c0404a..868b93ff91 100644 --- a/libraries/render-utils/src/DeferredBufferRead.slh +++ b/libraries/render-utils/src/DeferredBufferRead.slh @@ -76,15 +76,10 @@ DeferredFragment unpackDeferredFragmentNoPosition(vec2 texcoord) { // Diffuse color and unpack the mode and the metallicness frag.albedo = diffuseVal.xyz; - frag.scattering = 0.0; unpackModeMetallic(diffuseVal.w, frag.mode, frag.metallic); frag.obscurance = min(specularVal.w, frag.obscurance); - - if (frag.mode == FRAG_MODE_SCATTERING) { - frag.scattering = specularVal.x; - } - + frag.scattering = float(frag.mode == FRAG_MODE_SCATTERING) * specularVal.x; frag.fresnel = getFresnelF0(frag.metallic, diffuseVal.xyz); return frag; @@ -122,14 +117,11 @@ DeferredFragment unpackDeferredFragmentNoPositionNoAmbient(vec2 texcoord) { <$declareDeferredFrameTransform()$> vec4 unpackDeferredPosition(float depthValue, vec2 texcoord) { - int side = 0; - if (isStereo()) { - if (texcoord.x > 0.5) { - texcoord.x -= 0.5; - side = 1; - } - texcoord.x *= 2.0; - } + float check = float(isStereo()); + float check2 = check * float(texcoord.x > 0.5); + texcoord.x -= check2 * 0.5; + int side = int(check2); + texcoord.x *= 1.0 + check; return vec4(evalEyePositionFromZdb(side, depthValue, texcoord), 1.0); } @@ -142,19 +134,17 @@ vec4 unpackDeferredPositionFromZdb(vec2 texcoord) { vec4 unpackDeferredPositionFromZeye(vec2 texcoord) { float Zeye = -texture(linearZeyeMap, texcoord).x; - int side = 0; - if (isStereo()) { - if (texcoord.x > 0.5) { - texcoord.x -= 0.5; - side = 1; - } - texcoord.x *= 2.0; - } + + float check = float(isStereo()); + float check2 = check * float(texcoord.x > 0.5); + texcoord.x -= check2 * 0.5; + int side = int(check2); + texcoord.x *= 1.0 + check; + return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0); } DeferredFragment unpackDeferredFragment(DeferredFrameTransform deferredTransform, vec2 texcoord) { - float depthValue = texture(depthMap, texcoord).r; DeferredFragment frag = unpackDeferredFragmentNoPosition(texcoord); diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 9602bc4bf4..ea32c5ecb3 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -32,9 +32,11 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness if (alpha != 1.0) { discard; } - _fragColor0 = vec4(albedo, ((scattering > 0.0) ? packScatteringMetallic(metallic) : packShadedMetallic(metallic))); + + float check = float(scattering > 0.0); + _fragColor0 = vec4(albedo, mix(packShadedMetallic(metallic), packScatteringMetallic(metallic), check)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); - _fragColor2 = vec4(((scattering > 0.0) ? vec3(scattering) : emissive), occlusion); + _fragColor2 = vec4(mix(emissive, vec3(scattering), check), occlusion); _fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0); } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 8cf56ec7ad..e0fd9e970d 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -606,11 +606,16 @@ void RenderDeferredCleanup::run(const render::RenderContextPointer& renderContex } } +RenderDeferred::RenderDeferred(bool renderShadows): + _renderShadows(renderShadows) +{ + DependencyManager::get()->init(); +} + void RenderDeferred::configure(const Config& config) { } void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs& inputs) { - PROFILE_RANGE(render, "DeferredLighting"); auto deferredTransform = inputs.get0(); auto deferredFramebuffer = inputs.get1(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index a838d0c4d6..9fd9554d31 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -189,8 +189,7 @@ public: using Config = RenderDeferredConfig; using JobModel = render::Job::ModelI; - RenderDeferred() {} - RenderDeferred(bool renderShadows) : _renderShadows(renderShadows) {} + RenderDeferred(bool renderShadows = false); void configure(const Config& config); diff --git a/libraries/render-utils/src/DeferredTransform.slh b/libraries/render-utils/src/DeferredTransform.slh index 9b3ad213c6..93a3e61c51 100644 --- a/libraries/render-utils/src/DeferredTransform.slh +++ b/libraries/render-utils/src/DeferredTransform.slh @@ -116,6 +116,7 @@ bool isStereo() { float getStereoSideWidth(int resolutionLevel) { return float(int(frameTransform._stereoInfo.y) >> resolutionLevel); } + float getStereoSideHeight(int resolutionLevel) { return float(int(frameTransform._pixelInfo.w) >> resolutionLevel); } @@ -125,7 +126,7 @@ vec2 getStereoSideSize(int resolutionLevel) { } ivec4 getStereoSideInfoFromWidth(int xPos, int sideWidth) { - return ivec4(xPos < sideWidth ? ivec2(0, 0) : ivec2(1, sideWidth), sideWidth, isStereo()); + return ivec4((1 - int(xPos < sideWidth)) * ivec2(1, sideWidth), sideWidth, isStereo()); } ivec4 getStereoSideInfo(int xPos, int resolutionLevel) { diff --git a/libraries/render-utils/src/Fade.slh b/libraries/render-utils/src/Fade.slh index cdbdf1f91d..cd1e06f52e 100644 --- a/libraries/render-utils/src/Fade.slh +++ b/libraries/render-utils/src/Fade.slh @@ -85,10 +85,8 @@ float evalFadeGradient(FadeObjectParams params, vec3 position) { } float evalFadeAlpha(FadeObjectParams params, vec3 position) { - float alpha = evalFadeGradient(params, position)-params.threshold; - if (fadeParameters[params.category]._isInverted != 0) { - alpha = -alpha; - } + float alpha = evalFadeGradient(params, position) - params.threshold; + alpha *= 1.0 - 2.0 * float(fadeParameters[params.category]._isInverted); return alpha; } @@ -166,4 +164,4 @@ layout(location=RENDER_UTILS_ATTR_FADE3) out vec4 _fadeData3; _fadeData3 = inTexCoord4; <@endfunc@> -<@endif@> \ No newline at end of file +<@endif@> diff --git a/libraries/render-utils/src/Haze.slf b/libraries/render-utils/src/Haze.slf index 8d90b4c816..170e69eb2d 100644 --- a/libraries/render-utils/src/Haze.slf +++ b/libraries/render-utils/src/Haze.slf @@ -25,14 +25,13 @@ LAYOUT(binding=RENDER_UTILS_TEXTURE_HAZE_LINEAR_DEPTH) uniform sampler2D linearD vec4 unpackPositionFromZeye(vec2 texcoord) { float Zeye = -texture(linearDepthMap, texcoord).x; - int side = 0; - if (isStereo()) { - if (texcoord.x > 0.5) { - texcoord.x -= 0.5; - side = 1; - } - texcoord.x *= 2.0; - } + + float check = float(isStereo()); + float check2 = check * float(texcoord.x > 0.5); + texcoord.x -= check2 * 0.5; + int side = int(check2); + texcoord.x *= 1.0 + check; + return vec4(evalEyePositionFromZeye(side, Zeye, texcoord), 1.0); } diff --git a/libraries/render-utils/src/Haze.slh b/libraries/render-utils/src/Haze.slh index a7654da8d2..0bf1d5d689 100644 --- a/libraries/render-utils/src/Haze.slh +++ b/libraries/render-utils/src/Haze.slh @@ -63,20 +63,17 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirectionWS, vec3 // Height at which haze density is reduced by 95% (default set to 2000.0 for safety ,this should never happen) float height_95p = 2000.0; const float log_p_005 = log(0.05); + if (hazeParams.hazeKeyLightAltitudeFactor > 0.0f) { height_95p = -log_p_005 / hazeParams.hazeKeyLightAltitudeFactor; } // Note that we need the sine to be positive - float sin_pitch = abs(lightDirectionWS.y); - - float distance; const float minimumSinPitch = 0.001; - if (sin_pitch < minimumSinPitch) { - distance = height_95p / minimumSinPitch; - } else { - distance = height_95p / sin_pitch; - } + float sin_pitch = abs(lightDirectionWS.y); + sin_pitch = max(sin_pitch, minimumSinPitch); + + float distance = height_95p / sin_pitch; // Integration is from the fragment towards the light source // Note that the haze base reference affects only the haze density as function of altitude @@ -128,6 +125,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition } vec4 potentialFragColor; + const float EPSILON = 0.0000001f; if ((hazeParams.hazeMode & HAZE_MODE_IS_MODULATE_COLOR) == HAZE_MODE_IS_MODULATE_COLOR) { // Compute separately for each colour @@ -143,9 +141,9 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition const float slopeThreshold = 0.01; float deltaHeight = fragPositionWS.y - eyeWorldHeight; - if (abs(deltaHeight) > slopeThreshold) { - float t = hazeParams.hazeHeightFactor * deltaHeight; - hazeIntegral *= (1.0 - exp (-t)) / t; + float t = hazeParams.hazeHeightFactor * deltaHeight; + if (abs(t) > EPSILON) { + hazeIntegral *= mix(1.0, (1.0 - exp(-t)) / t, float(abs(deltaHeight) > slopeThreshold)); } vec3 hazeAmount = 1.0 - exp(-hazeIntegral); @@ -171,13 +169,9 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition const float slopeThreshold = 0.01; float deltaHeight = fragPositionWS.y - eyeWorldHeight; - if (abs(deltaHeight) > slopeThreshold) { - float t = hazeParams.hazeHeightFactor * deltaHeight; - // Protect from wild values - const float EPSILON = 0.0000001f; - if (abs(t) > EPSILON) { - hazeIntegral *= (1.0 - exp (-t)) / t; - } + float t = hazeParams.hazeHeightFactor * deltaHeight; + if (abs(t) > EPSILON) { + hazeIntegral *= mix(1.0, (1.0 - exp(-t)) / t, float(abs(deltaHeight) > slopeThreshold)); } float hazeAmount = 1.0 - exp(-hazeIntegral); @@ -189,9 +183,7 @@ vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePosition // Mix with background at far range const float BLEND_DISTANCE = 27000.0f; vec4 outFragColor = potentialFragColor; - if (distance > BLEND_DISTANCE) { - outFragColor.a *= hazeParams.backgroundBlend; - } + outFragColor.a *= mix(1.0, hazeParams.backgroundBlend, float(distance > BLEND_DISTANCE)); return outFragColor; } diff --git a/libraries/render-utils/src/Highlight.slh b/libraries/render-utils/src/Highlight.slh index 264b57acbb..85ff352207 100644 --- a/libraries/render-utils/src/Highlight.slh +++ b/libraries/render-utils/src/Highlight.slh @@ -45,11 +45,9 @@ void main(void) { highlightedDepth = -evalZeyeFromZdb(highlightedDepth); sceneDepth = -evalZeyeFromZdb(sceneDepth); - if (sceneDepth < highlightedDepth) { - outFragColor = vec4(params._fillOccludedColor, params._fillOccludedAlpha); - } else { - outFragColor = vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha); - } + outFragColor = mix(vec4(params._fillUnoccludedColor, params._fillUnoccludedAlpha), + vec4(params._fillOccludedColor, params._fillOccludedAlpha), + float(sceneDepth < highlightedDepth)); <@else@> discard; <@endif@> @@ -67,14 +65,13 @@ void main(void) { float outlinedDepth = 0.0; float sumOutlineDepth = 0.0; - for (y=0 ; y=0.0 && uv.y<=1.0) { - for (x=0 ; x=0.0 && uv.x<=1.0) - { + if (uv.y >= 0.0 && uv.y <= 1.0) { + for (x = 0; x < params._blurKernelSize; x++) { + if (uv.x >= 0.0 && uv.x <= 1.0) { outlinedDepth = texture(highlightedDepthMap, uv).x; float touch = (outlinedDepth < FAR_Z) ? 1.0 : 0.0; sumOutlineDepth = max(outlinedDepth * touch, sumOutlineDepth); @@ -86,11 +83,7 @@ void main(void) { } } - if (intensity > 0.0) { - // sumOutlineDepth /= intensity; - } else { - sumOutlineDepth = FAR_Z; - } + sumOutlineDepth = mix(FAR_Z, sumOutlineDepth, float(intensity > 0.0)); intensity /= weight; if (intensity < OPACITY_EPSILON) { @@ -106,11 +99,9 @@ void main(void) { sceneDepth = -evalZeyeFromZdb(sceneDepth); // Are we occluded? - if (sceneDepth < outlinedDepth) { - outFragColor = vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha); - } else { - outFragColor = vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha); - } + outFragColor = mix(vec4(params._outlineUnoccludedColor, intensity * params._outlineUnoccludedAlpha), + vec4(params._outlineOccludedColor, intensity * params._outlineOccludedAlpha), + float(sceneDepth < outlinedDepth)); } } diff --git a/libraries/render-utils/src/LightClusterGrid.slh b/libraries/render-utils/src/LightClusterGrid.slh index 62af92e6ce..cd944489ec 100644 --- a/libraries/render-utils/src/LightClusterGrid.slh +++ b/libraries/render-utils/src/LightClusterGrid.slh @@ -83,7 +83,7 @@ int clusterGrid_getClusterLightId(int index, int offset) { return element; */ int element = _clusterGridContent[GRID_FETCH_BUFFER((elementIndex >> 1))]; - return (((elementIndex & 0x00000001) == 1) ? (element >> 16) : element) & 0x0000FFFF; + return (element >> (16 * int((elementIndex & 0x00000001) == 1))) & 0x0000FFFF; } diff --git a/libraries/render-utils/src/LightClusterGrid_shared.slh b/libraries/render-utils/src/LightClusterGrid_shared.slh index 6d43e71920..cf58ce56ff 100644 --- a/libraries/render-utils/src/LightClusterGrid_shared.slh +++ b/libraries/render-utils/src/LightClusterGrid_shared.slh @@ -5,6 +5,14 @@ #define float_exp2 exp2 #endif +#ifdef __cplusplus +# define _MIN glm::min +# define _ABS(x) (int)fabsf(x) +#else +# define _MIN min +# define _ABS abs +#endif + float frustumGrid_depthRampGridToVolume(float ngrid) { // return ngrid; // return sqrt(ngrid); @@ -87,14 +95,9 @@ ivec3 frustumGrid_indexToCluster(int index) { } vec3 frustumGrid_clusterPosToEye(vec3 clusterPos) { - vec3 cvpos = clusterPos; - - vec3 volumePos = frustumGrid_gridToVolume(cvpos, frustumGrid.dims); - vec3 eyePos = frustumGrid_volumeToEye(volumePos, frustumGrid.eyeToGridProj, frustumGrid.rangeNear, frustumGrid.rangeFar); - return eyePos; } @@ -116,27 +119,19 @@ int frustumGrid_eyeDepthToClusterLayer(float eyeZ) { int gridZ = int(frustumGrid_volumeToGridDepth(volumeZ, frustumGrid.dims)); - if (gridZ >= frustumGrid.dims.z) { - gridZ = frustumGrid.dims.z; - } - - - return gridZ; + return _MIN(gridZ, frustumGrid.dims.z); } ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) { // make sure the frontEyePos is always in the front to eval the grid pos correctly vec3 frontEyePos = eyePos; - frontEyePos.z = (eyePos.z > 0.0f ? -eyePos.z : eyePos.z); + frontEyePos.z = -_ABS(eyePos.z); vec3 volumePos = frustumGrid_eyeToVolume(frontEyePos, frustumGrid.eyeToGridProj, frustumGrid.rangeNear, frustumGrid.rangeFar); vec3 gridPos = frustumGrid_volumeToGrid(volumePos, frustumGrid.dims); - - if (gridPos.z >= float(frustumGrid.dims.z)) { - gridPos.z = float(frustumGrid.dims.z); - } + gridPos.z = _MIN(gridPos.z, float(frustumGrid.dims.z)); ivec3 igridPos = ivec3(floor(gridPos)); @@ -154,7 +149,7 @@ ivec3 frustumGrid_eyeToClusterPos(vec3 eyePos) { int frustumGrid_eyeToClusterDirH(vec3 eyeDir) { if (eyeDir.z >= 0.0f) { - return (eyeDir.x > 0.0f ? frustumGrid.dims.x : -1); + return int(eyeDir.x > 0.0f) * (frustumGrid.dims.x + 1) - 1; } float eyeDepth = -eyeDir.z; @@ -168,7 +163,7 @@ int frustumGrid_eyeToClusterDirH(vec3 eyeDir) { int frustumGrid_eyeToClusterDirV(vec3 eyeDir) { if (eyeDir.z >= 0.0f) { - return (eyeDir.y > 0.0f ? frustumGrid.dims.y : -1); + return int(eyeDir.y > 0.0f) * (frustumGrid.dims.y + 1) - 1; } float eyeDepth = -eyeDir.z; @@ -196,4 +191,4 @@ vec4 frustumGrid_worldToEye(vec4 worldPos) { // <@if 1@> // Trigger Scribe include - // <@endif@> End C++ compatible \ No newline at end of file + // <@endif@> End C++ compatible diff --git a/libraries/render-utils/src/LightPoint.slh b/libraries/render-utils/src/LightPoint.slh index 1a361e3717..6100627105 100644 --- a/libraries/render-utils/src/LightPoint.slh +++ b/libraries/render-utils/src/LightPoint.slh @@ -41,12 +41,10 @@ void evalLightingPoint(out vec3 diffuse, out vec3 specular, Light light, specular *= lightEnergy * isSpecularEnabled(); if (isShowLightContour() > 0.0) { - // Show edge + // Show edges float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edgeCoord = exp2(-8.0 * edge * edge); + diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); } } @@ -59,13 +57,11 @@ bool evalLightPointEdge(out vec3 color, Light light, vec4 fragLightDirLen, vec3 // Allright we re valid in the volume float fragLightDistance = fragLightDirLen.w; vec3 fragLightDir = fragLightDirLen.xyz; - + // Show edges float edge = abs(2.0 * ((lightVolume_getRadius(light.volume) - fragLightDistance) / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - color = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edgeCoord = exp2(-8.0 * edge * edge); + color = mix(color, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); return (edge < 1.0); } diff --git a/libraries/render-utils/src/LightSpot.slh b/libraries/render-utils/src/LightSpot.slh index 2546c0225c..7fea9856d8 100644 --- a/libraries/render-utils/src/LightSpot.slh +++ b/libraries/render-utils/src/LightSpot.slh @@ -46,11 +46,9 @@ void evalLightingSpot(out vec3 diffuse, out vec3 specular, Light light, float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); float edgeDist = min(edgeDistR, edgeDistS); - float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - diffuse = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edge = abs(2.0 * (edgeDist * 10.0) - 1.0); + float edgeCoord = exp2(-8.0 * edge * edge); + diffuse = mix(diffuse, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); } } @@ -67,15 +65,11 @@ bool evalLightSpotEdge(out vec3 color, Light light, vec4 fragLightDirLen, float float edgeDistR = (lightVolume_getRadius(light.volume) - fragLightDistance); float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -lightVolume_getSpotOutsideNormal2(light.volume)); float edgeDist = min(edgeDistR, edgeDistS); - float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0); - if (edge < 1.0) { - float edgeCoord = exp2(-8.0*edge*edge); - color = vec3(edgeCoord * edgeCoord * getLightColor(light)); - } + float edge = abs(2.0 * (edgeDist * 10.0) - 1.0); + float edgeCoord = exp2(-8.0 * edge * edge); + color = mix(color, vec3(edgeCoord * edgeCoord * getLightColor(light)), float(edge < 1.0)); return (edge < 1.0); } <@endfunc@> - - diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index 8fe3b0fef5..d5e1ca4644 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -444,10 +444,12 @@ LightStageSetup::LightStageSetup() { } void LightStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage(LightStage::getName()); - if (!stage) { - stage = std::make_shared(); - renderContext->_scene->resetStage(LightStage::getName(), stage); + if (renderContext->_scene) { + auto stage = renderContext->_scene->getStage(LightStage::getName()); + if (!stage) { + stage = std::make_shared(); + renderContext->_scene->resetStage(LightStage::getName(), stage); + } } } diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 7da7a45e83..9cefbf65a8 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1418,18 +1418,21 @@ void Model::updateClusterMatrices() { const HFMModel& hfmModel = getHFMModel(); for (int i = 0; i < (int) _meshStates.size(); i++) { MeshState& state = _meshStates[i]; + int meshIndex = i; const HFMMesh& mesh = hfmModel.meshes.at(i); for (int j = 0; j < mesh.clusters.size(); j++) { const HFMCluster& cluster = mesh.clusters.at(j); + int clusterIndex = j; + if (_useDualQuaternionSkinning) { auto jointPose = _rig.getJointPose(cluster.jointIndex); Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans()); Transform clusterTransform; - Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform); + Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindTransform); state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform); } else { auto jointMatrix = _rig.getJointTransform(cluster.jointIndex); - glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]); + glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]); } } } diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 0b6aebadd7..b5b3e9c5b9 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -38,7 +38,7 @@ using namespace render; extern void initZPassPipelines(ShapePlumber& plumber, gpu::StatePointer state, const render::ShapePipeline::BatchSetter& batchSetter, const render::ShapePipeline::ItemSetter& itemSetter); void RenderShadowTask::configure(const Config& configuration) { - DependencyManager::get()->setShadowMapEnabled(configuration.enabled); + DependencyManager::get()->setShadowMapEnabled(configuration.isEnabled()); // This is a task, so must still propogate configure() to its Jobs // Task::configure(configuration); } diff --git a/libraries/render-utils/src/RenderShadowTask.h b/libraries/render-utils/src/RenderShadowTask.h index 8aaf554514..e90725d66d 100644 --- a/libraries/render-utils/src/RenderShadowTask.h +++ b/libraries/render-utils/src/RenderShadowTask.h @@ -38,7 +38,6 @@ protected: class RenderShadowTaskConfig : public render::Task::Config::Persistent { Q_OBJECT - Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty) public: RenderShadowTaskConfig() : render::Task::Config::Persistent(QStringList() << "Render" << "Engine" << "Shadows", true) {} diff --git a/libraries/render-utils/src/Shadow.slh b/libraries/render-utils/src/Shadow.slh index 9506c9805d..b503844554 100644 --- a/libraries/render-utils/src/Shadow.slh +++ b/libraries/render-utils/src/Shadow.slh @@ -115,18 +115,10 @@ float evalShadowAttenuation(vec3 worldLightDir, vec4 worldPosition, float viewDe isPixelOnCascade.z = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[2]); isPixelOnCascade.w = isShadowCascadeProjectedOnPixel(cascadeShadowCoords[3]); - if (isPixelOnCascade.x) { - cascadeAttenuations.x = evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL); - } - if (isPixelOnCascade.y) { - cascadeAttenuations.y = evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL); - } - if (isPixelOnCascade.z) { - cascadeAttenuations.z = evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL); - } - if (isPixelOnCascade.w) { - cascadeAttenuations.w = evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL); - } + cascadeAttenuations.x = mix(1.0, evalShadowCascadeAttenuation(0, offsets, cascadeShadowCoords[0], oneMinusNdotL), float(isPixelOnCascade.x)); + cascadeAttenuations.y = mix(1.0, evalShadowCascadeAttenuation(1, offsets, cascadeShadowCoords[1], oneMinusNdotL), float(isPixelOnCascade.y)); + cascadeAttenuations.z = mix(1.0, evalShadowCascadeAttenuation(2, offsets, cascadeShadowCoords[2], oneMinusNdotL), float(isPixelOnCascade.z)); + cascadeAttenuations.w = mix(1.0, evalShadowCascadeAttenuation(3, offsets, cascadeShadowCoords[3], oneMinusNdotL), float(isPixelOnCascade.w)); cascadeWeights.x = evalShadowCascadeWeight(cascadeShadowCoords[0]); cascadeWeights.y = evalShadowCascadeWeight(cascadeShadowCoords[1]); diff --git a/libraries/render-utils/src/Skinning.slh b/libraries/render-utils/src/Skinning.slh index 63246e85a1..30d5efd64e 100644 --- a/libraries/render-utils/src/Skinning.slh +++ b/libraries/render-utils/src/Skinning.slh @@ -81,9 +81,7 @@ void evalSkinning(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio // to ensure that we rotate along the shortest arc, reverse dual quaternions with negative polarity. float dqClusterWeight = clusterWeight; - if (dot(real, polarityReference) < 0.0) { - dqClusterWeight = -clusterWeight; - } + dqClusterWeight *= mix(1.0, -1.0, float(dot(real, polarityReference) < 0.0)); sAccum += scale * clusterWeight; rAccum += real * dqClusterWeight; @@ -102,12 +100,11 @@ void evalSkinning(ivec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPositio // sAccum.w indicates the amount of cauterization for this vertex. // 0 indicates no cauterization and 1 indicates full cauterization. // TODO: make this cauterization smoother or implement full dual-quaternion scale support. - const float CAUTERIZATION_THRESHOLD = 0.1; - if (sAccum.w > CAUTERIZATION_THRESHOLD) { - skinnedPosition = cAccum; - } else { - sAccum.w = 1.0; - skinnedPosition = m * (sAccum * inPosition); + { + const float CAUTERIZATION_THRESHOLD = 0.1; + float check = float(sAccum.w > CAUTERIZATION_THRESHOLD); + sAccum.w = mix(1.0, sAccum.w, check); + skinnedPosition = mix(m * (sAccum * inPosition), cAccum, check); } <@if USE_NORMAL@> diff --git a/libraries/render-utils/src/SoftAttachmentModel.cpp b/libraries/render-utils/src/SoftAttachmentModel.cpp index f26bad86b0..a6f82e1417 100644 --- a/libraries/render-utils/src/SoftAttachmentModel.cpp +++ b/libraries/render-utils/src/SoftAttachmentModel.cpp @@ -46,32 +46,25 @@ void SoftAttachmentModel::updateClusterMatrices() { for (int i = 0; i < (int) _meshStates.size(); i++) { MeshState& state = _meshStates[i]; const HFMMesh& mesh = hfmModel.meshes.at(i); - + int meshIndex = i; for (int j = 0; j < mesh.clusters.size(); j++) { const HFMCluster& cluster = mesh.clusters.at(j); + int clusterIndex = j; // TODO: cache these look-ups as an optimization int jointIndexOverride = getJointIndexOverride(cluster.jointIndex); + glm::mat4 jointMatrix; + if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride.getJointStateCount()) { + jointMatrix = _rigOverride.getJointTransform(jointIndexOverride); + } else { + jointMatrix = _rig.getJointTransform(cluster.jointIndex); + } if (_useDualQuaternionSkinning) { - glm::mat4 jointMatrix; - if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride.getJointStateCount()) { - jointMatrix = _rigOverride.getJointTransform(jointIndexOverride); - } else { - jointMatrix = _rig.getJointTransform(cluster.jointIndex); - } - glm::mat4 m; - glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, m); + glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, m); state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(m); } else { - glm::mat4 jointMatrix; - if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride.getJointStateCount()) { - jointMatrix = _rigOverride.getJointTransform(jointIndexOverride); - } else { - jointMatrix = _rig.getJointTransform(cluster.jointIndex); - } - - glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]); + glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]); } } } diff --git a/libraries/render-utils/src/SubsurfaceScattering.slh b/libraries/render-utils/src/SubsurfaceScattering.slh index 66b3ab1ea0..b4981110f2 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.slh +++ b/libraries/render-utils/src/SubsurfaceScattering.slh @@ -82,8 +82,6 @@ vec3 integrate(float cosTheta, float skinRadius) { while (a <= (_PI)) { float sampleAngle = theta + a; float diffuse = clamp(cos(sampleAngle), 0.0, 1.0); - //if (diffuse < 0.0) diffuse = 0.0; - //if (diffuse > 1.0) diffuse = 1.0; // Distance. float sampleDist = abs(2.0 * skinRadius * sin(a * 0.5)); @@ -180,7 +178,8 @@ vec3 evalSkinBRDF(vec3 lightDir, vec3 normal, vec3 midNormal, vec3 lowNormal, fl return lowNormal * 0.5 + vec3(0.5); } if (showCurvature()) { - return (curvature > 0.0 ? vec3(curvature, 0.0, 0.0) : vec3(0.0, 0.0, -curvature)); + float check = float(curvature > 0.0); + return vec3(check * curvature, 0.0, (1.0 - check) * -curvature); } vec3 bentNdotL = evalScatteringBentNdotL(normal, midNormal, lowNormal, lightDir); diff --git a/libraries/render-utils/src/ToneMappingEffect.h b/libraries/render-utils/src/ToneMappingEffect.h index 046e7606b3..69694b13f5 100644 --- a/libraries/render-utils/src/ToneMappingEffect.h +++ b/libraries/render-utils/src/ToneMappingEffect.h @@ -64,7 +64,6 @@ private: class ToneMappingConfig : public render::Job::Config { Q_OBJECT - Q_PROPERTY(bool enabled MEMBER enabled) Q_PROPERTY(float exposure MEMBER exposure WRITE setExposure); Q_PROPERTY(int curve MEMBER curve WRITE setCurve); public: diff --git a/libraries/render-utils/src/deferred_light_limited.slv b/libraries/render-utils/src/deferred_light_limited.slv index 1c835aacf7..0126d54664 100644 --- a/libraries/render-utils/src/deferred_light_limited.slv +++ b/libraries/render-utils/src/deferred_light_limited.slv @@ -37,9 +37,7 @@ void main(void) { #ifdef GPU_TRANSFORM_IS_STEREO #ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN #else - if (cam_isStereo()) { - projected.x = 0.5 * (projected.x + cam_getStereoSide()); - } + projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo())); #endif #endif _texCoord01 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w; @@ -66,9 +64,7 @@ void main(void) { #ifdef GPU_TRANSFORM_IS_STEREO #ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN #else - if (cam_isStereo()) { - _texCoord01.x = 0.5 * (_texCoord01.x + cam_getStereoSide()); - } + _texCoord01.x = mix(_texCoord01.x, 0.5 * (_texCoord01.x + cam_getStereoSide()), float(cam_isStereo())); #endif #endif diff --git a/libraries/render-utils/src/deferred_light_point.slv b/libraries/render-utils/src/deferred_light_point.slv index 3e6329be83..c77ead439c 100644 --- a/libraries/render-utils/src/deferred_light_point.slv +++ b/libraries/render-utils/src/deferred_light_point.slv @@ -47,8 +47,6 @@ void main(void) { vec4 projected = gl_Position / gl_Position.w; projected.xy = (projected.xy + 1.0) * 0.5; - if (cam_isStereo()) { - projected.x = 0.5 * (projected.x + cam_getStereoSide()); - } + projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo())); _texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w; } diff --git a/libraries/render-utils/src/deferred_light_spot.slv b/libraries/render-utils/src/deferred_light_spot.slv index 0370acc6bc..332bb96167 100644 --- a/libraries/render-utils/src/deferred_light_spot.slv +++ b/libraries/render-utils/src/deferred_light_spot.slv @@ -60,9 +60,7 @@ void main(void) { #ifdef GPU_TRANSFORM_IS_STEREO #ifdef GPU_TRANSFORM_STEREO_SPLIT_SCREEN #else - if (cam_isStereo()) { - projected.x = 0.5 * (projected.x + cam_getStereoSide()); - } + projected.x = mix(projected.x, 0.5 * (projected.x + cam_getStereoSide()), float(cam_isStereo())); #endif #endif _texCoord0 = vec4(projected.xy, 0.0, 1.0) * gl_Position.w; diff --git a/libraries/render-utils/src/deformed_model.slv b/libraries/render-utils/src/deformed_model.slv index 039ad0a7d9..8c6d3d049d 100644 --- a/libraries/render-utils/src/deformed_model.slv +++ b/libraries/render-utils/src/deformed_model.slv @@ -44,13 +44,13 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/deformed_model_dq.slv b/libraries/render-utils/src/deformed_model_dq.slv index 2165f3b9a4..56ac1b6558 100644 --- a/libraries/render-utils/src/deformed_model_dq.slv +++ b/libraries/render-utils/src/deformed_model_dq.slv @@ -41,13 +41,13 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/deformed_model_normal_map.slv b/libraries/render-utils/src/deformed_model_normal_map.slv index 8627b5b856..85e164b639 100644 --- a/libraries/render-utils/src/deformed_model_normal_map.slv +++ b/libraries/render-utils/src/deformed_model_normal_map.slv @@ -43,14 +43,14 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> <$transformModelToWorldDir(cam, obj, deformedTangent, _tangentWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/deformed_model_normal_map_dq.slv b/libraries/render-utils/src/deformed_model_normal_map_dq.slv index b45d94938a..807d343643 100644 --- a/libraries/render-utils/src/deformed_model_normal_map_dq.slv +++ b/libraries/render-utils/src/deformed_model_normal_map_dq.slv @@ -44,14 +44,14 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$> <$transformModelToWorldDir(cam, obj, deformedTangent, _tangentWS.xyz)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 15d00f713e..b1cfc26c66 100644 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -33,16 +33,15 @@ void main(void) { float shadowAttenuation = 1.0; - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; vec3 color = evalAmbientSphereGlobalColor( getViewInverse(), diff --git a/libraries/render-utils/src/directional_ambient_light_shadow.slf b/libraries/render-utils/src/directional_ambient_light_shadow.slf index d6cdf78f19..6b9fb80232 100644 --- a/libraries/render-utils/src/directional_ambient_light_shadow.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow.slf @@ -35,16 +35,16 @@ void main(void) { vec3 worldLightDirection = getLightDirection(shadowLight); float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal); - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; + vec3 color = evalAmbientSphereGlobalColor( getViewInverse(), shadowAttenuation, diff --git a/libraries/render-utils/src/directional_skybox_light.slf b/libraries/render-utils/src/directional_skybox_light.slf index b27d759dd4..b820b3d17f 100644 --- a/libraries/render-utils/src/directional_skybox_light.slf +++ b/libraries/render-utils/src/directional_skybox_light.slf @@ -31,16 +31,16 @@ void main(void) { float shadowAttenuation = 1.0; // Light mapped or not ? - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; + vec3 color = evalSkyboxGlobalColor( getViewInverse(), shadowAttenuation, diff --git a/libraries/render-utils/src/directional_skybox_light_shadow.slf b/libraries/render-utils/src/directional_skybox_light_shadow.slf index 292f7348e3..8716d60d54 100644 --- a/libraries/render-utils/src/directional_skybox_light_shadow.slf +++ b/libraries/render-utils/src/directional_skybox_light_shadow.slf @@ -36,16 +36,16 @@ void main(void) { float shadowAttenuation = evalShadowAttenuation(worldLightDirection, worldPos, -viewPos.z, frag.normal); // Light mapped or not ? - if (frag.mode == FRAG_MODE_UNLIT) { - discard; - } else if (frag.mode == FRAG_MODE_LIGHTMAPPED) { + if (frag.mode == FRAG_MODE_UNLIT || frag.mode == FRAG_MODE_LIGHTMAPPED) { discard; } else { vec4 midNormalCurvature = vec4(0); vec4 lowNormalCurvature = vec4(0); - if (frag.mode == FRAG_MODE_SCATTERING) { - unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); - } + unpackMidLowNormalCurvature(_texCoord0, midNormalCurvature, lowNormalCurvature); + float check = float(frag.mode == FRAG_MODE_SCATTERING); + midNormalCurvature = check * midNormalCurvature; + lowNormalCurvature = check * lowNormalCurvature; + vec3 color = evalSkyboxGlobalColor( getViewInverse(), shadowAttenuation, diff --git a/libraries/render-utils/src/drawWorkloadProxy.slv b/libraries/render-utils/src/drawWorkloadProxy.slv index 7a01702107..9dfcf8415c 100644 --- a/libraries/render-utils/src/drawWorkloadProxy.slv +++ b/libraries/render-utils/src/drawWorkloadProxy.slv @@ -62,7 +62,5 @@ void main(void) { varColor = vec4(REGION_COLOR[region].xyz, proxy.sphere.w); - if (region == 4) { - gl_Position = vec4(0.0); - } + gl_Position = mix(gl_Position, vec4(0.0), float(region == 4)); } diff --git a/libraries/render-utils/src/glowLine.slv b/libraries/render-utils/src/glowLine.slv index 167aeb8c9e..3471bc2f98 100644 --- a/libraries/render-utils/src/glowLine.slv +++ b/libraries/render-utils/src/glowLine.slv @@ -53,14 +53,9 @@ void main(void) { // Add or subtract the orthogonal vector based on a different vertex ID // calculation - if (gl_VertexID < 2) { - distanceFromCenter = -1.0; - eye.xyz -= orthogonal; - } else { - distanceFromCenter = 1.0; - eye.xyz += orthogonal; - } + distanceFromCenter = 1.0 - 2.0 * float(gl_VertexID < 2); + eye.xyz += distanceFromCenter * orthogonal; // Finally, put the eyespace vertex into clip space <$transformEyeToClipPos(cam, eye, gl_Position)$> -} \ No newline at end of file +} diff --git a/libraries/render-utils/src/grid.slf b/libraries/render-utils/src/grid.slf index 8e9b35dace..408a9ca190 100644 --- a/libraries/render-utils/src/grid.slf +++ b/libraries/render-utils/src/grid.slf @@ -34,12 +34,10 @@ layout(location=0) out vec4 outFragColor; void main(void) { Grid grid = getGrid(); - float alpha; - if (grid.edge.z == 0.0) { - alpha = paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy); - } else { - alpha = paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge); - } + float alpha = mix(paintGridMajorMinor(varTexCoord0, grid.offset, grid.period, grid.edge), + paintGrid(varTexCoord0, grid.offset.xy, grid.period.xy, grid.edge.xy), + float(grid.edge.z == 0.0)); + if (alpha == 0.0) { discard; } diff --git a/libraries/render-utils/src/lightClusters_drawClusterContent.slf b/libraries/render-utils/src/lightClusters_drawClusterContent.slf index 27cb838566..80013bc3cc 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterContent.slf +++ b/libraries/render-utils/src/lightClusters_drawClusterContent.slf @@ -90,6 +90,6 @@ void main(void) { numLightTouching++; } - _fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), (numLightTouching > 0 ? 0.5 + 0.5 * numLightsScale : 0.0)); + _fragColor = vec4(colorRamp(1.0 - (float(numLightTouching) / 12.0f)), float(numLightTouching > 0) * (0.5 + 0.5 * numLightsScale)); } diff --git a/libraries/render-utils/src/lightClusters_drawClusterContent.slv b/libraries/render-utils/src/lightClusters_drawClusterContent.slv index 1303cf3926..c30252da41 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterContent.slv +++ b/libraries/render-utils/src/lightClusters_drawClusterContent.slv @@ -69,5 +69,5 @@ void main(void) { TransformCamera cam = getTransformCamera(); <$transformWorldToClipPos(cam, worldPos, gl_Position)$> - varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), (numLights >0 ? 0.9 : 0.1)); + varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.1 + 0.8 * float(numLights > 0)); } \ No newline at end of file diff --git a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf index abbd86dd70..0e3f8a5ea5 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf +++ b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slf @@ -62,12 +62,10 @@ void main(void) { float relClusterId = float(clusterPos.z * summedDims.x + clusterPos.y * summedDims.y + clusterPos.x) / float(frustumGrid_numClusters()); - if (relClusterId < 0.0) { - _fragColor = vec4(0.0); - } else if (relClusterId >= 1.0) { - _fragColor = vec4(vec3(1.0), 0.2); - } else { - _fragColor = vec4(colorWheel(fract(relClusterId)), (numLights > 0 ? 0.05 + 0.95 * numLightsScale : 0.0)); - } + _fragColor = mix(mix(vec4(colorWheel(fract(relClusterId)), float(numLights > 0) * (0.05 + 0.95 * numLightsScale)), + vec4(vec3(1.0), 0.2), + float(relClusterId >= 1.0)), + vec4(0.0), + float(relClusterId < 0.0)); } diff --git a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv index d35c7cb20b..a5c037cc7a 100644 --- a/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv +++ b/libraries/render-utils/src/lightClusters_drawClusterFromDepth.slv @@ -62,5 +62,5 @@ void main(void) { TransformCamera cam = getTransformCamera(); <$transformWorldToClipPos(cam, worldPos, gl_Position)$> - varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.9); + varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), 0.9); } \ No newline at end of file diff --git a/libraries/render-utils/src/lightClusters_drawGrid.slv b/libraries/render-utils/src/lightClusters_drawGrid.slv index c4aff45beb..8d557d01c8 100644 --- a/libraries/render-utils/src/lightClusters_drawGrid.slv +++ b/libraries/render-utils/src/lightClusters_drawGrid.slv @@ -69,5 +69,5 @@ void main(void) { TransformCamera cam = getTransformCamera(); <$transformWorldToClipPos(cam, worldPos, gl_Position)$> - varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), (numLights > 0 ? 0.9 : 0.0)); + varColor = vec4(colorWheel(fract(float(gpu_InstanceID()) / float(frustumGrid_numClusters()))), float(numLights > 0) * 0.9); } \ No newline at end of file diff --git a/libraries/render-utils/src/local_lights_drawOutline.slf b/libraries/render-utils/src/local_lights_drawOutline.slf index fc1d416f96..a2b4cc1d10 100644 --- a/libraries/render-utils/src/local_lights_drawOutline.slf +++ b/libraries/render-utils/src/local_lights_drawOutline.slf @@ -96,9 +96,8 @@ void main(void) { vec3 fragLightDir = fragLightDirLen.xyz; vec3 color = vec3(0.0); - if (evalLightPointEdge(color, light, fragLightDirLen, fragEyeDir)) { - _fragColor.rgb += color; - } + float check = float(evalLightPointEdge(color, light, fragLightDirLen, fragEyeDir)); + _fragColor.rgb += check * color; } for (int i = cluster.x; i < numLights; i++) { @@ -130,10 +129,8 @@ void main(void) { numLightTouching++; vec3 color = vec3(0.0); - - if (evalLightSpotEdge(color, light, fragLightDirLen, cosSpotAngle, fragEyeDir)) { - _fragColor.rgb += color; - } + float check = float(evalLightSpotEdge(color, light, fragLightDirLen, cosSpotAngle, fragEyeDir)); + _fragColor.rgb += check * color; } } diff --git a/libraries/render-utils/src/model.slv b/libraries/render-utils/src/model.slv index f3d315c7a4..88cbd1e18c 100644 --- a/libraries/render-utils/src/model.slv +++ b/libraries/render-utils/src/model.slv @@ -31,13 +31,13 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, inPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv index 94d8a43b6e..0fd9a8b582 100644 --- a/libraries/render-utils/src/model_normal_map.slv +++ b/libraries/render-utils/src/model_normal_map.slv @@ -32,14 +32,14 @@ void main(void) { _color.rgb = color_sRGBToLinear(inColor.rgb); _color.a = inColor.a; - TexMapArray texMapArray = getTexMapArray(); - <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _texCoord01.xy)$> - <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _texCoord01.zw)$> - // standard transform TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToWorldAndEyeAndClipPos(cam, obj, inPosition, _positionWS, _positionES, gl_Position)$> <$transformModelToWorldDir(cam, obj, inNormal.xyz, _normalWS)$> <$transformModelToWorldDir(cam, obj, inTangent.xyz, _tangentWS)$> + + TexMapArray texMapArray = getTexMapArray(); + <$evalTexMapArrayTexcoord0(texMapArray, inTexCoord0, _positionWS, _texCoord01.xy)$> + <$evalTexMapArrayTexcoord1(texMapArray, inTexCoord1, _positionWS, _texCoord01.zw)$> } diff --git a/libraries/render-utils/src/parabola.slv b/libraries/render-utils/src/parabola.slv index 53dfc75cfe..6032452d1d 100644 --- a/libraries/render-utils/src/parabola.slv +++ b/libraries/render-utils/src/parabola.slv @@ -48,11 +48,8 @@ void main(void) { } else { normal = vec4(normalize(cross(_parabolaData.velocity, _parabolaData.acceleration)), 0); } - if (gl_VertexID % 2 == 0) { - pos += 0.5 * _parabolaData.width * normal; - } else { - pos -= 0.5 * _parabolaData.width * normal; - } + + pos += 0.5 * _parabolaData.width * normal * (-1.0 + 2.0 * float(gl_VertexID % 2 == 0)); <$transformModelToClipPos(cam, obj, pos, gl_Position)$> -} \ No newline at end of file +} diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 35e670eef8..b070fc44cf 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -39,13 +39,8 @@ const float taaBias = pow(2.0, TAA_TEXTURE_LOD_BIAS); float evalSDF(vec2 texCoord) { // retrieve signed distance float sdf = textureLod(Font, texCoord, TAA_TEXTURE_LOD_BIAS).g; - if (params.outline.x > 0.0) { - if (sdf > interiorCutoff) { - sdf = 1.0 - sdf; - } else { - sdf += outlineExpansion; - } - } + sdf = mix(sdf, mix(sdf + outlineExpansion, 1.0 - sdf, float(sdf > interiorCutoff)), float(params.outline.x > 0.0)); + // Rely on TAA for anti-aliasing return step(0.5, sdf); } @@ -57,16 +52,11 @@ void main() { // Perform 4x supersampling for anisotropic filtering float a; a = evalSDF(_texCoord0); - a += evalSDF(_texCoord0+dxTexCoord); - a += evalSDF(_texCoord0+dyTexCoord); - a += evalSDF(_texCoord0+dxTexCoord+dyTexCoord); + a += evalSDF(_texCoord0 + dxTexCoord); + a += evalSDF(_texCoord0 + dyTexCoord); + a += evalSDF(_texCoord0 + dxTexCoord + dyTexCoord); a *= 0.25; - // discard if invisible - if (a < 0.01) { - discard; - } - packDeferredFragment( normalize(_normalWS), a * params.color.a, diff --git a/libraries/render-utils/src/sdf_text3D_transparent.slf b/libraries/render-utils/src/sdf_text3D_transparent.slf index cc4cdfb72f..2fbfb2ca43 100644 --- a/libraries/render-utils/src/sdf_text3D_transparent.slf +++ b/libraries/render-utils/src/sdf_text3D_transparent.slf @@ -30,31 +30,32 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord0 _texCoord01.xy #define _texCoord1 _texCoord01.zw -const float gamma = 2.2; -const float smoothing = 32.0; +#define TAA_TEXTURE_LOD_BIAS -3.0 + const float interiorCutoff = 0.8; const float outlineExpansion = 0.2; +const float taaBias = pow(2.0, TAA_TEXTURE_LOD_BIAS); + +float evalSDF(vec2 texCoord) { + // retrieve signed distance + float sdf = textureLod(Font, texCoord, TAA_TEXTURE_LOD_BIAS).g; + sdf = mix(sdf, mix(sdf + outlineExpansion, 1.0 - sdf, float(sdf > interiorCutoff)), float(params.outline.x > 0.0)); + + // Rely on TAA for anti-aliasing + return step(0.5, sdf); +} void main() { - // retrieve signed distance - float sdf = texture(Font, _texCoord0).g; - if (params.outline.x > 0.0) { - if (sdf > interiorCutoff) { - sdf = 1.0 - sdf; - } else { - sdf += outlineExpansion; - } - } - // perform adaptive anti-aliasing of the edges - // The larger we're rendering, the less anti-aliasing we need - float s = smoothing * length(fwidth(_texCoord0)); - float w = clamp(s, 0.0, 0.5); - float a = smoothstep(0.5 - w, 0.5 + w, sdf); - - // discard if invisible - if (a < 0.01) { - discard; - } + vec2 dxTexCoord = dFdx(_texCoord0) * 0.5 * taaBias; + vec2 dyTexCoord = dFdy(_texCoord0) * 0.5 * taaBias; + + // Perform 4x supersampling for anisotropic filtering + float a; + a = evalSDF(_texCoord0); + a += evalSDF(_texCoord0 + dxTexCoord); + a += evalSDF(_texCoord0 + dyTexCoord); + a += evalSDF(_texCoord0 + dxTexCoord + dyTexCoord); + a *= 0.25; packDeferredFragmentTranslucent( normalize(_normalWS), diff --git a/libraries/render-utils/src/simple.slf b/libraries/render-utils/src/simple.slf index dac01aac89..d2ddaa8e55 100644 --- a/libraries/render-utils/src/simple.slf +++ b/libraries/render-utils/src/simple.slf @@ -54,7 +54,7 @@ void main(void) { vec3 specular = DEFAULT_SPECULAR; float shininess = DEFAULT_SHININESS; float emissiveAmount = 0.0; - + #ifdef PROCEDURAL #ifdef PROCEDURAL_V1 diff --git a/libraries/render-utils/src/simple_textured.slf b/libraries/render-utils/src/simple_textured.slf index b308b57345..9494edb890 100644 --- a/libraries/render-utils/src/simple_textured.slf +++ b/libraries/render-utils/src/simple_textured.slf @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> <@include render-utils/ShaderConstants.h@> @@ -28,11 +29,13 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; void main(void) { vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; packDeferredFragment( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb, + texel.rgb, DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_EMISSIVE, diff --git a/libraries/render-utils/src/simple_textured_fade.slf b/libraries/render-utils/src/simple_textured_fade.slf index 9132505d8e..5ca21a71ac 100644 --- a/libraries/render-utils/src/simple_textured_fade.slf +++ b/libraries/render-utils/src/simple_textured_fade.slf @@ -39,26 +39,24 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - + vec4 texel = texture(originalTexture, _texCoord0); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a = abs(_color.a); const float ALPHA_THRESHOLD = 0.999; - if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + if (texel.a < ALPHA_THRESHOLD) { packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha * texel.a, - _color.rgb * texel.rgb + fadeEmissive, + texel.a, + texel.rgb + fadeEmissive, DEFAULT_ROUGHNESS); } else { packDeferredFragment( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb, + texel.rgb, DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_EMISSIVE + fadeEmissive, diff --git a/libraries/render-utils/src/simple_textured_unlit.slf b/libraries/render-utils/src/simple_textured_unlit.slf index 87fecee9cd..2d8f228f1c 100644 --- a/libraries/render-utils/src/simple_textured_unlit.slf +++ b/libraries/render-utils/src/simple_textured_unlit.slf @@ -28,24 +28,22 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; #define _texCoord1 _texCoord01.zw void main(void) { - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a = abs(_color.a); const float ALPHA_THRESHOLD = 0.999; - if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + if (texel.a < ALPHA_THRESHOLD) { packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha * texel.a, - _color.rgb * texel.rgb, + texel.a, + texel.rgb, DEFAULT_ROUGHNESS); } else { packDeferredFragmentUnlit( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb); + texel.rgb); } } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_textured_unlit_fade.slf b/libraries/render-utils/src/simple_textured_unlit_fade.slf index edaa3b592a..442be14a8e 100644 --- a/libraries/render-utils/src/simple_textured_unlit_fade.slf +++ b/libraries/render-utils/src/simple_textured_unlit_fade.slf @@ -40,24 +40,22 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a = abs(_color.a); const float ALPHA_THRESHOLD = 0.999; - if (colorAlpha * texel.a < ALPHA_THRESHOLD) { + if (texel.a < ALPHA_THRESHOLD) { packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha * texel.a, - _color.rgb * texel.rgb+fadeEmissive, + texel.a, + texel.rgb + fadeEmissive, DEFAULT_ROUGHNESS); } else { packDeferredFragmentUnlit( normalize(_normalWS), 1.0, - _color.rgb * texel.rgb+fadeEmissive); + texel.rgb + fadeEmissive); } } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured.slf b/libraries/render-utils/src/simple_transparent_textured.slf index e1ed522c64..1a9d14e2fa 100644 --- a/libraries/render-utils/src/simple_transparent_textured.slf +++ b/libraries/render-utils/src/simple_transparent_textured.slf @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Color.slh@> <@include DeferredBufferWrite.slh@> <@include render-utils/ShaderConstants.h@> @@ -28,11 +29,13 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; void main(void) { vec4 texel = texture(originalTexture, _texCoord0); - float colorAlpha = _color.a * texel.a; + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); packDeferredFragmentTranslucent( normalize(_normalWS), - colorAlpha, - _color.rgb * texel.rgb, + texel.a, + texel.rgb, DEFAULT_ROUGHNESS); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured_fade.slf b/libraries/render-utils/src/simple_transparent_textured_fade.slf index 5fac67e1d2..75a88dc581 100644 --- a/libraries/render-utils/src/simple_transparent_textured_fade.slf +++ b/libraries/render-utils/src/simple_transparent_textured_fade.slf @@ -46,14 +46,10 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - vec4 texel = texture(originalTexture, _texCoord0.st); - float opacity = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - opacity = -_color.a; - } - opacity *= texel.a; - vec3 albedo = _color.rgb * texel.rgb; + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); vec3 fragPosition = _positionES.xyz; vec3 fragNormal = normalize(_normalWS); @@ -66,12 +62,11 @@ void main(void) { 1.0, fragPosition, fragNormal, - albedo, + texel.rgb, DEFAULT_FRESNEL, 0.0f, fadeEmissive, DEFAULT_ROUGHNESS, - opacity), - opacity); - + texel.a), + texel.a); } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured_unlit.slf b/libraries/render-utils/src/simple_transparent_textured_unlit.slf index bf3dbbdf88..3f4abfc730 100644 --- a/libraries/render-utils/src/simple_transparent_textured_unlit.slf +++ b/libraries/render-utils/src/simple_transparent_textured_unlit.slf @@ -27,11 +27,10 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) in vec4 _texCoord01; layout(location=0) out vec4 _fragColor0; void main(void) { - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } - _fragColor0 = vec4(_color.rgb * texel.rgb, colorAlpha * texel.a); + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); + + _fragColor0 = texel; } \ No newline at end of file diff --git a/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf b/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf index 943f361ead..e46426ec7a 100644 --- a/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf +++ b/libraries/render-utils/src/simple_transparent_textured_unlit_fade.slf @@ -39,11 +39,10 @@ void main(void) { <$fetchFadeObjectParamsInstanced(fadeParams)$> applyFade(fadeParams, _positionWS.xyz, fadeEmissive); - vec4 texel = texture(originalTexture, _texCoord0.st); - float colorAlpha = _color.a; - if (_color.a <= 0.0) { - texel = color_sRGBAToLinear(texel); - colorAlpha = -_color.a; - } - _fragColor0 = vec4(_color.rgb * texel.rgb + fadeEmissive, colorAlpha * texel.a); + vec4 texel = texture(originalTexture, _texCoord0); + texel = mix(color_sRGBAToLinear(texel), texel, float(_color.a <= 0.0)); + texel.rgb *= _color.rgb; + texel.a *= abs(_color.a); + + _fragColor0 = vec4(texel.rgb + fadeEmissive, texel.a); } \ No newline at end of file diff --git a/libraries/render-utils/src/ssao.slh b/libraries/render-utils/src/ssao.slh index b683dc38f1..50d3b31dde 100644 --- a/libraries/render-utils/src/ssao.slh +++ b/libraries/render-utils/src/ssao.slh @@ -219,26 +219,24 @@ vec3 getTapLocationClampedSSAO(int sampleNumber, float spinAngle, float outerRad } bool redoTap = false; - if ((tapPos.x < 0.5)) { - tapPos.x = -tapPos.x; - redoTap = true; - } else if ((tapPos.x > sideImageSize.x - 0.5)) { - tapPos.x -= (sideImageSize.x - tapPos.x); - redoTap = true; + { + float check1 = float(tapPos.x < 0.5); + float check2 = (1.0 - check1) * float(tapPos.x > sideImageSize.x - 0.5); + tapPos.x = tapPos.x - 2.0 * tapPos.x * check1 - check2 * (sideImageSize.x - tapPos.x); + redoTap = (check1 > 0.0 || check2 > 0.0); } - if ((tapPos.y < 0.5)) { - tapPos.y = -tapPos.y; - redoTap = true; - } else if ((tapPos.y > sideImageSize.y - 0.5)) { - tapPos.y -= (sideImageSize.y - tapPos.y); - redoTap = true; + { + float check1 = float(tapPos.y < 0.5); + float check2 = (1.0 - check1) * float(tapPos.y > sideImageSize.y - 0.5); + tapPos.y = tapPos.y - 2.0 * tapPos.y * check1 - check2 * (sideImageSize.y - tapPos.y); + redoTap = (check1 > 0.0 || check2 > 0.0); } - if (redoTap) { - tap.xy = tapPos - pixelPos; - tap.z = length(tap.xy); - tap.z = 0.0; + { + float check = float(redoTap); + tap.xy = mix(tap.xy, tapPos - pixelPos, check); + tap.z = (1.0 - check) * tap.z; } return tap; diff --git a/libraries/render-utils/src/ssao_debugOcclusion.slf b/libraries/render-utils/src/ssao_debugOcclusion.slf index 75e3ed5194..5b2ce4b0b5 100644 --- a/libraries/render-utils/src/ssao_debugOcclusion.slf +++ b/libraries/render-utils/src/ssao_debugOcclusion.slf @@ -39,6 +39,7 @@ layout(location=0) out vec4 outFragColor; void main(void) { // Stereo side info based on the real viewport size of this pass vec2 sideDepthSize = getDepthTextureSideSize(0); + // Pixel Debugged vec2 cursorUV = getDebugCursorTexcoord(); vec2 cursorPixelPos = cursorUV * sideDepthSize; @@ -46,6 +47,5 @@ void main(void) { ivec2 fragUVPos = ivec2(cursorPixelPos); // TODO - outFragColor = packOcclusionOutput(0.0, 0.0, vec3(0.0, 0.0, 1.0)); } diff --git a/libraries/render-utils/src/ssao_makeOcclusion.slf b/libraries/render-utils/src/ssao_makeOcclusion.slf index 5dfa879c69..fdccaecaed 100644 --- a/libraries/render-utils/src/ssao_makeOcclusion.slf +++ b/libraries/render-utils/src/ssao_makeOcclusion.slf @@ -43,6 +43,7 @@ void main(void) { } else { sideOcclusionSize = ivec2( getOcclusionSideSize() ); } + ivec4 side = getStereoSideInfoFromWidth(fragPixelPos.x, sideOcclusionSize.x); // From now on, fragUVPos is the UV pos in the side fragUVPos = getSideUVFromFramebufferUV(side, fragUVPos); diff --git a/libraries/render-utils/src/stencil_drawMask.slf b/libraries/render-utils/src/stencil_drawMask.slf index 5ba09a8264..2ae5853960 100644 --- a/libraries/render-utils/src/stencil_drawMask.slf +++ b/libraries/render-utils/src/stencil_drawMask.slf @@ -18,6 +18,9 @@ float aspectRatio = 0.95; void main(void) { vec2 pos = varTexCoord0 * 2.0 - vec2(1.0); - pos.x = aspectRatio * (pos.x * (pos.x > 0.0 ? 2.0 : -2.0) - 1.0); - if (1.0 - dot(pos.xy, pos.xy) > 0.0 ) discard; + pos.x = aspectRatio * (pos.x * mix(-2.0, 2.0, float(pos.x > 0.0)) - 1.0); + + if (1.0 - dot(pos.xy, pos.xy) > 0.0) { + discard; + } } diff --git a/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf b/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf index 877c31c23d..ac5907803c 100644 --- a/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf +++ b/libraries/render-utils/src/subsurfaceScattering_drawScattering.slf @@ -93,14 +93,14 @@ vec3 drawScatteringTableUV(vec2 cursor, vec2 texcoord) { vec3 color = vec3(0.0); bool keep = false; for (int c = 0; c < 3; c++) { - if (distance[c] > threshold) { - keep = true; - color[c] += 1.0; - } + bool check = distance[c] > threshold; + keep = keep || check; + color[c] += float(check); } - if (!keep) - discard; + if (!keep) { + discard; + } return color; } diff --git a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf index 363fd0d4f8..dd9b98b5e5 100644 --- a/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf +++ b/libraries/render-utils/src/surfaceGeometry_makeCurvature.slf @@ -67,11 +67,7 @@ vec3 getRawNormal(vec2 texcoord) { vec3 getWorldNormal(vec2 texcoord) { vec3 rawNormal = getRawNormal(texcoord); - if (isFullResolution()) { - return unpackNormal(rawNormal); - } else { - return normalize((rawNormal - vec3(0.5)) * 2.0); - } + return mix(normalize((rawNormal - vec3(0.5)) * 2.0), unpackNormal(rawNormal), float(isFullResolution())); } vec3 getWorldNormalDiff(vec2 texcoord, vec2 delta) { @@ -93,7 +89,7 @@ void main(void) { vec2 texcoordPos; ivec4 stereoSide; ivec2 framePixelPos = getPixelPosTexcoordPosAndSide(gl_FragCoord.xy, pixelPos, texcoordPos, stereoSide); - vec2 stereoSideClip = vec2(stereoSide.x, (isStereo() ? 0.5 : 1.0)); + vec2 stereoSideClip = vec2(stereoSide.x, 1.0 - 0.5 * float(isStereo())); // Texcoord to fetch in the deferred texture are the exact UVs comming from vertex shader // sideToFrameTexcoord(stereoSideClip, texcoordPos); @@ -128,8 +124,8 @@ void main(void) { // Calculate dF/du and dF/dv vec2 viewportScale = perspectiveScale * getInvWidthHeight(); - vec2 du = vec2( viewportScale.x * (float(stereoSide.w) > 0.0 ? 0.5 : 1.0), 0.0f ); - vec2 dv = vec2( 0.0f, viewportScale.y ); + vec2 du = vec2(viewportScale.x * (1.0 - 0.5 * float(stereoSide.w > 0)), 0.0); + vec2 dv = vec2( 0.0f, viewportScale.y); vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du)); vec4 dFdv = vec4(getWorldNormalDiff(frameTexcoordPos, dv), getEyeDepthDiff(frameTexcoordPos, dv)); diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index a2b58d3050..25320179f5 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -35,17 +35,11 @@ void main() { vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVel, sourceColor, historyColor); vec3 nextColor = sourceColor; - - if (taa_constrainColor()) { - // clamp history to neighbourhood of current sample - historyColor = taa_evalConstrainColor(sourceColor, fragUV, fragVel, historyColor); - } - - if (taa_feedbackColor()) { - nextColor = taa_evalFeedbackColor(sourceColor, historyColor, params.blend); - } else { - nextColor = mix(historyColor, sourceColor, params.blend); - } + + // clamp history to neighbourhood of current sample + historyColor = mix(historyColor, taa_evalConstrainColor(sourceColor, fragUV, fragVel, historyColor), float(taa_constrainColor())); + + nextColor = mix(mix(historyColor, sourceColor, params.blend), taa_evalFeedbackColor(sourceColor, historyColor, params.blend), float(taa_feedbackColor())); outFragColor = vec4(taa_resolveColor(nextColor), 1.0); } diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 784c0824d5..ed9162516e 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -121,21 +121,17 @@ float taa_fetchDepth(vec2 uv) { } -#define ZCMP_GT(a, b) (a > b) +#define ZCMP_GT(a, b) float(a > b) vec2 taa_getImageSize() { vec2 imageSize = getWidthHeight(0); - if (isStereo()) { - imageSize.x *= 2.0; - } + imageSize.x *= 1.0 + float(isStereo()); return imageSize; } vec2 taa_getTexelSize() { vec2 texelSize = getInvWidthHeight(); - if (isStereo()) { - texelSize.x *= 0.5; - } + texelSize.x *= 1.0 - 0.5 * float(isStereo()); return texelSize; } @@ -158,16 +154,16 @@ vec3 taa_findClosestFragment3x3(vec2 uv) vec3 dbr = vec3( 1, 1, taa_fetchDepth(uv + dv + du)); vec3 dmin = dtl; - if (ZCMP_GT(dmin.z, dtc.z)) dmin = dtc; - if (ZCMP_GT(dmin.z, dtr.z)) dmin = dtr; + dmin = mix(dmin, dtc, ZCMP_GT(dmin.z, dtc.z)); + dmin = mix(dmin, dtr, ZCMP_GT(dmin.z, dtr.z)); - if (ZCMP_GT(dmin.z, dml.z)) dmin = dml; - if (ZCMP_GT(dmin.z, dmc.z)) dmin = dmc; - if (ZCMP_GT(dmin.z, dmr.z)) dmin = dmr; + dmin = mix(dmin, dml, ZCMP_GT(dmin.z, dml.z)); + dmin = mix(dmin, dmc, ZCMP_GT(dmin.z, dmc.z)); + dmin = mix(dmin, dmr, ZCMP_GT(dmin.z, dmr.z)); - if (ZCMP_GT(dmin.z, dbl.z)) dmin = dbl; - if (ZCMP_GT(dmin.z, dbc.z)) dmin = dbc; - if (ZCMP_GT(dmin.z, dbr.z)) dmin = dbr; + dmin = mix(dmin, dbl, ZCMP_GT(dmin.z, dbl.z)); + dmin = mix(dmin, dbc, ZCMP_GT(dmin.z, dbc.z)); + dmin = mix(dmin, dbr, ZCMP_GT(dmin.z, dbr.z)); return vec3(uv + dd.xy * dmin.xy, dmin.z); } @@ -189,49 +185,46 @@ vec2 taa_fetchVelocityMapBest(vec2 uv) { vec2 dbc = taa_fetchVelocityMap(uv + dv); vec2 dbr = taa_fetchVelocityMap(uv + dv + du); - vec3 best = vec3(dtl, dot(dtl,dtl)); + vec3 best = vec3(dtl, dot(dtl, dtl)); - float testSpeed = dot(dtc,dtc); - if (testSpeed > best.z) { best = vec3(dtc, testSpeed); } - testSpeed = dot(dtr,dtr); - if (testSpeed > best.z) { best = vec3(dtr, testSpeed); } + float testSpeed = dot(dtc, dtc); + mix(best, vec3(dtc, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dtr, dtr); + mix(best, vec3(dtr, testSpeed), float(testSpeed > best.z)); - testSpeed = dot(dml,dml); - if (testSpeed > best.z) { best = vec3(dml, testSpeed); } - testSpeed = dot(dmc,dmc); - if (testSpeed > best.z) { best = vec3(dmc, testSpeed); } - testSpeed = dot(dmr,dmr); - if (testSpeed > best.z) { best = vec3(dmr, testSpeed); } + testSpeed = dot(dml, dml); + mix(best, vec3(dml, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dmc, dmc); + mix(best, vec3(dmc, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dmr, dmr); + mix(best, vec3(dmr, testSpeed), float(testSpeed > best.z)); - testSpeed = dot(dbl,dbl); - if (testSpeed > best.z) { best = vec3(dbl, testSpeed); } - testSpeed = dot(dbc,dbc); - if (testSpeed > best.z) { best = vec3(dbc, testSpeed); } - testSpeed = dot(dbr,dbr); - if (testSpeed > best.z) { best = vec3(dbr, testSpeed); } + testSpeed = dot(dbl, dbl); + mix(best, vec3(dbl, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dbc, dbc); + mix(best, vec3(dbc, testSpeed), float(testSpeed > best.z)); + testSpeed = dot(dbr, dbr); + mix(best, vec3(dbr, testSpeed), float(testSpeed > best.z)); return best.xy; } vec2 taa_fromFragUVToEyeUVAndSide(vec2 fragUV, out int stereoSide) { vec2 eyeUV = fragUV; - stereoSide = 0; - if (isStereo()) { - if (eyeUV.x > 0.5) { - eyeUV.x -= 0.5; - stereoSide = 1; - } - eyeUV.x *= 2.0; - } + + float check = float(isStereo()); + float check2 = float(eyeUV.x > 0.5); + eyeUV.x -= check * check2 * 0.5; + stereoSide = int(check * check2); + eyeUV.x *= 1.0 + check; return eyeUV; } vec2 taa_fromEyeUVToFragUV(vec2 eyeUV, int stereoSide) { vec2 fragUV = eyeUV; - if (isStereo()) { - fragUV.x *= 0.5; - fragUV.x += float(stereoSide)*0.5; - } + float check = float(isStereo()); + fragUV.x *= 1.0 - 0.5 * check; + fragUV.x += check * float(stereoSide) * 0.5; return fragUV; } @@ -247,10 +240,8 @@ vec2 taa_fetchSourceAndHistory(vec2 fragUV, vec2 fragVelocity, out vec3 sourceCo vec2 prevFragUV = taa_computePrevFragAndEyeUV(fragUV, fragVelocity, prevEyeUV); sourceColor = taa_fetchSourceMap(fragUV).xyz; - historyColor = sourceColor; - if (!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0))))) { - historyColor = taa_fetchHistoryMap(prevFragUV).xyz; - } + historyColor = mix(sourceColor, taa_fetchHistoryMap(prevFragUV).xyz, float(!(any(lessThan(prevEyeUV, vec2(0.0))) || any(greaterThan(prevEyeUV, vec2(1.0)))))); + return prevFragUV; } @@ -405,10 +396,11 @@ vec3 taa_clampColor(vec3 colorMin, vec3 colorMax, vec3 colorSource, vec3 color) vec3 a_unit = abs(v_unit); float ma_unit = max(a_unit.x, max(a_unit.y, a_unit.z)); - if (ma_unit > 1.0) + if (ma_unit > 1.0) { return p_clip + v_clip / ma_unit; - else - return q;// point inside aabb + } else { + return q;// point inside aabb + } } vec3 taa_evalConstrainColor(vec3 sourceColor, vec2 sourceUV, vec2 sourceVel, vec3 candidateColor) { @@ -514,10 +506,6 @@ vec3 taa_evalFXAA(vec2 fragUV) { // compare luma of new samples to the luma range of the original neighborhood // if the new samples exceed this range, just use the first two samples instead of all four - if (lumaB < lumaMin || lumaB > lumaMax) { - return rgbA; - } else { - return rgbB; - } + return mix(rgbB, rgbA, float(lumaB < lumaMin || lumaB > lumaMax)); } diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index 50575a6a07..0999b2482f 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -83,32 +83,21 @@ void main(void) { if ((prevOrbPosToPixLength < tenPercentHeight) && (cursorVelocityLength > 0.5)) { vec2 prevOrbPosToPix_uv = cursorPrevUV + prevOrbPosToPix * texelSize / taa_getDebugOrbZoom(); vec3 preOrbColor = vec3(0.0); - if (!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0))))) { - preOrbColor = texture(historyMap, prevOrbPosToPix_uv).xyz; - } - if (prevOrbPosToPixLength < orbPixThreshold) { - preOrbColor = vec3(1.0, 0.0, 1.0); - } + + preOrbColor = mix(preOrbColor, texture(historyMap, prevOrbPosToPix_uv).xyz, float(!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0)))))); + preOrbColor = mix(preOrbColor, vec3(1.0, 0.0, 1.0), float(prevOrbPosToPixLength < orbPixThreshold)); float distanceToNext = length(imageSize * (cursorUV - prevOrbPosToPix_uv)); - if (distanceToNext < orbPixThreshold) { - preOrbColor = vec3(1.0, 0.5, 0.0); - } + preOrbColor = mix(preOrbColor, vec3(1.0, 0.5, 0.0), float(distanceToNext < orbPixThreshold)); outFragColor = vec4(preOrbColor, 1.0); return; } if (nextOrbPosToPixLength < tenPercentHeight) { vec2 nextOrbPosToPix_uv = cursorUV + nextOrbPosToPix * texelSize / taa_getDebugOrbZoom(); vec3 nextOrbColor = vec3(0.0); - if (!(any(lessThan(nextOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(nextOrbPosToPix_uv, vec2(1.0))))) { - nextOrbColor = texture(nextMap, nextOrbPosToPix_uv).xyz; - } + nextOrbColor = mix(nextOrbColor, texture(nextMap, nextOrbPosToPix_uv).xyz, float(!(any(lessThan(nextOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(nextOrbPosToPix_uv, vec2(1.0)))))); float distanceToPrev = length(imageSize * (cursorPrevUV - nextOrbPosToPix_uv)); - if (distanceToPrev < orbPixThreshold) { - nextOrbColor = vec3(1.0, 0.0, 1.0); - } - if (nextOrbPosToPixLength < orbPixThreshold) { - nextOrbColor = vec3(1.0, 0.5, 0.0); - } + nextOrbColor = mix(nextOrbColor, vec3(1.0, 0.0, 1.0), float(distanceToPrev < orbPixThreshold)); + nextOrbColor = mix(nextOrbColor, vec3(1.0, 0.5, 0.0), float(nextOrbPosToPixLength < orbPixThreshold)); outFragColor = vec4(nextOrbColor, 1.0); return; @@ -141,16 +130,9 @@ void main(void) { outFragColor = vec4(nextColor, 1.0); vec3 prevColor = nextColor; + prevColor = mix(prevColor, texture(historyMap, prevTexCoord).xyz, float(!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0)))))); - if (!(any(lessThan(prevTexCoord, vec2(0.0))) || any(greaterThan(prevTexCoord, vec2(1.0))))) { - prevColor = texture(historyMap, prevTexCoord).xyz; - } + outFragColor.xyz = mix(prevColor, vec3(1, 0, 1), clamp(distance(prevColor, nextColor) - 0.01, 0.0, 1.0)); - outFragColor.xyz = mix(prevColor, vec3(1,0,1), clamp(distance(prevColor, nextColor) - 0.01, 0.0, 1.0)); - - if (pixVelocityLength > params.debugShowVelocityThreshold) { - vec3 speedColor = taa_getVelocityColorAboveThreshold(pixVelocityLength); - - outFragColor = vec4(0.0, 1.0, 1.0, 1.0); - } + outFragColor = mix(outFragColor, vec4(0.0, 1.0, 1.0, 1.0), float(pixVelocityLength > params.debugShowVelocityThreshold)); } diff --git a/libraries/render-utils/src/zone_drawAmbient.slf b/libraries/render-utils/src/zone_drawAmbient.slf index f20d83e913..d780fd0de2 100644 --- a/libraries/render-utils/src/zone_drawAmbient.slf +++ b/libraries/render-utils/src/zone_drawAmbient.slf @@ -44,7 +44,7 @@ void main(void) { // vec3 ambient = sphericalHarmonics_evalSphericalLight(getLightAmbientSphere(lightAmbient), fragNormal).xyz; // _fragColor = vec4( 0.5 * (fragNormal + vec3(1.0)), 1.0); - vec3 color = (sphereUV.x > 0.0 ? ambientMap : ambientSH); + vec3 color = mix(ambientSH, ambientMap, float(sphereUV.x > 0.0)); color = color * 1.0 - base.w + base.xyz * base.w; const float INV_GAMMA_22 = 1.0 / 2.2; diff --git a/libraries/render-utils/src/zone_drawSkybox.slf b/libraries/render-utils/src/zone_drawSkybox.slf index f8d1326b3a..743b48d0bf 100644 --- a/libraries/render-utils/src/zone_drawSkybox.slf +++ b/libraries/render-utils/src/zone_drawSkybox.slf @@ -35,16 +35,11 @@ void main(void) { vec3 color = skybox.color.rgb; // blend is only set if there is a cubemap - if (skybox.color.a > 0.0) { - color = texture(skyboxMap, direction).rgb; - if (skybox.color.a < 1.0) { - color *= skybox.color.rgb; - } - } + float check = float(skybox.color.a > 0.0); + color = mix(color, texture(skyboxMap, direction).rgb, check); + color *= mix(vec3(1.0), skybox.color.rgb, check * float(skybox.color.a < 1.0)); color = color * 1.0 - base.w + base.xyz * base.w; const float INV_GAMMA_22 = 1.0 / 2.2; _fragColor = vec4(pow(color, vec3(INV_GAMMA_22)), 1.0); } - - diff --git a/libraries/render/src/render/BlurTask.slh b/libraries/render/src/render/BlurTask.slh index fa4b9a4a4f..ff4e76a429 100644 --- a/libraries/render/src/render/BlurTask.slh +++ b/libraries/render/src/render/BlurTask.slh @@ -98,10 +98,11 @@ vec4 pixelShaderGaussian(vec2 texcoord, vec2 direction, vec2 pixelStep) { totalWeight += weight; } } - - if (totalWeight>0.0) { + + if (totalWeight > 0.0) { srcBlurred /= totalWeight; } + srcBlurred.a = getOutputAlpha(); return srcBlurred; } @@ -159,10 +160,11 @@ vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep totalWeight += weight; } } - - if (totalWeight>0.0) { + + if (totalWeight > 0.0) { srcBlurred /= totalWeight; } + return srcBlurred; } diff --git a/libraries/render/src/render/DrawSceneOctree.h b/libraries/render/src/render/DrawSceneOctree.h index 3f7c07ded3..0c7441404a 100644 --- a/libraries/render/src/render/DrawSceneOctree.h +++ b/libraries/render/src/render/DrawSceneOctree.h @@ -20,7 +20,6 @@ namespace render { class DrawSceneOctreeConfig : public Job::Config { Q_OBJECT - Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty()) Q_PROPERTY(bool showVisibleCells READ getShowVisibleCells WRITE setShowVisibleCells NOTIFY dirty()) Q_PROPERTY(bool showEmptyCells READ getShowEmptyCells WRITE setShowEmptyCells NOTIFY dirty()) Q_PROPERTY(int numAllocatedCells READ getNumAllocatedCells) @@ -77,7 +76,6 @@ namespace render { class DrawItemSelectionConfig : public Job::Config { Q_OBJECT - Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty()) Q_PROPERTY(bool showInsideItems READ getShowInsideItems WRITE setShowInsideItems NOTIFY dirty()) Q_PROPERTY(bool showInsideSubcellItems READ getShowInsideSubcellItems WRITE setShowInsideSubcellItems NOTIFY dirty()) Q_PROPERTY(bool showPartialItems READ getShowPartialItems WRITE setShowPartialItems NOTIFY dirty()) diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp index a1b61a4e77..76ed5aa663 100644 --- a/libraries/render/src/render/DrawStatus.cpp +++ b/libraries/render/src/render/DrawStatus.cpp @@ -26,7 +26,7 @@ using namespace render; void DrawStatusConfig::dirtyHelper() { - enabled = showNetwork || showDisplay; + _isEnabled = showNetwork || showDisplay; emit dirty(); } diff --git a/libraries/render/src/render/drawCellBounds.slv b/libraries/render/src/render/drawCellBounds.slv index 24cc6254fd..216f1ea299 100644 --- a/libraries/render/src/render/drawCellBounds.slv +++ b/libraries/render/src/render/drawCellBounds.slv @@ -51,7 +51,7 @@ void main(void) { vec4 pos = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]]; int cellIsEmpty = sign(inCellLocation.w); - ivec4 cellLocation = ivec4(inCellLocation.xyz, (inCellLocation.w < 0 ? -inCellLocation.w : inCellLocation.w)); + ivec4 cellLocation = ivec4(inCellLocation.xyz, abs(inCellLocation.w)); vec4 cellBound = evalBound(cellLocation); pos.xyz = cellBound.xyz + vec3(cellBound.w) * pos.xyz; @@ -62,4 +62,4 @@ void main(void) { <$transformModelToClipPos(cam, obj, pos, gl_Position)$> varColor = vec4(colorWheel(fract(float(inCellLocation.w) / 5.0)), 0.8 + 0.2 * float(cellIsEmpty)); -} \ No newline at end of file +} diff --git a/libraries/render/src/render/drawItemBounds.slf b/libraries/render/src/render/drawItemBounds.slf index 90faaff05c..0fed67beb6 100644 --- a/libraries/render/src/render/drawItemBounds.slf +++ b/libraries/render/src/render/drawItemBounds.slf @@ -18,11 +18,7 @@ layout(location=0) out vec4 outFragColor; void main(void) { float var = step(fract(varTexcoord.x * varTexcoord.y * 1.0), 0.5); - if (varColor.a == 0.0) { - outFragColor = vec4(mix(vec3(0.0), varColor.xyz, var), mix(0.0, 1.0, var)); - - } else { - outFragColor = vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a); - } - + outFragColor = mix(vec4(mix(vec3(1.0), varColor.xyz, var), varColor.a), + vec4(mix(vec3(0.0), varColor.xyz, var), var), + float(varColor.a == 0.0)); } diff --git a/libraries/render/src/render/drawItemBounds.slv b/libraries/render/src/render/drawItemBounds.slv index bb8e6a2886..32cfe1c131 100644 --- a/libraries/render/src/render/drawItemBounds.slv +++ b/libraries/render/src/render/drawItemBounds.slv @@ -98,11 +98,6 @@ void main(void) { TransformObject obj = getTransformObject(); <$transformModelToClipPos(cam, obj, pos, gl_Position)$> - if (params.color.w < 0.0) { - varColor = vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0); - } else { - varColor = vec4(colorWheel(float(params.color.w)), 1.0); - } + varColor = mix(vec4(colorWheel(float(params.color.w)), 1.0), vec4(colorWheel(float(boundID)/(-params.color.w)), 1.0), float(params.color.w < 0.0)); varTexcoord = vec2(cubeVec.w, length(boundDim)); - } \ No newline at end of file diff --git a/libraries/render/src/render/drawItemStatus.slf b/libraries/render/src/render/drawItemStatus.slf index e88cf4c920..ca7f2273cd 100644 --- a/libraries/render/src/render/drawItemStatus.slf +++ b/libraries/render/src/render/drawItemStatus.slf @@ -22,10 +22,9 @@ vec2 getIconTexcoord(float icon, vec2 uv) { } void main(void) { - if (varTexcoord.z < 254.5) { - outFragColor = texture(_icons, getIconTexcoord(varTexcoord.z, varTexcoord.xy)) * varColor; - } else { - vec2 centerDir = varTexcoord.xy * 2.0f - 1.0f; - outFragColor = vec4(varColor.xyz, 1.0 - step(1.0f, dot(centerDir.xy, centerDir.xy))); - } + vec2 centerDir = varTexcoord.xy * 2.0f - 1.0f; + + outFragColor = mix(vec4(varColor.xyz, 1.0 - step(1.0f, dot(centerDir.xy, centerDir.xy))), + texture(_icons, getIconTexcoord(varTexcoord.z, varTexcoord.xy)) * varColor, + float(varTexcoord.z < 254.5)); } diff --git a/libraries/script-engine/src/ScriptEngines.cpp b/libraries/script-engine/src/ScriptEngines.cpp index 2cdfc20647..399ccf1919 100644 --- a/libraries/script-engine/src/ScriptEngines.cpp +++ b/libraries/script-engine/src/ScriptEngines.cpp @@ -191,7 +191,6 @@ void ScriptEngines::shutdownScripting() { // Gracefully stop the engine's scripting thread scriptEngine->stop(); - removeScriptEngine(scriptEngine); // We need to wait for the engine to be done running before we proceed, because we don't // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing @@ -370,13 +369,10 @@ QStringList ScriptEngines::getRunningScripts() { } void ScriptEngines::stopAllScripts(bool restart) { - QVector toReload; QReadLocker lock(&_scriptEnginesHashLock); if (_isReloading) { return; - } else { - _isReloading = true; } for (QHash::const_iterator it = _scriptEnginesHash.constBegin(); @@ -389,29 +385,27 @@ void ScriptEngines::stopAllScripts(bool restart) { // queue user scripts if restarting if (restart && scriptEngine->isUserLoaded()) { - toReload << it.key().toString(); + _isReloading = true; + bool lastScript = (it == _scriptEnginesHash.constEnd() - 1); + ScriptEngine::Type type = scriptEngine->getType(); + + connect(scriptEngine.data(), &ScriptEngine::finished, this, [this, type, lastScript] (QString scriptName) { + reloadScript(scriptName, true)->setType(type); + + if (lastScript) { + _isReloading = false; + } + }); } // stop all scripts scriptEngine->stop(); - removeScriptEngine(scriptEngine); } - // wait for engines to stop (ie: providing time for .scriptEnding cleanup handlers to run) before - // triggering reload of any Client scripts / Entity scripts - QTimer::singleShot(1000, this, [=]() { - for(const auto &scriptName : toReload) { - auto scriptEngine = getScriptEngine(scriptName); - if (scriptEngine && !scriptEngine->isFinished()) { - scriptEngine->waitTillDoneRunning(); - } - reloadScript(scriptName); - } - if (restart) { - qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; - emit scriptsReloading(); - } - _isReloading = false; - }); + + if (restart) { + qCDebug(scriptengine) << "stopAllScripts -- emitting scriptsReloading"; + emit scriptsReloading(); + } } bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { @@ -439,7 +433,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) { } } scriptEngine->stop(); - removeScriptEngine(scriptEngine); stoppedScript = true; } } diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index da877f7b3b..bda1077990 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -27,16 +27,16 @@ class Dependency { public: typedef std::function DeleterFunction; - + protected: virtual ~Dependency() {} virtual void customDeleter() { _customDeleter(this); } - + void setCustomDeleter(DeleterFunction customDeleter) { _customDeleter = customDeleter; } DeleterFunction _customDeleter = [](Dependency* pointer) { delete pointer; }; - + friend class DependencyManager; }; @@ -49,10 +49,10 @@ class DependencyManager { public: template static QSharedPointer get(); - + template static bool isSet(); - + template static QSharedPointer set(Args&&... args); @@ -61,10 +61,10 @@ public: template static void destroy(); - + template static void registerInheritance(); - + template static size_t typeHash() { #ifdef Q_OS_ANDROID @@ -74,31 +74,46 @@ public: #endif return hashCode; } + + static void prepareToExit() { manager()._exiting = true; } + private: static DependencyManager& manager(); template size_t getHashCode(); - + QSharedPointer& safeGet(size_t hashCode); - + QHash> _instanceHash; QHash _inheritanceHash; + + bool _exiting { false }; }; template QSharedPointer DependencyManager::get() { static size_t hashCode = manager().getHashCode(); static QWeakPointer instance; - + if (instance.isNull()) { instance = qSharedPointerCast(manager().safeGet(hashCode)); - + +#ifndef QT_NO_DEBUG + // debug builds... if (instance.isNull()) { qWarning() << "DependencyManager::get(): No instance available for" << typeid(T).name(); } +#else + // for non-debug builds, don't print "No instance available" during shutdown, because + // the act of printing this often causes crashes (because the LogHandler has-been/is-being + // deleted). + if (!manager()._exiting && instance.isNull()) { + qWarning() << "DependencyManager::get(): No instance available for" << typeid(T).name(); + } +#endif } - + return instance.toStrongRef(); } @@ -159,12 +174,12 @@ template size_t DependencyManager::getHashCode() { size_t hashCode = typeHash(); auto derivedHashCode = _inheritanceHash.find(hashCode); - + while (derivedHashCode != _inheritanceHash.end()) { hashCode = derivedHashCode.value(); derivedHashCode = _inheritanceHash.find(hashCode); } - + return hashCode; } diff --git a/libraries/shared/src/SharedUtil.h b/libraries/shared/src/SharedUtil.h index f36574bed6..709eeca9b2 100644 --- a/libraries/shared/src/SharedUtil.h +++ b/libraries/shared/src/SharedUtil.h @@ -113,6 +113,13 @@ void doEvery(quint64& lastReportUsecs, quint64 secs, F lamdba) { // Maximum accuracy in msecs float secTimestampNow(); +// Custom deleter for QObjects that calls deleteLater +struct LaterDeleter { + void operator()(QObject* ptr) { + ptr->deleteLater(); + } +}; + float randFloat(); int randIntInRange (int min, int max); float randFloatInRange (float min,float max); diff --git a/libraries/shared/src/shared/HifiTypes.h b/libraries/shared/src/shared/HifiTypes.h new file mode 100644 index 0000000000..500170c88b --- /dev/null +++ b/libraries/shared/src/shared/HifiTypes.h @@ -0,0 +1,25 @@ +// +// HifiTypes.h +// libraries/shared/src/shared +// +// Created by Sabrina Shanman on 2018/11/12. +// Copyright 2018 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 +// + +#ifndef hifi_HifiTypes_h +#define hifi_HifiTypes_h + +#include +#include +#include + +namespace hifi { + using ByteArray = QByteArray; + using VariantHash = QVariantHash; + using URL = QUrl; +}; + +#endif // hifi_HifiTypes_h diff --git a/libraries/task/src/task/Config.cpp b/libraries/task/src/task/Config.cpp index b378237c9c..5e8e4b246d 100644 --- a/libraries/task/src/task/Config.cpp +++ b/libraries/task/src/task/Config.cpp @@ -18,6 +18,17 @@ using namespace task; +JobConfig::~JobConfig() { + +} + +void JobConfig::setEnabled(bool enable) { + if (_isEnabled != enable) { + _isEnabled = enable; + emit dirtyEnabled(); + } +} + void JobConfig::setPresetList(const QJsonObject& object) { for (auto it = object.begin(); it != object.end(); it++) { JobConfig* child = findChild(it.key(), Qt::FindDirectChildrenOnly); @@ -68,3 +79,57 @@ void TaskConfig::refresh() { _task->applyConfiguration(); } +TaskConfig* TaskConfig::getRootConfig(const std::string& jobPath, std::string& jobName) const { + TaskConfig* root = const_cast (this); + + std::list tokens; + std::size_t pos = 0, sepPos; + while ((sepPos = jobPath.find_first_of('.', pos)) != std::string::npos) { + std::string token = jobPath.substr(pos, sepPos - pos); + if (!token.empty()) { + tokens.push_back(token); + } + pos = sepPos + 1; + } + { + std::string token = jobPath.substr(pos, sepPos - pos); + if (!token.empty()) { + tokens.push_back(token); + } + } + + if (tokens.empty()) { + return root; + } + else { + while (tokens.size() > 1) { + auto taskName = tokens.front(); + tokens.pop_front(); + root = root->findChild((taskName.empty() ? QString() : QString(taskName.c_str()))); + if (!root) { + return nullptr; + } + } + jobName = tokens.front(); + } + return root; +} + +JobConfig* TaskConfig::getJobConfig(const std::string& jobPath) const { + std::string jobName; + auto root = getRootConfig(jobPath, jobName); + + if (!root) { + return nullptr; + } + if (jobName.empty()) { + return root; + } else { + + auto found = root->findChild((jobName.empty() ? QString() : QString(jobName.c_str()))); + if (!found) { + return nullptr; + } + return found; + } +} diff --git a/libraries/task/src/task/Config.h b/libraries/task/src/task/Config.h index 4379dbbaa6..da9b95a274 100644 --- a/libraries/task/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -50,12 +50,10 @@ public: _default = toJsonValue(*this).toObject().toVariantMap(); _presets.unite(list.toVariantMap()); - if (C::alwaysEnabled || C::enabled) { + if (C::isEnabled()) { _presets.insert(DEFAULT, _default); } - if (!C::alwaysEnabled) { - _presets.insert(NONE, QVariantMap{{ "enabled", false }}); - } + _presets.insert(NONE, QVariantMap{{ "enabled", false }}); auto preset = _preset.get(); if (preset != _preset.getDefault() && _presets.contains(preset)) { @@ -92,17 +90,21 @@ class JobConfig : public QObject { Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY dirtyEnabled()) double _msCPURunTime{ 0.0 }; + +protected: + friend class TaskConfig; + + bool _isEnabled{ true }; + public: using Persistent = PersistentConfig; JobConfig() = default; - JobConfig(bool enabled) : alwaysEnabled{ false }, enabled{ enabled } {} + JobConfig(bool enabled): _isEnabled{ enabled } {} + ~JobConfig(); - bool isEnabled() { return alwaysEnabled || enabled; } - void setEnabled(bool enable) { enabled = alwaysEnabled || enable; emit dirtyEnabled(); } - - bool alwaysEnabled{ true }; - bool enabled{ true }; + bool isEnabled() const { return _isEnabled; } + void setEnabled(bool enable); virtual void setPresetList(const QJsonObject& object); @@ -200,6 +202,7 @@ public: */ class TaskConfig : public JobConfig { Q_OBJECT + public: using Persistent = PersistentConfig; @@ -221,27 +224,13 @@ public: // // getter for qml integration, prefer the templated getter Q_INVOKABLE QObject* getConfig(const QString& name) { return getConfig(name.toStdString()); } + // getter for cpp (strictly typed), prefer this getter - template typename T::Config* getConfig(std::string job = "") const { - const TaskConfig* root = this; - QString path = (job.empty() ? QString() : QString(job.c_str())); // an empty string is not a null string - auto tokens = path.split('.', QString::SkipEmptyParts); + TaskConfig* getRootConfig(const std::string& jobPath, std::string& jobName) const; + JobConfig* getJobConfig(const std::string& jobPath) const; - if (tokens.empty()) { - tokens.push_back(QString()); - } - else { - while (tokens.size() > 1) { - auto name = tokens.front(); - tokens.pop_front(); - root = QObject::findChild(name); - if (!root) { - return nullptr; - } - } - } - - return root->findChild(tokens.front()); + template typename T::Config* getConfig(std::string jobPath = "") const { + return dynamic_cast(getJobConfig(jobPath)); } Q_INVOKABLE bool isTask() const override { return true; } diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index e8e95b4df4..fb7012b16c 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -164,7 +164,7 @@ public: void run(const ContextPointer& jobContext) override { jobContext->jobConfig = std::static_pointer_cast(Concept::_config); - if (jobContext->jobConfig->alwaysEnabled || jobContext->jobConfig->isEnabled()) { + if (jobContext->jobConfig->isEnabled()) { jobRun(_data, jobContext, _input.get(), _output.edit()); } jobContext->jobConfig.reset(); @@ -340,7 +340,7 @@ public: void run(const ContextPointer& jobContext) override { auto config = std::static_pointer_cast(Concept::_config); - if (config->alwaysEnabled || config->enabled) { + if (config->isEnabled()) { for (auto job : TaskConcept::_jobs) { job.run(jobContext); if (jobContext->taskFlow.doAbortTask()) { diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index 0aad297587..a13bdf0657 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -616,7 +616,9 @@ bool OffscreenUi::navigationFocused() { } void OffscreenUi::setNavigationFocused(bool focused) { - offscreenFlags->setNavigationFocused(focused); + if (offscreenFlags) { + offscreenFlags->setNavigationFocused(focused); + } } // FIXME HACK.... diff --git a/libraries/ui/src/ui/Menu.cpp b/libraries/ui/src/ui/Menu.cpp index 848b2362ee..b3b76ab534 100644 --- a/libraries/ui/src/ui/Menu.cpp +++ b/libraries/ui/src/ui/Menu.cpp @@ -422,9 +422,11 @@ void Menu::removeMenu(const QString& menuName) { } else { QMenuBar::removeAction(action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->removeAction(action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->removeAction(action); + }); + } } QMenuBar::repaint(); @@ -532,9 +534,11 @@ void Menu::setGroupingIsVisible(const QString& grouping, bool isVisible) { MenuWrapper::MenuWrapper(ui::Menu& rootMenu, QMenu* menu) : _rootMenu(rootMenu), _realMenu(menu) { auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addMenu(menu); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addMenu(menu); + }); + } _rootMenu._backMap[menu] = this; } @@ -553,50 +557,62 @@ void MenuWrapper::setEnabled(bool enabled) { QAction* MenuWrapper::addSeparator() { QAction* action = _realMenu->addSeparator(); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addSeparator(_realMenu); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addSeparator(_realMenu); + }); + } return action; } void MenuWrapper::addAction(QAction* action) { _realMenu->addAction(action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addAction(_realMenu, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addAction(_realMenu, action); + }); + } } QAction* MenuWrapper::addAction(const QString& menuName) { QAction* action = _realMenu->addAction(menuName); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addAction(_realMenu, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addAction(_realMenu, action); + }); + } return action; } QAction* MenuWrapper::addAction(const QString& menuName, const QObject* receiver, const char* member, const QKeySequence& shortcut) { QAction* action = _realMenu->addAction(menuName, receiver, member, shortcut); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->addAction(_realMenu, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->addAction(_realMenu, action); + }); + } return action; } void MenuWrapper::removeAction(QAction* action) { _realMenu->removeAction(action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->removeAction(action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->removeAction(action); + }); + } } void MenuWrapper::insertAction(QAction* before, QAction* action) { _realMenu->insertAction(before, action); auto offscreenUi = DependencyManager::get(); - offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { - vrMenu->insertAction(before, action); - }); + if (offscreenUi) { + offscreenUi->addMenuInitializer([=](VrMenu* vrMenu) { + vrMenu->insertAction(before, action); + }); + } } diff --git a/libraries/ui/src/ui/Menu.h b/libraries/ui/src/ui/Menu.h index 2977a5330a..ec286b29ad 100644 --- a/libraries/ui/src/ui/Menu.h +++ b/libraries/ui/src/ui/Menu.h @@ -146,6 +146,11 @@ protected: int findPositionOfMenuItem(MenuWrapper* menu, const QString& searchMenuItem); int positionBeforeSeparatorIfNeeded(MenuWrapper* menu, int requestedPosition); + // There is a design flaw here -- _actionHash is system-wide and hashes the names of menu-items to their + // QActions. The path (parent submenu name etc) isn't included in the hash key. This generally works, + // but we add "Home" twice -- once for "go home" and once for "set startup location to home". Anytime + // a user bookmarks a place and gives it a name like an existing menu-item, something will go wrong. + // TODO: change the js api to require the full path when referring to a specific menu item. QHash _actionHash; bool isValidGrouping(const QString& grouping) const { return grouping == "Advanced" || grouping == "Developer"; } diff --git a/libraries/ui/src/ui/TabletScriptingInterface.cpp b/libraries/ui/src/ui/TabletScriptingInterface.cpp index 8fc2d069ec..13b0498e76 100644 --- a/libraries/ui/src/ui/TabletScriptingInterface.cpp +++ b/libraries/ui/src/ui/TabletScriptingInterface.cpp @@ -366,6 +366,7 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { auto offscreenUi = DependencyManager::get(); if (toolbarMode) { +#if !defined(DISABLE_QML) // create new desktop window auto tabletRootWindow = new TabletRootWindow(); tabletRootWindow->initQml(QVariantMap()); @@ -379,6 +380,7 @@ void TabletProxy::setToolbarMode(bool toolbarMode) { // forward qml surface events to interface js connect(tabletRootWindow, &QmlWindowClass::fromQml, this, &TabletProxy::fromQml); +#endif } else { if (_currentPathLoaded != TABLET_HOME_SOURCE_URL) { loadHomeScreen(true); diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index af4f4da18c..283556f86a 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -892,7 +892,7 @@ glm::mat4 ViveControllerManager::InputDevice::calculateDefaultToReferenceForHead glm::vec3 x = glm::normalize(glm::cross(Vectors::UNIT_Y, forward)); glm::vec3 z = glm::normalize(glm::cross(x, Vectors::UNIT_Y)); glm::mat3 centerEyeRotMat(x, Vectors::UNIT_Y, z); - glm::vec3 centerEyeTrans = headPuckPose.translation + centerEyeRotMat * glm::vec3(0.0f, _headPuckYOffset, _headPuckZOffset); + glm::vec3 centerEyeTrans = headPuckPose.translation + centerEyeRotMat * -glm::vec3(0.0f, _headPuckYOffset, _headPuckZOffset); glm::mat4 E_s(glm::vec4(centerEyeRotMat[0], 0.0f), glm::vec4(centerEyeRotMat[1], 0.0f), @@ -1056,7 +1056,7 @@ void ViveControllerManager::InputDevice::hapticsHelper(float deltaTime, bool lef float hapticTime = strength * MAX_HAPTIC_TIME; if (hapticTime < duration * 1000.0f) { _system->TriggerHapticPulse(deviceIndex, 0, hapticTime); - } + } float remainingHapticTime = duration - (hapticTime / 1000.0f + deltaTime * 1000.0f); // in milliseconds if (leftHand) { @@ -1077,23 +1077,20 @@ void ViveControllerManager::InputDevice::calibrateLeftHand(const glm::mat4& defa } // This allows the user to not have to match the t-pose exactly. We assume that the y facing of the hand lies in the plane of the puck. - // Where the plane of the puck is defined by the the local z-axis of the puck, which is facing out of the vive logo/power button. + // Where the plane of the puck is defined by the the local z-axis of the puck, which is pointing out of the camera mount on the bottom of the puck. glm::vec3 zPrime = handPoseZAxis; glm::vec3 xPrime = glm::normalize(glm::cross(referenceHandYAxis, handPoseZAxis)); glm::vec3 yPrime = glm::normalize(glm::cross(zPrime, xPrime)); glm::mat4 newHandMat = glm::mat4(glm::vec4(xPrime, 0.0f), glm::vec4(yPrime, 0.0f), glm::vec4(zPrime, 0.0f), glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); - glm::vec3 translationOffset = glm::vec3(0.0f, _handPuckYOffset, _handPuckZOffset); - glm::quat initialRotation = handPose.getRotation(); - glm::quat finalRotation = glmExtractRotation(newHandMat); - - glm::quat rotationOffset = glm::inverse(initialRotation) * finalRotation; - - glm::mat4 offsetMat = createMatFromQuatAndPos(rotationOffset, translationOffset); + glm::quat initialRot = handPose.getRotation(); + glm::quat postOffsetRot = glm::inverse(initialRot) * glmExtractRotation(newHandMat); + glm::vec3 postOffsetTrans = postOffsetRot * -glm::vec3(0.0f, _handPuckYOffset, _handPuckZOffset); + glm::mat4 postOffsetMat = createMatFromQuatAndPos(postOffsetRot, postOffsetTrans); _jointToPuckMap[controller::LEFT_HAND] = handPair.first; - _pucksPostOffset[handPair.first] = offsetMat; + _pucksPostOffset[handPair.first] = postOffsetMat; } void ViveControllerManager::InputDevice::calibrateRightHand(const glm::mat4& defaultToReferenceMat, const controller::InputCalibrationData& inputCalibration, PuckPosePair& handPair) { @@ -1113,16 +1110,13 @@ void ViveControllerManager::InputDevice::calibrateRightHand(const glm::mat4& def glm::mat4 newHandMat = glm::mat4(glm::vec4(xPrime, 0.0f), glm::vec4(yPrime, 0.0f), glm::vec4(zPrime, 0.0f), glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); - glm::vec3 translationOffset = glm::vec3(0.0f, _handPuckYOffset, _handPuckZOffset); - glm::quat initialRotation = handPose.getRotation(); - glm::quat finalRotation = glmExtractRotation(newHandMat); - - glm::quat rotationOffset = glm::inverse(initialRotation) * finalRotation; - - glm::mat4 offsetMat = createMatFromQuatAndPos(rotationOffset, translationOffset); + glm::quat initialRot = handPose.getRotation(); + glm::quat postOffsetRot = glm::inverse(initialRot) * glmExtractRotation(newHandMat); + glm::vec3 postOffsetTrans = postOffsetRot * -glm::vec3(0.0f, _handPuckYOffset, _handPuckZOffset); + glm::mat4 postOffsetMat = createMatFromQuatAndPos(postOffsetRot, postOffsetTrans); _jointToPuckMap[controller::RIGHT_HAND] = handPair.first; - _pucksPostOffset[handPair.first] = offsetMat; + _pucksPostOffset[handPair.first] = postOffsetMat; } diff --git a/prebuild.py b/prebuild.py index dacc49a86e..b8cb2c96ae 100644 --- a/prebuild.py +++ b/prebuild.py @@ -83,12 +83,17 @@ class VcpkgRepo: self.sourcePortsPath = os.path.join(scriptPath, 'cmake', 'ports') # FIXME Revert to ports hash before release self.id = hashFolder(self.sourcePortsPath)[:8] + # OS dependent information + system = platform.system() if args.vcpkg_root is not None: print("override vcpkg path with " + args.vcpkg_root) self.path = args.vcpkg_root else: - defaultBasePath = os.path.join(tempfile.gettempdir(), 'hifi', 'vcpkg') + if 'Darwin' == system: + defaultBasePath = os.path.expanduser('~/hifi/vcpkg') + else: + defaultBasePath = os.path.join(tempfile.gettempdir(), 'hifi', 'vcpkg') basePath = os.getenv('HIFI_VCPKG_BASE', defaultBasePath) if (not os.path.isdir(basePath)): os.makedirs(basePath) @@ -101,8 +106,6 @@ class VcpkgRepo: self.tagContents = "{}_{}".format(self.id, self.version) print("prebuild path: " + self.path) - # OS dependent information - system = platform.system() if 'Windows' == system: self.exe = os.path.join(self.path, 'vcpkg.exe') self.vcpkgUrl = 'https://hifi-public.s3.amazonaws.com/dependencies/vcpkg/vcpkg-win32.tar.gz?versionId=YZYkDejDRk7L_hrK_WVFthWvisAhbDzZ' diff --git a/scripts/developer/utilities/lib/jet/jet.js b/scripts/developer/utilities/lib/jet/jet.js index 85842b8861..71fb3e1f70 100644 --- a/scripts/developer/utilities/lib/jet/jet.js +++ b/scripts/developer/utilities/lib/jet/jet.js @@ -73,6 +73,121 @@ function job_print_functor(printout, showProps, maxDepth) { } } +// Use this function to create a functor that will build a tree datastructure of the Job visited + +function job_tree_model_array_functor(jobTreeArray, newNodeFunctor) { + var jobsRoot; + var numJobs = 0; + var jobTreePath = [] + if (newNodeFunctor === undefined) newNodeFunctor = function (node) {} + + return function (job, depth, index) { + var id = numJobs + var newItem = {"name": job.objectName, "level": depth, "index": index, "id": id, "subNode": [], "path": ""} + if (depth == 0) { + newNodeFunctor(newItem) + jobTreeArray.push(newItem) + numJobs++ + jobsRoot = jobTreeArray[0].subNode; + } else { + if (jobTreePath.length < depth) { + var node = jobsRoot; + var path; + for (var n = 0; n < jobTreePath.length; n++) { + newItem.path += (n > 0 ? "." : "") + node[jobTreePath[n]].name + node = node[jobTreePath[n]].subNode + } + + newNodeFunctor(newItem) + node.push((newItem)) + numJobs++ + jobTreePath.push(0); + } else if (jobTreePath.length >= depth) { + var node = jobsRoot; + for (var n = 0; n < (depth - 1); n++) { + newItem.path += (n > 0 ? "." : "") + node[jobTreePath[n]].name + node = node[jobTreePath[n]].subNode + } + + newNodeFunctor(newItem) + node.push((newItem)) + numJobs++ + jobTreePath[depth-1] = index; + while (jobTreePath.length > depth) { + jobTreePath.pop(); + } + } + } + return true; + } +} + +function job_tree_model_functor(jobTreeModel, maxLevel, newNodeFunctor) { + var jobsRoot; + var numJobs = 0; + var jobTreePath = [] + if (newNodeFunctor === undefined) newNodeFunctor = function (node) {} + + return function (job, depth, index) { + var id = numJobs + var newItem = {"name": job.objectName, "level": depth, "index": index, "id": id, "subNode": [], "path": "", "init": (depth < maxLevel), "ud": {}} + if (depth == 0) { + newNodeFunctor(newItem) + jobTreeModel.append(newItem) + numJobs++ + jobsRoot = jobTreeModel.get(0).subNode; + } else { + if (jobTreePath.length < depth) { + var node = jobsRoot; + var path; + for (var n = 0; n < jobTreePath.length; n++) { + newItem.path += (n > 0 ? "." : "") + node.get(jobTreePath[n]).name + node = node.get(jobTreePath[n]).subNode + } + + newNodeFunctor(newItem) + node.append((newItem)) + numJobs++ + jobTreePath.push(0); + } else if (jobTreePath.length >= depth) { + var node = jobsRoot; + for (var n = 0; n < (depth - 1); n++) { + newItem.path += (n > 0 ? "." : "") + node.get(jobTreePath[n]).name + node = node.get(jobTreePath[n]).subNode + } + + newNodeFunctor(newItem) + node.append((newItem)) + numJobs++ + jobTreePath[depth-1] = index; + while (jobTreePath.length > depth) { + jobTreePath.pop(); + } + } + } + return true; + } +} + + +// Traverse the jobTreenode data structure created above +function job_traverseTreeNode(root, functor, depth) { + if (root.subNode.length) { + depth++; + for (var i = 0; i 0 ? "." : "") + node.get(jobTreePath[n]).name - node = node.get(jobTreePath[n]).subNode - } - node.append(newItem) - jobTreePath.push(0); - } else if (jobTreePath.length >= depth) { - var node = jobsRoot; - for (var n = 0; n < (depth - 1); n++) { - newItem.path += (n > 0 ? "." : "") + node.get(jobTreePath[n]).name - node = node.get(jobTreePath[n]).subNode - } - node.append(newItem) - jobTreePath[depth-1] = index; - while (jobTreePath.length > depth) { - jobTreePath.pop(); - } - } - } - return true; - } - + var functor = Jet.job_tree_model_functor(jobsModel, 3, function(node) { + node["cpuT"] = 0.0 + }) Jet.task_traverseTree(rootConfig, functor); } - + ListModel { id: jobsModel + property var engineJobItemModel : [] } Component { @@ -77,30 +44,46 @@ Rectangle { id: objRecursiveColumn clip: true visible: model.init - - MouseArea { - width: objRow.implicitWidth - height: objRow.implicitHeight - onDoubleClicked: { - for(var i = 1; i < parent.children.length - 1; ++i) { - parent.children[i].visible = !parent.children[i].visible - } + + function switchFold() { + for(var i = 1; i < children.length - 1; ++i) { + children[i].visible = !children[i].visible } - Row { - id: objRow - Item { - height: 1 - width: model.level * 15 + } + + Row { + id: objRow + Item { + height: 1 + width: model.level * 15 + } + + HifiControls.CheckBox { + id: objCheck + property var config: root.rootConfig.getConfig(model.path + "." + model.name); + text: " " + checked: root.rootConfig.getConfig(model.path + "." + model.name).enabled + onCheckedChanged: { root.rootConfig.getConfig(model.path + "." + model.name).enabled = checked } + } + + MouseArea { + width: objLabel.implicitWidth + height: objLabel.implicitHeight + onDoubleClicked: { + parent.parent.switchFold() } - HifiControls.CheckBox { - property var config: root.rootConfig.getConfig(model.path + "." + model.name); + + HifiControls.Label { + id: objLabel + colorScheme: (root.rootConfig.getConfig(model.path + "." + model.name) ? hifi.colorSchemes.dark : hifi.colorSchemes.light) text: (objRecursiveColumn.children.length > 2 ? objRecursiveColumn.children[1].visible ? - qsTr("- ") : qsTr("+ ") : qsTr(" ")) + model.name + " ms=" + config.cpuRunTime.toFixed(2) - checked: config.enabled + qsTr("- ") : qsTr("+ ") : qsTr(" ")) + model.name + + " id=" + model.id } } } + Repeater { model: subNode delegate: objRecursiveDelegate diff --git a/scripts/developer/utilities/lib/jet/qml/TaskTimeFrameView.qml b/scripts/developer/utilities/lib/jet/qml/TaskTimeFrameView.qml new file mode 100644 index 0000000000..f3ca550e44 --- /dev/null +++ b/scripts/developer/utilities/lib/jet/qml/TaskTimeFrameView.qml @@ -0,0 +1,265 @@ +// +// jet/TaskTimeFrameView.qml +// +// Created by Sam Gateau, 2018/06/15 +// Copyright 2018 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 +// + +import QtQuick 2.7 +import QtQuick.Controls 1.4 as Original +import QtQuick.Controls.Styles 1.4 + +import "qrc:///qml/styles-uit" +import "qrc:///qml/controls-uit" as HifiControls + +import "../jet.js" as Jet + +Rectangle { + HifiConstants { id: hifi;} + color: Qt.rgba(hifi.colors.baseGray.r, hifi.colors.baseGray.g, hifi.colors.baseGray.b, 0.8); + id: root; + + property var rootConfig : Workload + + property var jobsTree + property var jobsArray + + + Component.onCompleted: { + if (!jobsTree) { jobsTree = new Array(); } + if (!jobsArray) { jobsArray = new Array(); } + + var tfunctor = Jet.job_tree_model_array_functor(jobsTree, function(node) { + var job = { "fullpath": (node.path + "." + node.name), "cpuT": 0.0, "depth": node.level, "name": node.name } + jobsArray.push(job) + }) + Jet.task_traverseTree(rootConfig, tfunctor); + + for (var j = 0; j ") + height: 24 + width: 24 + onClicked: { + print("list of highlight styles") + myCanvasTimer.running = !myCanvasTimer.running + } + } + } + Canvas { + id: mycanvas + anchors.top:myHeaderRow.bottom + anchors.bottom:parent.bottom + anchors.left:parent.left + anchors.right:parent.right + + property var frameDuration: 10 + property var frameViewBegin: 0 + property var frameViewRange: width + + function reset() { + frameViewBegin = 0 + frameViewRange = width + } + + function checkView() { + if (frameViewBegin > width * 0.9) { + frameViewBegin = width * 0.9 + } else if (frameViewBegin + frameViewRange < width * 0.1) { + frameViewBegin = width * 0.1 -frameViewRange + } + } + + function drag(deltaX) { + frameViewBegin -= deltaX + checkView() + } + + function pivotScale(pivotX, deltaX) { + var newRange = frameViewRange + 2 * deltaX + if (newRange <= 1) { + newRange = 2; + } + frameViewBegin = pivotX - frameViewRange * (pivotX - frameViewBegin) / newRange + frameViewRange = newRange + print( "pivot= " + pivotX + " deltaX= " + (deltaX)) + checkView() + } + + + onPaint: { + // print("mycanvasOnPaint " + jobsArray.length) + var lineHeight = 12; + + function getXFromTime(t) { + return (t / mycanvas.frameDuration) * mycanvas.frameViewRange - (mycanvas.frameViewBegin) + } + function getWFromDuration(d) { + return (d / mycanvas.frameDuration) * mycanvas.frameViewRange + } + function displayBackground(ctx) { + ctx.fillStyle = Qt.rgba(0, 0, 0, root.backgroundOpacity); + ctx.fillRect(0, 0, width, height); + + ctx.strokeStyle= "grey"; + ctx.lineWidth="2"; + + ctx.beginPath(); + ctx.moveTo(0, lineHeight + 1); + ctx.lineTo(width, lineHeight + 1); + ctx.moveTo(0, height); + ctx.lineTo(width, height); + + var x0 = getXFromTime(0) + ctx.moveTo(x0, 0); + ctx.lineTo(x0, height); + + x0 = getXFromTime(5) + ctx.moveTo(x0, 0); + ctx.lineTo(x0, height); + + x0 = getXFromTime(10) + ctx.moveTo(x0, 0); + ctx.lineTo(x0, height); + + ctx.stroke(); + } + + function drawJob(ctx, depth, index, duration, timeOffset) { + //print(root.jobsArray[index].cpuT) + ctx.fillStyle = ( depth % 2 ? ( index % 2 ? "blue" : "yellow") : ( index % 2 ? "green" : "red")) + ctx.fillRect(getXFromTime(timeOffset), lineHeight * 2 * depth,getWFromDuration(duration), lineHeight); + + if (depth,getWFromDuration(duration) >= width * 0.1) { + ctx.fillStyle = "grey"; + ctx.textAlign = "center"; + ctx.fillText( root.jobsArray[index].name, getXFromTime(timeOffset + duration * 0.5), lineHeight * 2 * depth); + + } + } + + var ctx = getContext("2d"); + ctx.clearRect(0, 0, width, height); + ctx.font="12px Verdana"; + + displayBackground(ctx); + if (jobsArray.length > 0) { + mycanvas.frameDuration = Math.max(jobsArray[0].cpuT, 1) + var rangeStack =new Array() + rangeStack.push( { "b": 0.0, "e": mycanvas.frameDuration } ) + + drawJob(ctx, 0, 0, jobsArray[0].cpuT, 0) + + for (var i = 1; i lastDepth) { + timeOffset = rangeStack[lastDepth].b + while(rangeStack.length <= depth) { + rangeStack.push( { "b": timeOffset, "e": timeOffset + duration } ) + } + + } else { + if (depth < lastDepth) { + while(rangeStack.length != (depth + 1)) { + rangeStack.pop() + } + } + + timeOffset = rangeStack[depth].e + rangeStack[depth].b = timeOffset + rangeStack[depth].e = timeOffset + duration + } + if (duration > 0.0) { + drawJob(ctx, depth, i, duration, timeOffset) + } + } + } + } + } + + MouseArea { + id: hitbox + anchors.fill: mycanvas + acceptedButtons: Qt.LeftButton | Qt.RightButton + + property var pivotX + property var dragPos + onPressed: { + dragPos = { "x":mouse.x, "y":mouse.y } + pivotX = mouse.x + } + onPositionChanged: { + if (dragPos !== undefined) { + var delta = mouse.x - dragPos.x + + if (mouse.buttons & Qt.LeftButton) { + mycanvas.drag(delta) + } + + if (mouse.buttons & Qt.RightButton) { + mycanvas.pivotScale(pivotX, delta) + } + + dragPos.x = mouse.x + dragPos.y = mouse.y + mycanvas.requestPaint() + } + } + onReleased: { + dragPos = undefined + } + + onWheel: { + mycanvas.pivotScale(wheel.x, mycanvas.frameViewRange * 0.02 * (wheel.angleDelta.y / 120.0)) + mycanvas.requestPaint() + } + + onDoubleClicked: { + mycanvas.reset() + mycanvas.requestPaint() + } + } +} \ No newline at end of file diff --git a/scripts/developer/utilities/lib/jet/qml/qmldir b/scripts/developer/utilities/lib/jet/qml/qmldir index 2df22caa6a..e16820914b 100644 --- a/scripts/developer/utilities/lib/jet/qml/qmldir +++ b/scripts/developer/utilities/lib/jet/qml/qmldir @@ -1,2 +1,3 @@ TaskList 1.0 TaskList.qml TaskViewList 1.0 TaskViewList.qml +TaskTimeFrameView 1.0 TaskTimeFrameView.qml diff --git a/scripts/developer/utilities/render/engineInspector.js b/scripts/developer/utilities/render/engineInspector.js index dcf13157b5..cd2b74f907 100644 --- a/scripts/developer/utilities/render/engineInspector.js +++ b/scripts/developer/utilities/render/engineInspector.js @@ -1,13 +1,57 @@ - function openEngineTaskView() { - // Set up the qml ui - var qml = Script.resolvePath('engineInspector.qml'); - var window = new OverlayWindow({ - title: 'Render Engine', - source: qml, - width: 300, - height: 400 + (function() { + var TABLET_BUTTON_NAME = "Inspector"; + var QMLAPP_URL = Script.resolvePath("./engineInspector.qml"); + var ICON_URL = Script.resolvePath("../../../system/assets/images/luci-i.svg"); + var ACTIVE_ICON_URL = Script.resolvePath("../../../system/assets/images/luci-a.svg"); + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + var button = tablet.addButton({ + text: TABLET_BUTTON_NAME, + icon: ICON_URL, + activeIcon: ACTIVE_ICON_URL }); - window.setPosition(200, 50); - //window.closed.connect(function() { Script.stop(); }); - } - openEngineTaskView(); \ No newline at end of file + + Script.scriptEnding.connect(function () { + killWindow() + button.clicked.disconnect(onClicked); + tablet.removeButton(button); + }); + + button.clicked.connect(onClicked); + + var onScreen = false; + var window; + + function onClicked() { + if (onScreen) { + killWindow() + } else { + createWindow() + } + } + + function createWindow() { + var qml = Script.resolvePath(QMLAPP_URL); + window = new OverlayWindow({ + title: 'Render Engine Inspector', + source: qml, + width: 250, + height: 500 + }); + window.setPosition(200, 50); + window.closed.connect(killWindow); + onScreen = true + button.editProperties({isActive: true}); + } + + function killWindow() { + if (window !== undefined) { + window.closed.disconnect(killWindow); + window.close() + window = undefined + } + onScreen = false + button.editProperties({isActive: false}) + } + }()); + \ No newline at end of file diff --git a/scripts/developer/utilities/render/engineInspector.qml b/scripts/developer/utilities/render/engineInspector.qml index 16dd8eb985..1e05605ac7 100644 --- a/scripts/developer/utilities/render/engineInspector.qml +++ b/scripts/developer/utilities/render/engineInspector.qml @@ -1,7 +1,7 @@ // -// deferredLighting.qml +// EngineInspector.qml // -// Created by Sam Gateau on 6/6/2016 +// Created by Sam Gateau on 06/07/2018 // Copyright 2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -18,13 +18,13 @@ import "../lib/jet/qml" as Jet Item { HifiConstants { id: hifi;} - id: render; + id: root; anchors.fill: parent - property var mainViewTask: Render.getConfig("RenderMainView") + property var rootConfig: Render.getConfig("") Jet.TaskListView { - rootConfig: Render - anchors.fill: render + rootConfig: root.rootConfig + anchors.fill: root } } \ No newline at end of file diff --git a/scripts/developer/utilities/render/engineProfiler.js b/scripts/developer/utilities/render/engineProfiler.js new file mode 100644 index 0000000000..418cab8622 --- /dev/null +++ b/scripts/developer/utilities/render/engineProfiler.js @@ -0,0 +1,59 @@ + + + (function() { + var TABLET_BUTTON_NAME = "Profiler"; + var QMLAPP_URL = Script.resolvePath("./engineProfiler.qml"); + var ICON_URL = Script.resolvePath("../../../system/assets/images/luci-i.svg"); + var ACTIVE_ICON_URL = Script.resolvePath("../../../system/assets/images/luci-a.svg"); + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + var button = tablet.addButton({ + text: TABLET_BUTTON_NAME, + icon: ICON_URL, + activeIcon: ACTIVE_ICON_URL + }); + + Script.scriptEnding.connect(function () { + killWindow() + button.clicked.disconnect(onClicked); + tablet.removeButton(button); + }); + + button.clicked.connect(onClicked); + + var onScreen = false; + var window; + + function onClicked() { + if (onScreen) { + killWindow() + } else { + createWindow() + } + } + + function createWindow() { + var qml = Script.resolvePath(QMLAPP_URL); + window = Desktop.createWindow(Script.resolvePath(QMLAPP_URL), { + title: 'Render Engine Profiler', + flags: Desktop.ALWAYS_ON_TOP, + presentationMode: Desktop.PresentationMode.NATIVE, + size: {x: 500, y: 100} + }); + window.setPosition(200, 50); + window.closed.connect(killWindow); + onScreen = true + button.editProperties({isActive: true}); + } + + function killWindow() { + if (window !== undefined) { + window.closed.disconnect(killWindow); + window.close() + window = undefined + } + onScreen = false + button.editProperties({isActive: false}) + } + }()); + \ No newline at end of file diff --git a/scripts/developer/utilities/render/engineProfiler.qml b/scripts/developer/utilities/render/engineProfiler.qml new file mode 100644 index 0000000000..bfa049d089 --- /dev/null +++ b/scripts/developer/utilities/render/engineProfiler.qml @@ -0,0 +1,31 @@ +// +// EngineProfiler.qml +// +// Created by Sam Gateau on 06/07/2018 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.7 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 + +import "qrc:///qml/styles-uit" +import "qrc:///qml/controls-uit" as HifiControls + +import "../lib/jet/qml" as Jet + +Item { + HifiConstants { id: hifi;} + id: root; + anchors.fill: parent + + property var rootConfig: Render.getConfig("") + + + Jet.TaskTimeFrameView { + rootConfig: root.rootConfig + anchors.fill: root + } +} \ No newline at end of file diff --git a/scripts/system/commerce/wallet.js b/scripts/system/commerce/wallet.js index 5e0cdbb94b..3a8462c5cb 100644 --- a/scripts/system/commerce/wallet.js +++ b/scripts/system/commerce/wallet.js @@ -539,6 +539,9 @@ function fromQml(message) { case 'http.request': // Handled elsewhere, don't log. break; + case 'closeSendAsset': + ui.close(); + break; default: print('wallet.js: Unrecognized message from QML'); } @@ -612,7 +615,9 @@ function notificationPollCallbackHistory(historyArray) { ui.notificationDisplayBanner(message); } else { for (var i = 0; i < notificationCount; i++) { - message = '"' + (historyArray[i].message) + '" ' + + var historyMessage = historyArray[i].message; + var sanitizedHistoryMessage = historyMessage.replace(/<\/?[^>]+(>|$)/g, ""); + message = '"' + sanitizedHistoryMessage + '" ' + "Open INVENTORY to see all activity."; ui.notificationDisplayBanner(message); } @@ -663,6 +668,7 @@ function uninstallMarketplaceItemTester() { var BUTTON_NAME = "INVENTORY"; var WALLET_QML_SOURCE = "hifi/commerce/wallet/Wallet.qml"; +var SENDASSET_QML_SOURCE = "hifi/commerce/common/sendAsset/SendAsset.qml"; var NOTIFICATION_POLL_TIMEOUT = 300000; var ui; function startup() { @@ -686,6 +692,7 @@ function startup() { buttonName: BUTTON_NAME, sortOrder: 10, home: WALLET_QML_SOURCE, + additionalAppScreens: SENDASSET_QML_SOURCE, onOpened: walletOpened, onClosed: walletClosed, onMessage: fromQml, diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index b657faefba..2658f11989 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -129,9 +129,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); return getControllerWorldLocation(Controller.Standard.RightHand, true); }; - Selection.enableListHighlight(DISPATCHER_HOVERING_LIST, DISPATCHER_HOVERING_STYLE); - Selection.enableListToScene(DISPATCHER_HOVERING_LIST); - this.updateTimings = function () { _this.intervalCount++; var thisInterval = Date.now(); @@ -525,7 +522,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Controller.disableMapping(MAPPING_NAME); _this.pointerManager.removePointers(); Pointers.removePointer(this.mouseRayPick); - Selection.disableListHighlight(DISPATCHER_HOVERING_LIST); }; } diff --git a/scripts/system/controllers/controllerModules/equipEntity.js b/scripts/system/controllers/controllerModules/equipEntity.js index 12a69d7b27..c61e46c8eb 100644 --- a/scripts/system/controllers/controllerModules/equipEntity.js +++ b/scripts/system/controllers/controllerModules/equipEntity.js @@ -459,13 +459,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa this.dropGestureReset(); this.clearEquipHaptics(); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); - unhighlightTargetEntity(this.targetEntityID); - var message = { - hand: this.hand, - entityID: this.targetEntityID - }; - Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var grabbedProperties = Entities.getEntityProperties(this.targetEntityID, DISPATCHER_PROPERTIES); var grabData = getGrabbableData(grabbedProperties); diff --git a/scripts/system/controllers/controllerModules/farActionGrabEntity.js b/scripts/system/controllers/controllerModules/farActionGrabEntity.js index 91119a4292..1eaed44ce2 100644 --- a/scripts/system/controllers/controllerModules/farActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farActionGrabEntity.js @@ -84,7 +84,6 @@ Script.include("/~/system/libraries/controllers.js"); this.entityWithContextOverlay = false; this.contextOverlayTimer = false; this.locked = false; - this.highlightedEntity = null; this.reticleMinX = MARGIN; this.reticleMaxX = null; this.reticleMinY = MARGIN; @@ -410,9 +409,6 @@ Script.include("/~/system/libraries/controllers.js"); if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || (this.notPointingAtEntity(controllerData) && Window.isPhysicsEnabled()) || this.targetIsNull()) { this.endFarGrabAction(); - Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", - this.highlightedEntity); - this.highlightedEntity = null; this.restoreIgnoredEntities(); return makeRunningValues(false, [], []); } @@ -466,9 +462,6 @@ Script.include("/~/system/libraries/controllers.js"); if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) { if (controllerData.triggerClicks[this.hand]) { var entityID = rayPickInfo.objectID; - Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", - this.highlightedEntity); - this.highlightedEntity = null; var targetProps = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES); if (targetProps.href !== "") { AddressManager.handleLookupString(targetProps.href); @@ -513,66 +506,43 @@ Script.include("/~/system/libraries/controllers.js"); this.startFarGrabAction(controllerData, targetProps); } } - } else { - var targetEntityID = rayPickInfo.objectID; - if (this.highlightedEntity !== targetEntityID) { - Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", - this.highlightedEntity); - var selectionTargetProps = Entities.getEntityProperties(targetEntityID, DISPATCHER_PROPERTIES); + } else if (!this.entityWithContextOverlay) { + var _this = this; - var selectionTargetObject = new TargetObject(targetEntityID, selectionTargetProps); - selectionTargetObject.parentProps = getEntityParents(selectionTargetProps); - var selectionTargetEntity = selectionTargetObject.getTargetEntity(); - - if (entityIsGrabbable(selectionTargetEntity.props) || - entityIsGrabbable(selectionTargetObject.entityProps)) { - - Selection.addToSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", rayPickInfo.objectID); + if (_this.potentialEntityWithContextOverlay !== rayPickInfo.objectID) { + if (_this.contextOverlayTimer) { + Script.clearTimeout(_this.contextOverlayTimer); } - this.highlightedEntity = rayPickInfo.objectID; + _this.contextOverlayTimer = false; + _this.potentialEntityWithContextOverlay = rayPickInfo.objectID; } - if (!this.entityWithContextOverlay) { - var _this = this; - - if (_this.potentialEntityWithContextOverlay !== rayPickInfo.objectID) { - if (_this.contextOverlayTimer) { - Script.clearTimeout(_this.contextOverlayTimer); + if (!_this.contextOverlayTimer) { + _this.contextOverlayTimer = Script.setTimeout(function () { + if (!_this.entityWithContextOverlay && + _this.contextOverlayTimer && + _this.potentialEntityWithContextOverlay === rayPickInfo.objectID) { + var props = Entities.getEntityProperties(rayPickInfo.objectID, DISPATCHER_PROPERTIES); + var pointerEvent = { + type: "Move", + id: _this.hand + 1, // 0 is reserved for hardware mouse + pos2D: projectOntoEntityXYPlane(rayPickInfo.objectID, + rayPickInfo.intersection, props), + pos3D: rayPickInfo.intersection, + normal: rayPickInfo.surfaceNormal, + direction: Vec3.subtract(ZERO_VEC, rayPickInfo.surfaceNormal), + button: "Secondary" + }; + if (ContextOverlay.createOrDestroyContextOverlay(rayPickInfo.objectID, pointerEvent)) { + _this.entityWithContextOverlay = rayPickInfo.objectID; + } } _this.contextOverlayTimer = false; - _this.potentialEntityWithContextOverlay = rayPickInfo.objectID; - } - - if (!_this.contextOverlayTimer) { - _this.contextOverlayTimer = Script.setTimeout(function () { - if (!_this.entityWithContextOverlay && - _this.contextOverlayTimer && - _this.potentialEntityWithContextOverlay === rayPickInfo.objectID) { - var props = Entities.getEntityProperties(rayPickInfo.objectID, DISPATCHER_PROPERTIES); - var pointerEvent = { - type: "Move", - id: _this.hand + 1, // 0 is reserved for hardware mouse - pos2D: projectOntoEntityXYPlane(rayPickInfo.objectID, - rayPickInfo.intersection, props), - pos3D: rayPickInfo.intersection, - normal: rayPickInfo.surfaceNormal, - direction: Vec3.subtract(ZERO_VEC, rayPickInfo.surfaceNormal), - button: "Secondary" - }; - if (ContextOverlay.createOrDestroyContextOverlay(rayPickInfo.objectID, pointerEvent)) { - _this.entityWithContextOverlay = rayPickInfo.objectID; - } - } - _this.contextOverlayTimer = false; - }, 500); - } + }, 500); } } } else if (this.distanceRotating) { this.distanceRotate(otherFarGrabModule); - } else if (this.highlightedEntity) { - Selection.removeFromSelectedItemsList(DISPATCHER_HOVERING_LIST, "entity", this.highlightedEntity); - this.highlightedEntity = null; } } return this.exitIfDisabled(controllerData); diff --git a/scripts/system/controllers/controllerModules/farParentGrabEntity.js b/scripts/system/controllers/controllerModules/farParentGrabEntity.js index f85869aa7f..230c4f06db 100644 --- a/scripts/system/controllers/controllerModules/farParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farParentGrabEntity.js @@ -61,6 +61,8 @@ Script.include("/~/system/libraries/controllers.js"); this.reticleMinY = MARGIN; this.reticleMaxY = 0; this.lastUnexpectedChildrenCheckTime = 0; + this.endedGrab = 0; + this.MIN_HAPTIC_PULSE_INTERVAL = 500; // ms var FAR_GRAB_JOINTS = [65527, 65528]; // FARGRAB_LEFTHAND_INDEX, FARGRAB_RIGHTHAND_INDEX @@ -144,7 +146,12 @@ Script.include("/~/system/libraries/controllers.js"); // compute the mass for the purpose of energy and how quickly to move object this.mass = this.getMass(grabbedProperties.dimensions, grabbedProperties.density); - Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); + // Debounce haptic pules. Can occur as near grab controller module vacillates between being ready or not due to + // changing positions and floating point rounding. + if (Date.now() - this.endedGrab > this.MIN_HAPTIC_PULSE_INTERVAL) { + Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); + } + unhighlightTargetEntity(this.targetEntityID); var message = { hand: this.hand, @@ -256,7 +263,7 @@ Script.include("/~/system/libraries/controllers.js"); }; this.endFarParentGrab = function (controllerData) { - this.hapticTargetID = null; + this.endedGrab = Date.now(); // var endProps = controllerData.nearbyEntityPropertiesByID[this.targetEntityID]; var endProps = Entities.getEntityProperties(this.targetEntityID, DISPATCHER_PROPERTIES); if (this.thisFarGrabJointIsParent(endProps)) { @@ -410,11 +417,6 @@ Script.include("/~/system/libraries/controllers.js"); if (targetEntity) { var gtProps = Entities.getEntityProperties(targetEntity, DISPATCHER_PROPERTIES); if (entityIsGrabbable(gtProps)) { - // give haptic feedback - if (gtProps.id !== this.hapticTargetID) { - Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); - this.hapticTargetID = gtProps.id; - } // if we've attempted to grab a child, roll up to the root of the tree var groupRootProps = findGroupParent(controllerData, gtProps); if (entityIsGrabbable(groupRootProps)) { diff --git a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js b/scripts/system/controllers/controllerModules/highlightNearbyEntities.js deleted file mode 100644 index 403b5d5149..0000000000 --- a/scripts/system/controllers/controllerModules/highlightNearbyEntities.js +++ /dev/null @@ -1,155 +0,0 @@ -// -// highlightNearbyEntities.js -// -// Created by Dante Ruiz 2018-4-10 -// Copyright 2017 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 - - -/* global Script, MyAvatar, entityIsCloneable, Messages, print */ - -"use strict"; - -(function () { - Script.include("/~/system/libraries/controllerDispatcherUtils.js"); - Script.include("/~/system/libraries/controllers.js"); - Script.include("/~/system/libraries/cloneEntityUtils.js"); - var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js"); - - function differenceInArrays(firstArray, secondArray) { - var differenceArray = firstArray.filter(function(element) { - return secondArray.indexOf(element) < 0; - }); - - return differenceArray; - } - - function HighlightNearbyEntities(hand) { - this.hand = hand; - this.otherHand = hand === dispatcherUtils.RIGHT_HAND ? dispatcherUtils.LEFT_HAND : - dispatcherUtils.RIGHT_HAND; - this.highlightedEntities = []; - - this.parameters = dispatcherUtils.makeDispatcherModuleParameters( - 480, - this.hand === dispatcherUtils.RIGHT_HAND ? ["rightHand"] : ["leftHand"], - [], - 100); - - - this.isGrabable = function(controllerData, props) { - var canGrabEntity = false; - if (dispatcherUtils.entityIsGrabbable(props) || entityIsCloneable(props)) { - // if we've attempted to grab a child, roll up to the root of the tree - var groupRootProps = dispatcherUtils.findGroupParent(controllerData, props); - canGrabEntity = true; - if (!dispatcherUtils.entityIsGrabbable(groupRootProps)) { - canGrabEntity = false; - } - } - return canGrabEntity; - }; - - this.clearAll = function() { - this.highlightedEntities.forEach(function(entity) { - dispatcherUtils.unhighlightTargetEntity(entity); - }); - }; - - this.hasHyperLink = function(props) { - return (props.href !== "" && props.href !== undefined); - }; - - this.removeEntityFromHighlightList = function(entityID) { - var index = this.highlightedEntities.indexOf(entityID); - if (index > -1) { - this.highlightedEntities.splice(index, 1); - } - }; - - this.getOtherModule = function() { - var otherModule = this.hand === dispatcherUtils.RIGHT_HAND ? leftHighlightNearbyEntities : - rightHighlightNearbyEntities; - return otherModule; - }; - - this.getOtherHandHighlightedEntities = function() { - return this.getOtherModule().highlightedEntities; - }; - - this.highlightEntities = function(controllerData) { - var nearbyEntitiesProperties = controllerData.nearbyEntityProperties[this.hand]; - var otherHandHighlightedEntities = this.getOtherHandHighlightedEntities(); - var newHighlightedEntities = []; - var sensorScaleFactor = MyAvatar.sensorToWorldScale; - for (var i = 0; i < nearbyEntitiesProperties.length; i++) { - var props = nearbyEntitiesProperties[i]; - if (props.distance > dispatcherUtils.NEAR_GRAB_RADIUS * sensorScaleFactor) { - continue; - } - if (this.isGrabable(controllerData, props) || this.hasHyperLink(props)) { - dispatcherUtils.highlightTargetEntity(props.id); - if (newHighlightedEntities.indexOf(props.id) < 0) { - newHighlightedEntities.push(props.id); - } - } - } - - var unhighlightEntities = differenceInArrays(this.highlightedEntities, newHighlightedEntities); - - unhighlightEntities.forEach(function(entityID) { - if (otherHandHighlightedEntities.indexOf(entityID) < 0 ) { - dispatcherUtils.unhighlightTargetEntity(entityID); - } - }); - this.highlightedEntities = newHighlightedEntities; - }; - - this.isReady = function(controllerData) { - this.highlightEntities(controllerData); - return dispatcherUtils.makeRunningValues(false, [], []); - }; - - this.run = function(controllerData) { - return this.isReady(controllerData); - }; - } - - var handleMessage = function(channel, message, sender) { - var data; - if (sender === MyAvatar.sessionUUID) { - if (channel === 'Hifi-unhighlight-entity') { - try { - data = JSON.parse(message); - var hand = data.hand; - if (hand === dispatcherUtils.LEFT_HAND) { - leftHighlightNearbyEntities.removeEntityFromHighlightList(data.entityID); - } else if (hand === dispatcherUtils.RIGHT_HAND) { - rightHighlightNearbyEntities.removeEntityFromHighlightList(data.entityID); - } - } catch (e) { - print("highlightNearbyEntities -- Failed to parse message: " + JSON.stringify(message)); - } - } else if (channel === 'Hifi-unhighlight-all') { - leftHighlightNearbyEntities.clearAll(); - rightHighlightNearbyEntities.clearAll(); - } - } - }; - var leftHighlightNearbyEntities = new HighlightNearbyEntities(dispatcherUtils.LEFT_HAND); - var rightHighlightNearbyEntities = new HighlightNearbyEntities(dispatcherUtils.RIGHT_HAND); - - dispatcherUtils.enableDispatcherModule("LeftHighlightNearbyEntities", leftHighlightNearbyEntities); - dispatcherUtils.enableDispatcherModule("RightHighlightNearbyEntities", rightHighlightNearbyEntities); - - function cleanup() { - dispatcherUtils.disableDispatcherModule("LeftHighlightNearbyEntities"); - dispatcherUtils.disableDispatcherModule("RightHighlightNearbyEntities"); - } - Messages.subscribe('Hifi-unhighlight-entity'); - Messages.subscribe('Hifi-unhighlight-all'); - Messages.messageReceived.connect(handleMessage); - Script.scriptEnding.connect(cleanup); -}()); diff --git a/scripts/system/controllers/controllerModules/mouseHMD.js b/scripts/system/controllers/controllerModules/mouseHMD.js index 27fe82ca19..172923a8e2 100644 --- a/scripts/system/controllers/controllerModules/mouseHMD.js +++ b/scripts/system/controllers/controllerModules/mouseHMD.js @@ -29,6 +29,7 @@ function MouseHMD() { var _this = this; + this.hmdWasActive = HMD.active; this.mouseMoved = false; this.mouseActivity = new TimeLock(5000); this.handControllerActivity = new TimeLock(4000); @@ -102,6 +103,8 @@ this.isReady = function(controllerData, deltaTime) { var now = Date.now(); + var hmdChanged = this.hmdWasActive !== HMD.active; + this.hmdWasActive = HMD.active; this.triggersPressed(controllerData, now); if (HMD.active) { if (!this.mouseActivity.expired(now) && _this.handControllerActivity.expired()) { @@ -110,7 +113,7 @@ } else { Reticle.visible = false; } - } else if (!Reticle.visible) { + } else if (hmdChanged && !Reticle.visible) { Reticle.visible = true; } diff --git a/scripts/system/controllers/controllerModules/mouseHighlightEntities.js b/scripts/system/controllers/controllerModules/mouseHighlightEntities.js deleted file mode 100644 index 59a68d98a4..0000000000 --- a/scripts/system/controllers/controllerModules/mouseHighlightEntities.js +++ /dev/null @@ -1,104 +0,0 @@ -// -// mouseHighlightEntities.js -// -// scripts/system/controllers/controllerModules/ -// -// Created by Dante Ruiz 2018-4-11 -// Copyright 2017 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 -// - -/* jslint bitwise: true */ - -/* global Script, print, Entities, Messages, Picks, HMD, MyAvatar, isInEditMode, DISPATCHER_PROPERTIES */ - - -(function() { - Script.include("/~/system/libraries/utils.js"); - var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js"); - - function MouseHighlightEntities() { - this.highlightedEntity = null; - this.grabbedEntity = null; - - this.parameters = dispatcherUtils.makeDispatcherModuleParameters( - 5, - ["mouse"], - [], - 100); - - this.setGrabbedEntity = function(entity) { - this.grabbedEntity = entity; - this.highlightedEntity = null; - }; - - this.isReady = function(controllerData) { - if (HMD.active) { - if (this.highlightedEntity) { - dispatcherUtils.unhighlightTargetEntity(this.highlightedEntity); - this.highlightedEntity = null; - } - } else if (!this.grabbedEntity && !isInEditMode()) { - var pickResult = controllerData.mouseRayPick; - if (pickResult.type === Picks.INTERSECTED_ENTITY) { - var targetEntityID = pickResult.objectID; - - if (this.highlightedEntity !== targetEntityID) { - var targetProps = Entities.getEntityProperties(targetEntityID, DISPATCHER_PROPERTIES); - - if (this.highlightedEntity) { - dispatcherUtils.unhighlightTargetEntity(this.highlightedEntity); - this.highlightedEntity = null; - } - - if (dispatcherUtils.entityIsGrabbable(targetProps)) { - // highlight entity - dispatcherUtils.highlightTargetEntity(targetEntityID); - this.highlightedEntity = targetEntityID; - } - } - } else if (this.highlightedEntity) { - dispatcherUtils.unhighlightTargetEntity(this.highlightedEntity); - this.highlightedEntity = null; - } - } - - return dispatcherUtils.makeRunningValues(false, [], []); - }; - - this.run = function(controllerData) { - return this.isReady(controllerData); - }; - } - - var mouseHighlightEntities = new MouseHighlightEntities(); - dispatcherUtils.enableDispatcherModule("MouseHighlightEntities", mouseHighlightEntities); - - var handleMessage = function(channel, message, sender) { - var data; - if (sender === MyAvatar.sessionUUID) { - if (channel === 'Hifi-Object-Manipulation') { - try { - data = JSON.parse(message); - if (data.action === 'grab') { - var grabbedEntity = data.grabbedEntity; - mouseHighlightEntities.setGrabbedEntity(grabbedEntity); - } else if (data.action === 'release') { - mouseHighlightEntities.setGrabbedEntity(null); - } - } catch (e) { - print("Warning: mouseHighlightEntities -- error parsing Hifi-Object-Manipulation: " + message); - } - } - } - }; - - function cleanup() { - dispatcherUtils.disableDispatcherModule("MouseHighlightEntities"); - } - Messages.subscribe('Hifi-Object-Manipulation'); - Messages.messageReceived.connect(handleMessage); - Script.scriptEnding.connect(cleanup); -})(); diff --git a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js index 5ced6080a2..bb563a269c 100644 --- a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js @@ -24,7 +24,6 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); this.hand = hand; this.targetEntityID = null; this.actionID = null; // action this script created... - this.hapticTargetID = null; this.parameters = makeDispatcherModuleParameters( 500, @@ -115,13 +114,6 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(this.targetEntityID, "startNearGrab", args); - unhighlightTargetEntity(this.targetEntityID); - var message = { - hand: this.hand, - entityID: this.targetEntityID - }; - - Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); }; // this is for when the action is going to time-out @@ -171,10 +163,6 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); break; } if (entityIsGrabbable(props) || entityIsCloneable(props)) { - if (props.id !== this.hapticTargetID) { - Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); - this.hapticTargetID = props.id; - } if (!entityIsCloneable(props)) { // if we've attempted to grab a non-cloneable child, roll up to the root of the tree var groupRootProps = findGroupParent(controllerData, props); @@ -206,7 +194,6 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); return makeRunningValues(true, [this.targetEntityID], []); } } else { - this.hapticTargetID = null; return makeRunningValues(false, [], []); } }; @@ -216,7 +203,6 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); if (controllerData.triggerClicks[this.hand] < TRIGGER_OFF_VALUE && controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) { this.endNearGrabAction(); - this.hapticTargetID = null; return makeRunningValues(false, [], []); } diff --git a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js index f354067a77..13557bdb7e 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabEntity.js @@ -11,7 +11,7 @@ TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, entityIsGrabbable, makeRunningValues, NEAR_GRAB_RADIUS, findGroupParent, Vec3, cloneEntity, entityIsCloneable, propsAreCloneDynamic, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, BUMPER_ON_VALUE, findHandChildEntities, TEAR_AWAY_DISTANCE, MSECS_PER_SEC, TEAR_AWAY_CHECK_TIME, - TEAR_AWAY_COUNT, distanceBetweenPointAndEntityBoundingBox, print, Uuid, highlightTargetEntity, unhighlightTargetEntity, + TEAR_AWAY_COUNT, distanceBetweenPointAndEntityBoundingBox, print, Uuid, NEAR_GRAB_DISTANCE, distanceBetweenEntityLocalPositionAndBoundingBox, getGrabbableData, getGrabPointSphereOffset, DISPATCHER_PROPERTIES */ @@ -24,15 +24,6 @@ Script.include("/~/system/libraries/controllers.js"); // XXX this.ignoreIK = (grabbableData.ignoreIK !== undefined) ? grabbableData.ignoreIK : true; // XXX this.kinematicGrab = (grabbableData.kinematic !== undefined) ? grabbableData.kinematic : NEAR_GRABBING_KINEMATIC; - // this offset needs to match the one in libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp:378 - var GRAB_POINT_SPHERE_OFFSET = { x: 0.04, y: 0.13, z: 0.039 }; // x = upward, y = forward, z = lateral - - function getGrabOffset(handController) { - var offset = getGrabPointSphereOffset(handController, true); - offset.y = -offset.y; - return Vec3.multiply(MyAvatar.sensorToWorldScale, offset); - } - function NearParentingGrabEntity(hand) { this.hand = hand; this.targetEntityID = null; @@ -40,12 +31,10 @@ Script.include("/~/system/libraries/controllers.js"); this.previousParentID = {}; this.previousParentJointIndex = {}; this.previouslyUnhooked = {}; - this.hapticTargetID = null; this.lastUnequipCheckTime = 0; this.autoUnequipCounter = 0; this.lastUnexpectedChildrenCheckTime = 0; this.robbed = false; - this.highlightedEntity = null; this.cloneAllowed = true; this.parameters = makeDispatcherModuleParameters( @@ -95,14 +84,7 @@ Script.include("/~/system/libraries/controllers.js"); this.startNearParentingGrabEntity = function (controllerData, targetProps) { var grabData = getGrabbableData(targetProps); Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); - unhighlightTargetEntity(this.targetEntityID); - this.highlightedEntity = null; - var message = { - hand: this.hand, - entityID: this.targetEntityID - }; - Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var handJointIndex; if (grabData.grabFollowsController) { handJointIndex = getControllerJointIndex(this.hand); @@ -146,7 +128,6 @@ Script.include("/~/system/libraries/controllers.js"); }; this.endNearParentingGrabEntity = function (controllerData) { - this.hapticTargetID = null; var props = controllerData.nearbyEntityPropertiesByID[this.targetEntityID]; if (this.thisHandIsParent(props) && !this.robbed) { Entities.editEntity(this.targetEntityID, { @@ -164,8 +145,7 @@ Script.include("/~/system/libraries/controllers.js"); grabbedEntity: this.targetEntityID, joint: this.hand === RIGHT_HAND ? "RightHand" : "LeftHand" })); - unhighlightTargetEntity(this.targetEntityID); - this.highlightedEntity = null; + this.grabbing = false; this.targetEntityID = null; this.robbed = false; @@ -178,8 +158,10 @@ Script.include("/~/system/libraries/controllers.js"); this.lastUnequipCheckTime = now; if (props.parentID === MyAvatar.SELF_ID) { var tearAwayDistance = TEAR_AWAY_DISTANCE * MyAvatar.sensorToWorldScale; - var controllerIndex = (this.hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand); - var controllerGrabOffset = getGrabOffset(controllerIndex); + var controllerIndex = + this.hand === LEFT_HAND ? Controller.Standard.LeftHand : Controller.Standard.RightHand; + var controllerGrabOffset = getGrabPointSphereOffset(controllerIndex, true); + controllerGrabOffset = Vec3.multiply(-MyAvatar.sensorToWorldScale, controllerGrabOffset); var distance = distanceBetweenEntityLocalPositionAndBoundingBox(props, controllerGrabOffset); if (distance > tearAwayDistance) { this.autoUnequipCounter++; @@ -242,21 +224,18 @@ Script.include("/~/system/libraries/controllers.js"); // nearbyEntityProperties is already sorted by length from controller var nearbyEntityProperties = controllerData.nearbyEntityProperties[this.hand]; var sensorScaleFactor = MyAvatar.sensorToWorldScale; + var nearGrabDistance = NEAR_GRAB_DISTANCE * sensorScaleFactor; + var nearGrabRadius = NEAR_GRAB_RADIUS * sensorScaleFactor; for (var i = 0; i < nearbyEntityProperties.length; i++) { var props = nearbyEntityProperties[i]; - var handPosition = controllerData.controllerLocations[this.hand].position; - var dist = distanceBetweenPointAndEntityBoundingBox(handPosition, props); - var distance = Vec3.distance(handPosition, props.position); - if ((dist > TEAR_AWAY_DISTANCE) || - (distance > NEAR_GRAB_RADIUS * sensorScaleFactor)) { + var grabPosition = controllerData.controllerLocations[this.hand].position; // Is offset from hand position. + var dist = distanceBetweenPointAndEntityBoundingBox(grabPosition, props); + var distance = Vec3.distance(grabPosition, props.position); + if ((dist > nearGrabDistance) || + (distance > nearGrabRadius)) { // Only smallish entities can be near grabbed. continue; } if (entityIsGrabbable(props) || entityIsCloneable(props)) { - // give haptic feedback - if (props.id !== this.hapticTargetID) { - Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand); - this.hapticTargetID = props.id; - } if (!entityIsCloneable(props)) { // if we've attempted to grab a non-cloneable child, roll up to the root of the tree var groupRootProps = findGroupParent(controllerData, props); @@ -290,16 +269,9 @@ Script.include("/~/system/libraries/controllers.js"); return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it } else { this.targetEntityID = targetProps.id; - this.highlightedEntity = this.targetEntityID; - highlightTargetEntity(this.targetEntityID); return makeRunningValues(true, [this.targetEntityID], []); } } else { - if (this.highlightedEntity) { - unhighlightTargetEntity(this.highlightedEntity); - this.highlightedEntity = null; - } - this.hapticTargetID = null; this.robbed = false; return makeRunningValues(false, [], []); } @@ -316,11 +288,8 @@ Script.include("/~/system/libraries/controllers.js"); var props = controllerData.nearbyEntityPropertiesByID[this.targetEntityID]; if (!props) { // entity was deleted - unhighlightTargetEntity(this.targetEntityID); - this.highlightedEntity = null; this.grabbing = false; this.targetEntityID = null; - this.hapticTargetID = null; this.robbed = false; return makeRunningValues(false, [], []); } @@ -335,12 +304,10 @@ Script.include("/~/system/libraries/controllers.js"); var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(this.targetEntityID, "continueNearGrab", args); } else { - // still searching / highlighting + // still searching var readiness = this.isReady(controllerData); if (!readiness.active) { this.robbed = false; - unhighlightTargetEntity(this.highlightedEntity); - this.highlightedEntity = null; return readiness; } if (controllerData.triggerClicks[this.hand] || controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE) { diff --git a/scripts/system/controllers/controllerModules/nearTrigger.js b/scripts/system/controllers/controllerModules/nearTrigger.js index f4e39cfbb9..4bff4ea3f0 100644 --- a/scripts/system/controllers/controllerModules/nearTrigger.js +++ b/scripts/system/controllers/controllerModules/nearTrigger.js @@ -7,7 +7,7 @@ /* global Script, Entities, MyAvatar, RIGHT_HAND, LEFT_HAND, enableDispatcherModule, disableDispatcherModule, getGrabbableData, - Vec3, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, makeRunningValues, NEAR_GRAB_RADIUS, unhighlightTargetEntity + Vec3, TRIGGER_OFF_VALUE, makeDispatcherModuleParameters, makeRunningValues, NEAR_GRAB_RADIUS */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -55,7 +55,6 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.startNearTrigger = function (controllerData) { var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(this.targetEntityID, "startNearTrigger", args); - unhighlightTargetEntity(this.targetEntityID); }; this.continueNearTrigger = function (controllerData) { diff --git a/scripts/system/controllers/controllerScripts.js b/scripts/system/controllers/controllerScripts.js index 999e448171..83fa455519 100644 --- a/scripts/system/controllers/controllerScripts.js +++ b/scripts/system/controllers/controllerScripts.js @@ -35,9 +35,7 @@ var CONTOLLER_SCRIPTS = [ "controllerModules/hudOverlayPointer.js", "controllerModules/mouseHMD.js", "controllerModules/scaleEntity.js", - "controllerModules/highlightNearbyEntities.js", "controllerModules/nearGrabHyperLinkEntity.js", - "controllerModules/mouseHighlightEntities.js", "controllerModules/nearTabletHighlight.js" ]; diff --git a/scripts/system/edit.js b/scripts/system/edit.js index 48fdb8e565..039f4f1e22 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -554,8 +554,9 @@ var toolBar = (function () { } } - SelectionManager.saveProperties(); entityID = Entities.addEntity(properties); + SelectionManager.addEntity(entityID, false, this); + SelectionManager.saveProperties(); pushCommandForSelections([{ entityID: entityID, properties: properties @@ -1273,6 +1274,7 @@ function mouseClickEvent(event) { } else { selectionManager.addEntity(foundEntity, true, this); } + selectionManager.saveProperties(); if (wantDebug) { print("Model selected: " + foundEntity); @@ -2130,12 +2132,17 @@ function applyEntityProperties(data) { entityID = DELETED_ENTITY_MAP[entityID]; } Entities.deleteEntity(entityID); + var index = selectedEntityIDs.indexOf(entityID); + if (index >= 0) { + selectedEntityIDs.splice(index, 1); + } } // We might be getting an undo while edit.js is disabled. If that is the case, don't set // our selections, causing the edit widgets to display. if (isActive) { selectionManager.setSelections(selectedEntityIDs, this); + selectionManager.saveProperties(); } } @@ -2223,6 +2230,7 @@ var PropertiesTool = function (opts) { // are selected or if no entity is selected this will be `null`. var currentSelectedEntityID = null; var statusMonitor = null; + var blockPropertyUpdates = false; that.setVisible = function (newVisible) { visible = newVisible; @@ -2260,6 +2268,10 @@ var PropertiesTool = function (opts) { }; function updateSelections(selectionUpdated) { + if (blockPropertyUpdates) { + return; + } + var data = { type: 'update', spaceMode: selectionDisplay.getSpaceMode() @@ -2319,7 +2331,6 @@ var PropertiesTool = function (opts) { } var i, properties, dY, diff, newPosition; if (data.type === "update") { - selectionManager.saveProperties(); if (selectionManager.selections.length > 1) { for (i = 0; i < selectionManager.selections.length; i++) { Entities.editEntity(selectionManager.selections[i], data.properties); @@ -2355,8 +2366,14 @@ var PropertiesTool = function (opts) { entityListTool.sendUpdate(); } } - pushCommandForSelections(); + if (data.onlyUpdateEntities) { + blockPropertyUpdates = true; + } else { + pushCommandForSelections(); + SelectionManager.saveProperties(); + } selectionManager._update(false, this); + blockPropertyUpdates = false; } else if (data.type === 'saveUserData' || data.type === 'saveMaterialData') { //the event bridge and json parsing handle our avatar id string differently. var actualID = data.id.split('"')[1]; @@ -2730,17 +2747,16 @@ keyUpEventFromUIWindow = function(keyUpEvent) { selectionManager.pasteEntities(); } else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "D") { selectionManager.duplicateSelection(); - } else if (keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") { - undoHistory.undo(); + } else if (!isOnMacPlatform && keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") { + undoHistory.undo(); // undo is only handled via handleMenuItem on Mac } else if (keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "P") { parentSelectedEntities(); } else if (keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "P") { unparentSelectedEntities(); - } else if ( - (keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") || - (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "Y")) { - - undoHistory.redo(); + } else if (!isOnMacPlatform && + ((keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") || + (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "Y"))) { + undoHistory.redo(); // redo is only handled via handleMenuItem on Mac } else if (WANT_DEBUG_MISSING_SHORTCUTS) { console.warn("unhandled key event: " + JSON.stringify(keyUpEvent)) } diff --git a/scripts/system/html/css/edit-style.css b/scripts/system/html/css/edit-style.css index a00dc4d57c..049a162871 100644 --- a/scripts/system/html/css/edit-style.css +++ b/scripts/system/html/css/edit-style.css @@ -590,9 +590,6 @@ div.section[collapsed="true"], div.section[collapsed="true"] > .section-header { background-color: #373737; } -.section-header { - cursor: pointer; -} .section-header span { font-size: 30px; @@ -919,7 +916,7 @@ div.refresh input[type="button"] { } .draggable-number div { height: 28px; - width: 92px; + width: 124px; } .draggable-number.text { display: inline-block; @@ -932,6 +929,7 @@ div.refresh input[type="button"] { height: 28px; width: 100%; line-height: 2; + box-sizing: border-box; } .draggable-number.text:hover { cursor: ew-resize; @@ -947,13 +945,13 @@ div.refresh input[type="button"] { cursor: default; } .draggable-number.left-arrow { - top: -5px; - right: 106px; + top: 3px; + left: 0px; transform: rotate(180deg); } .draggable-number.right-arrow { - top: -5px; - left: 106px; + top: 3px; + right: 0px; } .draggable-number input[type=number] { position: absolute; @@ -974,14 +972,14 @@ div.refresh input[type="button"] { left: 12px; } .draggable-number.fstuple + .draggable-number.fstuple { - padding-left: 28px; + margin-left: 28px; } .draggable-number.fstuple input { right: -10px; } .draggable-number.fstuple .sublabel { position: absolute; - top: 0; + top: 6px; left: -16px; font-family: FiraSans-SemiBold; font-size: 15px; @@ -1123,7 +1121,7 @@ textarea:enabled[scrolling="true"]::-webkit-resizer { } -body#entity-list-body { +div#grid-section, body#entity-list-body { padding-bottom: 0; margin: 16px; } @@ -1556,14 +1554,15 @@ input.rename-entity { .container { display: flex; flex-flow: row nowrap; - justify-content: space-around; margin-bottom: 8px; min-height: 28px; } .container > label { margin-top: 6px; - width: 200px; + width: 160px; + min-width: 160px; + max-width: 160px; } .container > div.checkbox { @@ -1604,6 +1603,8 @@ input.rename-entity { .xyz.fstuple, .pyr.fstuple { position: relative; left: -12px; + min-width: 50px; + width: 100px; } .rgb.fstuple .tuple { @@ -1654,3 +1655,15 @@ input.number-slider { display: flex; width: 100%; } + +.spacemode-hidden { + display: none; +} + +#placeholder-property-type { + min-width: 0px; +} + +.collapse-icon { + cursor: pointer; +} diff --git a/scripts/system/html/gridControls.html b/scripts/system/html/gridControls.html index cd646fed51..4be002619a 100644 --- a/scripts/system/html/gridControls.html +++ b/scripts/system/html/gridControls.html @@ -19,47 +19,52 @@ -
    -
    - -
    -
    - +
    +
    +
    + + +
    -
    - +
    +
    + + +
    -
    +
    +
    -
    +
    +
    +
    -
    -
    +
    - -
    -
    -
    - -
    -
    -
    -
    +
    +
    -
    - +
    + +
    +
    +
    +
    +
    + +
    - +
    - \ No newline at end of file + diff --git a/scripts/system/html/js/colpick.js b/scripts/system/html/js/colpick.js index 505dd294d6..e4ad65dfb6 100644 --- a/scripts/system/html/js/colpick.js +++ b/scripts/system/html/js/colpick.js @@ -309,6 +309,9 @@ For usage and examples: colpick.com/plugin }, // Fix the values if the user enters a negative or high value fixHSB = function (hsb) { + hsb.h = isNaN(hsb.h) ? 0 : hsb.h; + hsb.s = isNaN(hsb.s) ? 0 : hsb.s; + hsb.b = isNaN(hsb.b) ? 0 : hsb.b; return { h: Math.min(360, Math.max(0, hsb.h)), s: Math.min(100, Math.max(0, hsb.s)), @@ -316,6 +319,9 @@ For usage and examples: colpick.com/plugin }; }, fixRGB = function (rgb) { + rgb.r = isNaN(rgb.r) ? 0 : rgb.r; + rgb.g = isNaN(rgb.g) ? 0 : rgb.g; + rgb.b = isNaN(rgb.b) ? 0 : rgb.b; return { r: Math.min(255, Math.max(0, rgb.r)), g: Math.min(255, Math.max(0, rgb.g)), diff --git a/scripts/system/html/js/draggableNumber.js b/scripts/system/html/js/draggableNumber.js index 1f4bc21441..e72881e1ae 100644 --- a/scripts/system/html/js/draggableNumber.js +++ b/scripts/system/html/js/draggableNumber.js @@ -7,12 +7,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html const DELTA_X_FOCUS_THRESHOLD = 1; +const ENTER_KEY = 13; -function DraggableNumber(min, max, step, decimals) { +function DraggableNumber(min, max, step, decimals, dragStart, dragEnd) { this.min = min; this.max = max; this.step = step !== undefined ? step : 1; this.decimals = decimals; + this.dragStartFunction = dragStart; + this.dragEndFunction = dragEnd; + this.dragging = false; this.initialMouseEvent = null; this.lastMouseEvent = null; this.valueChangeFunction = null; @@ -20,8 +24,22 @@ function DraggableNumber(min, max, step, decimals) { } DraggableNumber.prototype = { + showInput: function() { + this.elText.style.visibility = "hidden"; + this.elLeftArrow.style.visibility = "hidden"; + this.elRightArrow.style.visibility = "hidden"; + this.elInput.style.opacity = 1; + }, + + hideInput: function() { + this.elText.style.visibility = "visible"; + this.elLeftArrow.style.visibility = "visible"; + this.elRightArrow.style.visibility = "visible"; + this.elInput.style.opacity = 0; + }, + mouseDown: function(event) { - if (event.target === this.elText) { + if (event.target === this.elText && !this.isDisabled()) { this.initialMouseEvent = event; this.lastMouseEvent = event; document.addEventListener("mousemove", this.onDocumentMouseMove); @@ -30,31 +48,42 @@ DraggableNumber.prototype = { }, mouseUp: function(event) { - if (event.target === this.elText && this.initialMouseEvent) { + if (!this.dragging && event.target === this.elText && this.initialMouseEvent) { let dx = event.clientX - this.initialMouseEvent.clientX; - if (dx <= DELTA_X_FOCUS_THRESHOLD) { - this.elInput.style.visibility = "visible"; - this.elText.style.visibility = "hidden"; + if (Math.abs(dx) <= DELTA_X_FOCUS_THRESHOLD) { + this.showInput(); + this.elInput.focus(); } this.initialMouseEvent = null; } }, documentMouseMove: function(event) { - if (this.lastMouseEvent) { + if (!this.dragging && this.initialMouseEvent) { + let dxFromInitial = event.clientX - this.initialMouseEvent.clientX; + if (Math.abs(dxFromInitial) > DELTA_X_FOCUS_THRESHOLD) { + if (this.dragStartFunction) { + this.dragStartFunction(); + } + this.dragging = true; + } + this.lastMouseEvent = event; + } + if (this.dragging && this.lastMouseEvent) { let initialValue = this.elInput.value; let dx = event.clientX - this.lastMouseEvent.clientX; let changeValue = dx !== 0; if (changeValue) { while (dx !== 0) { if (dx > 0) { - this.stepUp(); + this.elInput.stepUp(); --dx; } else { - this.stepDown(); + this.elInput.stepDown(); ++dx; } } + this.inputChange(); if (this.valueChangeFunction) { this.valueChangeFunction(); } @@ -64,19 +93,35 @@ DraggableNumber.prototype = { }, documentMouseUp: function(event) { + if (this.dragging) { + if (this.dragEndFunction) { + this.dragEndFunction(); + } + this.dragging = false; + } this.lastMouseEvent = null; document.removeEventListener("mousemove", this.onDocumentMouseMove); document.removeEventListener("mouseup", this.onDocumentMouseUp); }, stepUp: function() { - this.elInput.stepUp(); - this.inputChange(); + if (!this.isDisabled()) { + this.elInput.stepUp(); + this.inputChange(); + if (this.valueChangeFunction) { + this.valueChangeFunction(); + } + } }, stepDown: function() { - this.elInput.stepDown(); - this.inputChange(); + if (!this.isDisabled()) { + this.elInput.stepDown(); + this.inputChange(); + if (this.valueChangeFunction) { + this.valueChangeFunction(); + } + } }, setValue: function(newValue) { @@ -89,9 +134,6 @@ DraggableNumber.prototype = { }, setValueChangeFunction: function(valueChangeFunction) { - if (this.valueChangeFunction) { - this.elInput.removeEventListener("change", this.valueChangeFunction); - } this.valueChangeFunction = valueChangeFunction.bind(this.elInput); this.elInput.addEventListener("change", this.valueChangeFunction); }, @@ -100,9 +142,18 @@ DraggableNumber.prototype = { this.setValue(this.elInput.value); }, - inputBlur: function() { - this.elInput.style.visibility = "hidden"; - this.elText.style.visibility = "visible"; + inputBlur: function(ev) { + this.hideInput(); + }, + + keyPress: function(event) { + if (event.keyCode === ENTER_KEY) { + this.inputBlur(); + } + }, + + isDisabled: function() { + return this.elText.getAttribute("disabled") === "disabled"; }, initialize: function() { @@ -114,6 +165,7 @@ DraggableNumber.prototype = { this.onStepDown = this.stepDown.bind(this); this.onInputChange = this.inputChange.bind(this); this.onInputBlur = this.inputBlur.bind(this); + this.onKeyPress = this.keyPress.bind(this); this.elDiv = document.createElement('div'); this.elDiv.className = "draggable-number"; @@ -146,13 +198,15 @@ DraggableNumber.prototype = { if (this.step !== undefined) { this.elInput.setAttribute("step", this.step); } - this.elInput.style.visibility = "hidden"; + this.elInput.style.opacity = 0; this.elInput.addEventListener("change", this.onInputChange); this.elInput.addEventListener("blur", this.onInputBlur); + this.elInput.addEventListener("keypress", this.onKeyPress); + this.elInput.addEventListener("focus", this.showInput.bind(this)); - this.elText.appendChild(this.elLeftArrow); - this.elText.appendChild(this.elInput); - this.elText.appendChild(this.elRightArrow); + this.elDiv.appendChild(this.elLeftArrow); + this.elDiv.appendChild(this.elInput); + this.elDiv.appendChild(this.elRightArrow); this.elDiv.appendChild(this.elText); } }; diff --git a/scripts/system/html/js/entityList.js b/scripts/system/html/js/entityList.js index 6f12dd1e7c..a51f470d2f 100644 --- a/scripts/system/html/js/entityList.js +++ b/scripts/system/html/js/entityList.js @@ -155,6 +155,9 @@ const ICON_FOR_TYPE = { Text: "l", }; +const DOUBLE_CLICK_TIMEOUT = 300; // ms +const RENAME_COOLDOWN = 400; // ms + // List of all entities let entities = []; // List of all entities, indexed by Entity ID @@ -185,6 +188,10 @@ let elTargetTh = null; let targetColumnIndex = 0; let lastColumnSwapPosition = -1; let initialThEvent = null; +let renameTimeout = null; +let renameLastBlur = null; +let renameLastEntityID = null; +let isRenameFieldBeingMoved = false; let elEntityTable, elEntityTableHeader, @@ -208,7 +215,8 @@ let elEntityTable, elNoEntitiesMessage, elColumnsMultiselectBox, elColumnsOptions, - elToggleSpaceMode; + elToggleSpaceMode, + elRenameInput; const ENABLE_PROFILING = false; let profileIndent = ''; @@ -388,19 +396,20 @@ function loaded() { elEntityTableHeaderRow = document.querySelectorAll("#entity-table thead th"); - entityList = new ListView(elEntityTableBody, elEntityTableScroll, elEntityTableHeaderRow, - createRow, updateRow, clearRow, WINDOW_NONVARIABLE_HEIGHT); + entityList = new ListView(elEntityTableBody, elEntityTableScroll, elEntityTableHeaderRow, createRow, updateRow, + clearRow, preRefresh, postRefresh, preRefresh, WINDOW_NONVARIABLE_HEIGHT); entityListContextMenu = new EntityListContextMenu(); function startRenamingEntity(entityID) { + renameLastEntityID = entityID; let entity = entitiesByID[entityID]; if (!entity || entity.locked || !entity.elRow) { return; } let elCell = entity.elRow.childNodes[getColumnIndex("name")]; - let elRenameInput = document.createElement("input"); + elRenameInput = document.createElement("input"); elRenameInput.setAttribute('class', 'rename-entity'); elRenameInput.value = entity.name; let ignoreClicks = function(event) { @@ -415,6 +424,9 @@ function loaded() { }; elRenameInput.onblur = function(event) { + if (isRenameFieldBeingMoved) { + return; + } let value = elRenameInput.value; EventBridge.emitWebEvent(JSON.stringify({ type: 'rename', @@ -422,7 +434,10 @@ function loaded() { name: value })); entity.name = value; - elCell.innerText = value; + elRenameInput.parentElement.innerText = value; + + renameLastBlur = Date.now(); + elRenameInput = null; }; elCell.innerHTML = ""; @@ -431,6 +446,32 @@ function loaded() { elRenameInput.select(); } + function preRefresh() { + // move the rename input to the body + if (!isRenameFieldBeingMoved && elRenameInput) { + isRenameFieldBeingMoved = true; + document.body.appendChild(elRenameInput); + // keep the focus + elRenameInput.select(); + } + } + + function postRefresh() { + if (!elRenameInput || !isRenameFieldBeingMoved) { + return; + } + let entity = entitiesByID[renameLastEntityID]; + if (!entity || entity.locked || !entity.elRow) { + return; + } + let elCell = entity.elRow.childNodes[getColumnIndex("name")]; + elCell.innerHTML = ""; + elCell.appendChild(elRenameInput); + // keep the focus + elRenameInput.select(); + isRenameFieldBeingMoved = false; + } + entityListContextMenu.setOnSelectedCallback(function(optionName, selectedEntityID) { switch (optionName) { case "Cut": @@ -455,6 +496,11 @@ function loaded() { }); function onRowContextMenu(clickEvent) { + if (elRenameInput) { + // disallow the context menu from popping up while renaming + return; + } + let entityID = this.dataset.entityID; if (!selectedEntities.includes(entityID)) { @@ -478,6 +524,13 @@ function loaded() { entityListContextMenu.open(clickEvent, entityID, enabledContextMenuItems); } + let clearRenameTimeout = () => { + if (renameTimeout !== null) { + window.clearTimeout(renameTimeout); + renameTimeout = null; + } + }; + function onRowClicked(clickEvent) { let entityID = this.dataset.entityID; let selection = [entityID]; @@ -516,7 +569,15 @@ function loaded() { } else if (!clickEvent.ctrlKey && !clickEvent.shiftKey && selectedEntities.length === 1) { // if reselecting the same entity then start renaming it if (selectedEntities[0] === entityID) { - startRenamingEntity(entityID); + if (renameLastBlur && renameLastEntityID === entityID && (Date.now() - renameLastBlur) < RENAME_COOLDOWN) { + + return; + } + clearRenameTimeout(); + renameTimeout = window.setTimeout(() => { + renameTimeout = null; + startRenamingEntity(entityID); + }, DOUBLE_CLICK_TIMEOUT); } } @@ -530,6 +591,8 @@ function loaded() { } function onRowDoubleClicked() { + clearRenameTimeout(); + let selection = [this.dataset.entityID]; updateSelectedEntities(selection, false); @@ -1149,7 +1212,7 @@ function loaded() { } } } - } + }; document.onmouseup = function(event) { if (elTargetTh) { @@ -1180,7 +1243,8 @@ function loaded() { }; document.addEventListener("keyup", function (keyUpEvent) { - if (keyUpEvent.target.nodeName === "INPUT") { + const FILTERED_NODE_NAMES = ["INPUT", "TEXTAREA"]; + if (FILTERED_NODE_NAMES.includes(keyUpEvent.target.nodeName)) { return; } @@ -1276,7 +1340,7 @@ function loaded() { refreshSortOrder(); refreshEntities(); - window.onresize = updateColumnWidths; + window.addEventListener("resize", updateColumnWidths); }); augmentSpinButtons(); diff --git a/scripts/system/html/js/entityProperties.js b/scripts/system/html/js/entityProperties.js index c49e0d88f6..dc304c6803 100644 --- a/scripts/system/html/js/entityProperties.js +++ b/scripts/system/html/js/entityProperties.js @@ -29,7 +29,7 @@ const ICON_FOR_TYPE = { const DEGREES_TO_RADIANS = Math.PI / 180.0; -const NO_SELECTION = "w"; +const NO_SELECTION = ","; const PROPERTY_SPACE_MODE = { ALL: 0, @@ -197,7 +197,7 @@ const GROUPS = [ multiplier: DEGREES_TO_RADIANS, decimals: 2, unit: "deg", - propertyID: "keyLight.direction.x", + propertyID: "keyLight.direction.y", showPropertyRule: { "keyLightMode": "enabled" }, }, { @@ -206,7 +206,7 @@ const GROUPS = [ multiplier: DEGREES_TO_RADIANS, decimals: 2, unit: "deg", - propertyID: "keyLight.direction.y", + propertyID: "keyLight.direction.x", showPropertyRule: { "keyLightMode": "enabled" }, }, { @@ -579,6 +579,14 @@ const GROUPS = [ min: 0, propertyID: "priority", }, + { + label: "Material Mapping Mode", + type: "dropdown", + options: { + uv: "UV space", projected: "3D projected" + }, + propertyID: "materialMappingMode", + }, { label: "Material Position", type: "vec2", @@ -608,6 +616,11 @@ const GROUPS = [ unit: "deg", propertyID: "materialMappingRot", }, + { + label: "Material Repeat", + type: "bool", + propertyID: "materialRepeat", + }, ] }, { @@ -882,7 +895,7 @@ const GROUPS = [ properties: [ { type: "triple", - label: "Alpha", + label: "Spin", properties: [ { label: "Start", @@ -951,8 +964,8 @@ const GROUPS = [ { label: "Start", type: "number", - min: -180, - max: 0, + min: 0, + max: 180, step: 1, decimals: 0, multiplier: DEGREES_TO_RADIANS, @@ -979,7 +992,7 @@ const GROUPS = [ { label: "Start", type: "number", - min: 0, + min: -180, max: 180, step: 1, decimals: 0, @@ -990,7 +1003,7 @@ const GROUPS = [ { label: "Finish", type: "number", - min: 0, + min: -180, max: 180, step: 1, decimals: 0, @@ -1158,18 +1171,21 @@ const GROUPS = [ label: "Link", type: "string", propertyID: "href", + placeholder: "URL", }, { label: "Script", type: "string", buttons: [ { id: "reload", label: "F", className: "glyph", onClick: reloadScripts } ], propertyID: "script", + placeholder: "URL", }, { label: "Server Script", type: "string", buttons: [ { id: "reload", label: "F", className: "glyph", onClick: reloadServerScripts } ], propertyID: "serverScripts", + placeholder: "URL", }, { label: "Server Script Status", @@ -1179,7 +1195,7 @@ const GROUPS = [ }, { label: "Lifetime", - type: "number", + type: "string", unit: "s", propertyID: "lifetime", }, @@ -1244,8 +1260,9 @@ const GROUPS = [ showPropertyRule: { "collisionless": "false" }, }, { - label: "Collision sound URL", + label: "Collision Sound", type: "string", + placeholder: "URL", propertyID: "collisionSoundURL", showPropertyRule: { "collisionless": "false" }, }, @@ -1366,6 +1383,7 @@ const GROUPS_PER_TYPE = { }; const EDITOR_TIMEOUT_DURATION = 1500; +const IMAGE_DEBOUNCE_TIMEOUT = 250; const DEBOUNCE_TIMEOUT = 125; const COLOR_MIN = 0; @@ -1500,7 +1518,7 @@ function disableProperties() { function showPropertyElement(propertyID, show) { let elProperty = properties[propertyID].elContainer; - elProperty.style.display = show ? "flex" : "none"; + elProperty.style.display = show ? "" : "none"; } function resetProperties() { @@ -1622,10 +1640,11 @@ function updateVisibleSpaceModeProperties() { if (properties.hasOwnProperty(propertyID)) { let property = properties[propertyID]; let propertySpaceMode = property.spaceMode; - if (propertySpaceMode !== PROPERTY_SPACE_MODE.ALL) { - showPropertyElement(propertyID, propertySpaceMode === currentSpaceMode); + let elProperty = properties[propertyID].elContainer; + if (propertySpaceMode !== PROPERTY_SPACE_MODE.ALL && propertySpaceMode !== currentSpaceMode) { + elProperty.classList.add('spacemode-hidden'); } else { - showPropertyElement(propertyID, true); + elProperty.classList.remove('spacemode-hidden'); } } } @@ -1662,7 +1681,11 @@ function updateProperty(originalPropertyName, propertyValue, isParticleProperty) }); particleSyncDebounce(); } else { - updateProperties(propertyUpdate); + // only update the entity property value itself if in the middle of dragging + // prevent undo command push, saving new property values, and property update + // callback until drag is complete (additional update sent via dragEnd callback) + let onlyUpdateEntity = properties[originalPropertyName] && properties[originalPropertyName].dragging === true; + updateProperties(propertyUpdate, onlyUpdateEntity); } } @@ -1671,66 +1694,88 @@ var particleSyncDebounce = _.debounce(function () { particlePropertyUpdates = {}; }, DEBOUNCE_TIMEOUT); -function updateProperties(propertiesToUpdate) { +function updateProperties(propertiesToUpdate, onlyUpdateEntity) { + if (onlyUpdateEntity === undefined) { + onlyUpdateEntity = false; + } EventBridge.emitWebEvent(JSON.stringify({ id: lastEntityID, type: "update", - properties: propertiesToUpdate + properties: propertiesToUpdate, + onlyUpdateEntities: onlyUpdateEntity })); } -function createEmitTextPropertyUpdateFunction(propertyName, isParticleProperty) { +function createEmitTextPropertyUpdateFunction(property) { return function() { - updateProperty(propertyName, this.value, isParticleProperty); + updateProperty(property.name, this.value, property.isParticleProperty); }; } -function createEmitCheckedPropertyUpdateFunction(propertyName, inverse, isParticleProperty) { +function createEmitCheckedPropertyUpdateFunction(property) { return function() { - updateProperty(propertyName, inverse ? !this.checked : this.checked, isParticleProperty); + updateProperty(property.name, property.data.inverse ? !this.checked : this.checked, property.isParticleProperty); }; } -function createEmitNumberPropertyUpdateFunction(propertyName, multiplier, isParticleProperty) { +function createDragStartFunction(property) { return function() { + property.dragging = true; + }; +} + +function createDragEndFunction(property) { + return function() { + property.dragging = false; + // send an additonal update post-dragging to consider whole property change from dragStart to dragEnd to be 1 action + this.valueChangeFunction(); + }; +} + +function createEmitNumberPropertyUpdateFunction(property) { + return function() { + let multiplier = property.data.multiplier; if (multiplier === undefined) { multiplier = 1; } let value = parseFloat(this.value) * multiplier; - updateProperty(propertyName, value, isParticleProperty); + updateProperty(property.name, value, property.isParticleProperty); }; } -function createEmitVec2PropertyUpdateFunction(propertyName, elX, elY, multiplier, isParticleProperty) { +function createEmitVec2PropertyUpdateFunction(property) { return function () { + let multiplier = property.data.multiplier; if (multiplier === undefined) { multiplier = 1; } let newValue = { - x: elX.value * multiplier, - y: elY.value * multiplier + x: property.elNumberX.elInput.value * multiplier, + y: property.elNumberY.elInput.value * multiplier }; - updateProperty(propertyName, newValue, isParticleProperty); + updateProperty(property.name, newValue, property.isParticleProperty); }; } -function createEmitVec3PropertyUpdateFunction(propertyName, elX, elY, elZ, multiplier, isParticleProperty) { +function createEmitVec3PropertyUpdateFunction(property) { return function() { + let multiplier = property.data.multiplier; if (multiplier === undefined) { multiplier = 1; } let newValue = { - x: elX.value * multiplier, - y: elY.value * multiplier, - z: elZ.value * multiplier + x: property.elNumberX.elInput.value * multiplier, + y: property.elNumberY.elInput.value * multiplier, + z: property.elNumberZ.elInput.value * multiplier }; - updateProperty(propertyName, newValue, isParticleProperty); + updateProperty(property.name, newValue, property.isParticleProperty); }; } -function createEmitColorPropertyUpdateFunction(propertyName, elRed, elGreen, elBlue, isParticleProperty) { +function createEmitColorPropertyUpdateFunction(property) { return function() { - emitColorPropertyUpdate(propertyName, elRed.value, elGreen.value, elBlue.value, isParticleProperty); + emitColorPropertyUpdate(property.name, property.elNumberR.elInput.value, property.elNumberG.elInput.value, + property.elNumberB.elInput.value, property.isParticleProperty); }; } @@ -1755,10 +1800,10 @@ function updateCheckedSubProperty(propertyName, propertyValue, subPropertyElemen updateProperty(propertyName, propertyValue, isParticleProperty); } -function createImageURLUpdateFunction(propertyName, isParticleProperty) { +function createImageURLUpdateFunction(property) { return function () { let newTextures = JSON.stringify({ "tex.picture": this.value }); - updateProperty(propertyName, newTextures, isParticleProperty); + updateProperty(property.name, newTextures, property.isParticleProperty); }; } @@ -1768,7 +1813,6 @@ function createImageURLUpdateFunction(propertyName, isParticleProperty) { */ function createStringProperty(property, elProperty) { - let propertyName = property.name; let elementID = property.elementID; let propertyData = property.data; @@ -1782,7 +1826,7 @@ function createStringProperty(property, elProperty) { `) - elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(propertyName, property.isParticleProperty)); + elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property)); elProperty.appendChild(elInput); @@ -1821,59 +1865,54 @@ function createBoolProperty(property, elProperty) { elInput, propertyName, property.isParticleProperty); }); } else { - elInput.addEventListener('change', createEmitCheckedPropertyUpdateFunction(propertyName, propertyData.inverse, - property.isParticleProperty)); + elInput.addEventListener('change', createEmitCheckedPropertyUpdateFunction(property)); } return elInput; } function createNumberProperty(property, elProperty) { - let propertyName = property.name; let elementID = property.elementID; let propertyData = property.data; elProperty.className = "draggable-number"; - let elDraggableNumber = new DraggableNumber(propertyData.min, propertyData.max, - propertyData.step, propertyData.decimals); + let dragStartFunction = createDragStartFunction(property); + let dragEndFunction = createDragEndFunction(property); + let elDraggableNumber = new DraggableNumber(propertyData.min, propertyData.max, propertyData.step, + propertyData.decimals, dragStartFunction, dragEndFunction); let defaultValue = propertyData.defaultValue; if (defaultValue !== undefined) { elDraggableNumber.elInput.value = defaultValue; } - let valueChangeFunction = createEmitNumberPropertyUpdateFunction(propertyName, propertyData.multiplier, - property.isParticleProperty); + let valueChangeFunction = createEmitNumberPropertyUpdateFunction(property); elDraggableNumber.setValueChangeFunction(valueChangeFunction); elDraggableNumber.elInput.setAttribute("id", elementID); elProperty.appendChild(elDraggableNumber.elDiv); if (propertyData.buttons !== undefined) { - addButtons(elDraggableNumber.elText, elementID, propertyData.buttons, false); + addButtons(elDraggableNumber.elDiv, elementID, propertyData.buttons, false); } return elDraggableNumber; } function createVec3Property(property, elProperty) { - let propertyName = property.name; - let elementID = property.elementID; let propertyData = property.data; elProperty.className = propertyData.vec3Type + " fstuple"; - let elNumberX = createTupleNumberInput(elProperty, elementID, propertyData.subLabels[VECTOR_ELEMENTS.X_NUMBER], - propertyData.min, propertyData.max, propertyData.step, propertyData.decimals); - let elNumberY = createTupleNumberInput(elProperty, elementID, propertyData.subLabels[VECTOR_ELEMENTS.Y_NUMBER], - propertyData.min, propertyData.max, propertyData.step, propertyData.decimals); - let elNumberZ = createTupleNumberInput(elProperty, elementID, propertyData.subLabels[VECTOR_ELEMENTS.Z_NUMBER], - propertyData.min, propertyData.max, propertyData.step, propertyData.decimals); + let elNumberX = createTupleNumberInput(property, propertyData.subLabels[VECTOR_ELEMENTS.X_NUMBER]); + let elNumberY = createTupleNumberInput(property, propertyData.subLabels[VECTOR_ELEMENTS.Y_NUMBER]); + let elNumberZ = createTupleNumberInput(property, propertyData.subLabels[VECTOR_ELEMENTS.Z_NUMBER]); + elProperty.appendChild(elNumberX.elDiv); + elProperty.appendChild(elNumberY.elDiv); + elProperty.appendChild(elNumberZ.elDiv); - let valueChangeFunction = createEmitVec3PropertyUpdateFunction(propertyName, elNumberX.elInput, elNumberY.elInput, - elNumberZ.elInput, propertyData.multiplier, - property.isParticleProperty); + let valueChangeFunction = createEmitVec3PropertyUpdateFunction(property); elNumberX.setValueChangeFunction(valueChangeFunction); elNumberY.setValueChangeFunction(valueChangeFunction); elNumberZ.setValueChangeFunction(valueChangeFunction); @@ -1886,8 +1925,6 @@ function createVec3Property(property, elProperty) { } function createVec2Property(property, elProperty) { - let propertyName = property.name; - let elementID = property.elementID; let propertyData = property.data; elProperty.className = propertyData.vec2Type + " fstuple"; @@ -1897,13 +1934,12 @@ function createVec2Property(property, elProperty) { elProperty.appendChild(elTuple); - let elNumberX = createTupleNumberInput(elProperty, elementID, propertyData.subLabels[VECTOR_ELEMENTS.X_NUMBER], - propertyData.min, propertyData.max, propertyData.step, propertyData.decimals); - let elNumberY = createTupleNumberInput(elProperty, elementID, propertyData.subLabels[VECTOR_ELEMENTS.Y_NUMBER], - propertyData.min, propertyData.max, propertyData.step, propertyData.decimals); + let elNumberX = createTupleNumberInput(property, propertyData.subLabels[VECTOR_ELEMENTS.X_NUMBER]); + let elNumberY = createTupleNumberInput(property, propertyData.subLabels[VECTOR_ELEMENTS.Y_NUMBER]); + elProperty.appendChild(elNumberX.elDiv); + elProperty.appendChild(elNumberY.elDiv); - let valueChangeFunction = createEmitVec2PropertyUpdateFunction(propertyName, elNumberX.elInput, elNumberY.elInput, - propertyData.multiplier, property.isParticleProperty); + let valueChangeFunction = createEmitVec2PropertyUpdateFunction(property); elNumberX.setValueChangeFunction(valueChangeFunction); elNumberY.setValueChangeFunction(valueChangeFunction); @@ -1916,6 +1952,7 @@ function createVec2Property(property, elProperty) { function createColorProperty(property, elProperty) { let propertyName = property.name; let elementID = property.elementID; + let propertyData = property.data; elProperty.className = "rgb fstuple"; @@ -1929,12 +1966,24 @@ function createColorProperty(property, elProperty) { elProperty.appendChild(elColorPicker); elProperty.appendChild(elTuple); - let elNumberR = createTupleNumberInput(elTuple, elementID, "red", COLOR_MIN, COLOR_MAX, COLOR_STEP); - let elNumberG = createTupleNumberInput(elTuple, elementID, "green", COLOR_MIN, COLOR_MAX, COLOR_STEP); - let elNumberB = createTupleNumberInput(elTuple, elementID, "blue", COLOR_MIN, COLOR_MAX, COLOR_STEP); + if (propertyData.min === undefined) { + propertyData.min = COLOR_MIN; + } + if (propertyData.max === undefined) { + propertyData.max = COLOR_MAX; + } + if (propertyData.step === undefined) { + propertyData.step = COLOR_STEP; + } - let valueChangeFunction = createEmitColorPropertyUpdateFunction(propertyName, elNumberR.elInput, elNumberG.elInput, - elNumberB.elInput, property.isParticleProperty); + let elNumberR = createTupleNumberInput(property, "red"); + let elNumberG = createTupleNumberInput(property, "green"); + let elNumberB = createTupleNumberInput(property, "blue"); + elTuple.appendChild(elNumberR.elDiv); + elTuple.appendChild(elNumberG.elDiv); + elTuple.appendChild(elNumberB.elDiv); + + let valueChangeFunction = createEmitColorPropertyUpdateFunction(property); elNumberR.setValueChangeFunction(valueChangeFunction); elNumberG.setValueChangeFunction(valueChangeFunction); elNumberB.setValueChangeFunction(valueChangeFunction); @@ -1973,7 +2022,6 @@ function createColorProperty(property, elProperty) { } function createDropdownProperty(property, propertyID, elProperty) { - let propertyName = property.name; let elementID = property.elementID; let propertyData = property.data; @@ -1990,7 +2038,7 @@ function createDropdownProperty(property, propertyID, elProperty) { elInput.add(option); } - elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(propertyName, property.isParticleProperty)); + elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property)); elProperty.appendChild(elInput); @@ -1998,7 +2046,6 @@ function createDropdownProperty(property, propertyID, elProperty) { } function createTextareaProperty(property, elProperty) { - let propertyName = property.name; let elementID = property.elementID; let propertyData = property.data; @@ -2010,7 +2057,7 @@ function createTextareaProperty(property, elProperty) { elInput.readOnly = true; } - elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(propertyName, property.isParticleProperty)); + elInput.addEventListener('change', createEmitTextPropertyUpdateFunction(property)); elProperty.appendChild(elInput); @@ -2070,7 +2117,7 @@ function createTextureProperty(property, elProperty) { elDiv.classList.remove("no-preview"); elDiv.classList.add("no-texture"); } - }, DEBOUNCE_TIMEOUT * 2); + }, IMAGE_DEBOUNCE_TIMEOUT); elInput.imageLoad = imageLoad; elInput.oninput = function (event) { // Add throttle @@ -2102,7 +2149,9 @@ function createButtonsProperty(property, elProperty, elLabel) { return elProperty; } -function createTupleNumberInput(elTuple, propertyElementID, subLabel, min, max, step, decimals) { +function createTupleNumberInput(property, subLabel) { + let propertyElementID = property.elementID; + let propertyData = property.data; let elementID = propertyElementID + "-" + subLabel.toLowerCase(); let elLabel = document.createElement('label'); @@ -2111,11 +2160,13 @@ function createTupleNumberInput(elTuple, propertyElementID, subLabel, min, max, elLabel.setAttribute("for", elementID); elLabel.style.visibility = "visible"; - let elDraggableNumber = new DraggableNumber(min, max, step, decimals); + let dragStartFunction = createDragStartFunction(property); + let dragEndFunction = createDragEndFunction(property); + let elDraggableNumber = new DraggableNumber(propertyData.min, propertyData.max, propertyData.step, + propertyData.decimals, dragStartFunction, dragEndFunction); elDraggableNumber.elInput.setAttribute("id", elementID); elDraggableNumber.elDiv.className += " fstuple"; - elDraggableNumber.elText.insertBefore(elLabel, elDraggableNumber.elLeftArrow); - elTuple.appendChild(elDraggableNumber.elDiv); + elDraggableNumber.elDiv.insertBefore(elLabel, elDraggableNumber.elLeftArrow); return elDraggableNumber; } @@ -2388,7 +2439,7 @@ function multiDataUpdater(groupName, updateKeyPair, userDataElement, defaults, r userDataElement.value = propertyUpdate.userData; - updateProperties(propertyUpdate); + updateProperties(propertyUpdate, false); } var editor = null; @@ -2769,7 +2820,7 @@ function loaded() { elLegend.appendChild(createElementFromHTML(`
    ${group.label}
    `)); let elSpan = document.createElement('span'); - elSpan.className = ".collapse-icon"; + elSpan.className = "collapse-icon"; elSpan.innerText = "M"; elLegend.appendChild(elSpan); elGroup.appendChild(elLegend); @@ -3306,17 +3357,17 @@ function loaded() { } }); - getPropertyInputElement("image").addEventListener('change', createImageURLUpdateFunction('textures', false)); + getPropertyInputElement("image").addEventListener('change', createImageURLUpdateFunction(properties['textures'])); // Collapsible sections - let elCollapsible = document.getElementsByClassName("section-header"); + let elCollapsible = document.getElementsByClassName("collapse-icon"); let toggleCollapsedEvent = function(event) { - let element = this.parentNode; + let element = this.parentNode.parentNode; let isCollapsed = element.dataset.collapsed !== "true"; element.dataset.collapsed = isCollapsed ? "true" : false; element.setAttribute("collapsed", isCollapsed ? "true" : "false"); - element.getElementsByClassName(".collapse-icon")[0].textContent = isCollapsed ? "L" : "M"; + this.textContent = isCollapsed ? "L" : "M"; }; for (let collapseIndex = 0, numCollapsibles = elCollapsible.length; collapseIndex < numCollapsibles; ++collapseIndex) { @@ -3401,7 +3452,7 @@ function loaded() { let propertyID = elDropdown.getAttribute("propertyID"); let property = properties[propertyID]; property.elInput = dt; - dt.addEventListener('change', createEmitTextPropertyUpdateFunction(property.name, property.isParticleProperty)); + dt.addEventListener('change', createEmitTextPropertyUpdateFunction(property)); } elDropdowns = document.getElementsByTagName("select"); @@ -3417,7 +3468,8 @@ function loaded() { }; document.addEventListener("keyup", function (keyUpEvent) { - if (keyUpEvent.target.nodeName === "INPUT") { + const FILTERED_NODE_NAMES = ["INPUT", "TEXTAREA"]; + if (FILTERED_NODE_NAMES.includes(keyUpEvent.target.nodeName)) { return; } let {code, key, keyCode, altKey, ctrlKey, metaKey, shiftKey} = keyUpEvent; diff --git a/scripts/system/html/js/gridControls.js b/scripts/system/html/js/gridControls.js index 70e91071fb..3e5bfa1e2f 100644 --- a/scripts/system/html/js/gridControls.js +++ b/scripts/system/html/js/gridControls.js @@ -83,44 +83,26 @@ function loaded() { var gridColor = { red: 255, green: 255, blue: 255 }; var elColor = document.getElementById("grid-color"); - var elColorRed = document.getElementById("grid-color-red"); - var elColorGreen = document.getElementById("grid-color-green"); - var elColorBlue = document.getElementById("grid-color-blue"); elColor.style.backgroundColor = "rgb(" + gridColor.red + "," + gridColor.green + "," + gridColor.blue + ")"; - elColorRed.value = gridColor.red; - elColorGreen.value = gridColor.green; - elColorBlue.value = gridColor.blue; - - var colorChangeFunction = function () { - gridColor = { red: elColorRed.value, green: elColorGreen.value, blue: elColorBlue.value }; - elColor.style.backgroundColor = "rgb(" + gridColor.red + "," + gridColor.green + "," + gridColor.blue + ")"; - emitUpdate(); - }; var colorPickFunction = function (red, green, blue) { - elColorRed.value = red; - elColorGreen.value = green; - elColorBlue.value = blue; gridColor = { red: red, green: green, blue: blue }; emitUpdate(); }; - elColorRed.addEventListener('change', colorChangeFunction); - elColorGreen.addEventListener('change', colorChangeFunction); - elColorBlue.addEventListener('change', colorChangeFunction); $('#grid-color').colpick({ colorScheme: 'dark', - layout: 'hex', + layout: 'rgbhex', color: { r: gridColor.red, g: gridColor.green, b: gridColor.blue }, + submit: false, onShow: function (colpick) { $('#grid-color').attr('active', 'true'); }, onHide: function (colpick) { $('#grid-color').attr('active', 'false'); }, - onSubmit: function (hsb, hex, rgb, el) { + onChange: function (hsb, hex, rgb, el) { $(el).css('background-color', '#' + hex); - $(el).colpickHide(); colorPickFunction(rgb.r, rgb.g, rgb.b); } }); @@ -136,7 +118,8 @@ function loaded() { }; document.addEventListener("keyup", function (keyUpEvent) { - if (keyUpEvent.target.nodeName === "INPUT") { + const FILTERED_NODE_NAMES = ["INPUT", "TEXTAREA"]; + if (FILTERED_NODE_NAMES.includes(keyUpEvent.target.nodeName)) { return; } let {code, key, keyCode, altKey, ctrlKey, metaKey, shiftKey} = keyUpEvent; diff --git a/scripts/system/html/js/listView.js b/scripts/system/html/js/listView.js index 07aba53f1c..49a91388a5 100644 --- a/scripts/system/html/js/listView.js +++ b/scripts/system/html/js/listView.js @@ -13,8 +13,8 @@ debugPrint = function (message) { console.log(message); }; -function ListView(elTableBody, elTableScroll, elTableHeaderRow, createRowFunction, - updateRowFunction, clearRowFunction, WINDOW_NONVARIABLE_HEIGHT) { +function ListView(elTableBody, elTableScroll, elTableHeaderRow, createRowFunction, updateRowFunction, clearRowFunction, + preRefreshFunction, postRefreshFunction, preResizeFunction, WINDOW_NONVARIABLE_HEIGHT) { this.elTableBody = elTableBody; this.elTableScroll = elTableScroll; this.elTableHeaderRow = elTableHeaderRow; @@ -25,6 +25,9 @@ function ListView(elTableBody, elTableScroll, elTableHeaderRow, createRowFunctio this.createRowFunction = createRowFunction; this.updateRowFunction = updateRowFunction; this.clearRowFunction = clearRowFunction; + this.preRefreshFunction = preRefreshFunction; + this.postRefreshFunction = postRefreshFunction; + this.preResizeFunction = preResizeFunction; // the list of row elements created in the table up to max viewable height plus SCROLL_ROWS rows for scrolling buffer this.elRows = []; @@ -72,11 +75,6 @@ ListView.prototype = { } }, - onScroll: function() { - var that = this.listView; - that.scroll(); - }, - scroll: function() { let scrollTop = this.elTableScroll.scrollTop; let scrollHeight = this.getScrollHeight(); @@ -178,6 +176,7 @@ ListView.prototype = { }, refresh: function() { + this.preRefreshFunction(); // block refreshing before rows are initialized let numRows = this.getNumRows(); if (numRows === 0) { @@ -216,6 +215,7 @@ ListView.prototype = { this.lastRowShiftScrollTop = 0; } } + this.postRefreshFunction(); }, refreshBuffers: function() { @@ -235,7 +235,7 @@ ListView.prototype = { refreshRowOffset: function() { // make sure the row offset isn't causing visible rows to pass the end of the item list and is clamped to 0 - var numRows = this.getNumRows(); + let numRows = this.getNumRows(); if (this.rowOffset + numRows > this.itemData.length) { this.rowOffset = this.itemData.length - numRows; } @@ -244,18 +244,13 @@ ListView.prototype = { } }, - onResize: function() { - var that = this.listView; - that.resize(); - }, - resize: function() { if (!this.elTableBody || !this.elTableScroll) { debugPrint("ListView.resize - no valid table body or table scroll element"); return; } - - let prevScrollTop = this.elTableScroll.scrollTop; + this.preResizeFunction(); + let prevScrollTop = this.elTableScroll.scrollTop; // take up available window space this.elTableScroll.style.height = window.innerHeight - WINDOW_NONVARIABLE_HEIGHT; @@ -305,10 +300,10 @@ ListView.prototype = { this.elTableBody.appendChild(this.elBottomBuffer); this.elBottomBuffer.setAttribute("height", 0); - this.elTableScroll.listView = this; - this.elTableScroll.onscroll = this.onScroll; - window.listView = this; - window.onresize = this.onResize; + this.onScroll = this.scroll.bind(this); + this.elTableScroll.addEventListener("scroll", this.onScroll); + this.onResize = this.resize.bind(this); + window.addEventListener("resize", this.onResize); // initialize all row elements this.resize(); diff --git a/scripts/system/html/js/marketplacesInject.js b/scripts/system/html/js/marketplacesInject.js index 1bfa9d4b20..e3da1c2577 100644 --- a/scripts/system/html/js/marketplacesInject.js +++ b/scripts/system/html/js/marketplacesInject.js @@ -219,17 +219,12 @@ }); } - function buyButtonClicked(id, name, author, price, href, referrer, edition, type) { + function buyButtonClicked(id, referrer, edition) { EventBridge.emitWebEvent(JSON.stringify({ type: "CHECKOUT", itemId: id, - itemName: name, - itemPrice: price ? parseInt(price, 10) : 0, - itemHref: href, referrer: referrer, - itemAuthor: author, - itemEdition: edition, - itemType: type.trim() + itemEdition: edition })); } @@ -313,13 +308,8 @@ return false; } buyButtonClicked($(this).closest('.grid-item').attr('data-item-id'), - $(this).closest('.grid-item').find('.item-title').text(), - $(this).closest('.grid-item').find('.creator').find('.value').text(), - $(this).closest('.grid-item').find('.item-cost').text(), - $(this).attr('data-href'), "mainPage", - -1, - $(this).closest('.grid-item').find('.item-type').text()); + -1); }); } @@ -427,13 +417,8 @@ purchaseButton.on('click', function () { if ('available' === availability || isUpdating) { buyButtonClicked(window.location.pathname.split("/")[3], - $('#top-center').find('h1').text(), - $('#creator').find('.value').text(), - cost, - href, "itemPage", - urlParams.get('edition'), - type); + urlParams.get('edition')); } }); } diff --git a/scripts/system/interstitialPage.js b/scripts/system/interstitialPage.js index b7c5809b3a..e4dc778985 100644 --- a/scripts/system/interstitialPage.js +++ b/scripts/system/interstitialPage.js @@ -197,7 +197,7 @@ var loadingBarProgress = Overlays.addOverlay("image3d", { name: "Loading-Bar-Progress", - localPosition: { x: 0.0, y: -0.86, z: 0.0 }, + localPosition: { x: 0.0, y: -0.91, z: 0.0 }, url: LOADING_BAR_PROGRESS, alpha: 1, dimensions: { x: TOTAL_LOADING_PROGRESS, y: 0.3}, @@ -274,6 +274,7 @@ previousCameraMode = Camera.mode; Camera.mode = "first person"; updateProgressBar(0.0); + scaleInterstitialPage(MyAvatar.sensorToWorldScale); timer = Script.setTimeout(update, 2000); } } @@ -482,7 +483,7 @@ var end = 0; var xLocalPosition = (progressPercentage * (end - start)) + start; var properties = { - localPosition: { x: xLocalPosition, y: -0.93, z: 0.0 }, + localPosition: { x: xLocalPosition, y: (HMD.active ? -0.93 : -0.91), z: 0.0 }, dimensions: { x: progress, y: 0.3 diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index e9d5255d28..ab2801087e 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -53,6 +53,7 @@ TEAR_AWAY_DISTANCE:true, TEAR_AWAY_COUNT:true, TEAR_AWAY_CHECK_TIME:true, + NEAR_GRAB_DISTANCE: true, distanceBetweenPointAndEntityBoundingBox:true, entityIsEquipped:true, entityIsFarGrabbedByOther:true, @@ -99,6 +100,10 @@ NEAR_GRAB_RADIUS = 1.0; TEAR_AWAY_DISTANCE = 0.15; // ungrab an entity if its bounding-box moves this far from the hand TEAR_AWAY_COUNT = 2; // multiply by TEAR_AWAY_CHECK_TIME to know how long the item must be away TEAR_AWAY_CHECK_TIME = 0.15; // seconds, duration between checks + +NEAR_GRAB_DISTANCE = 0.14; // Grab an entity if its bounding box is within this distance. +// Smaller than TEAR_AWAY_DISTANCE for hysteresis. + DISPATCHER_HOVERING_LIST = "dispactherHoveringList"; DISPATCHER_HOVERING_STYLE = { isOutlineSmooth: true, diff --git a/scripts/system/libraries/entityList.js b/scripts/system/libraries/entityList.js index 8942c84f33..eeb16fd60d 100644 --- a/scripts/system/libraries/entityList.js +++ b/scripts/system/libraries/entityList.js @@ -17,7 +17,7 @@ var profileIndent = ''; const PROFILE_NOOP = function(_name, fn, args) { fn.apply(this, args); }; -PROFILE = !PROFILING_ENABLED ? PROFILE_NOOP : function(name, fn, args) { +const PROFILE = !PROFILING_ENABLED ? PROFILE_NOOP : function(name, fn, args) { console.log("PROFILE-Script " + profileIndent + "(" + name + ") Begin"); var previousIndent = profileIndent; profileIndent += ' '; diff --git a/scripts/system/makeUserConnection.js b/scripts/system/makeUserConnection.js index d205d368dd..4b59f050c9 100644 --- a/scripts/system/makeUserConnection.js +++ b/scripts/system/makeUserConnection.js @@ -229,6 +229,15 @@ } animationData.rightHandRotation = Quat.fromPitchYawRollDegrees(90, 0, 90); animationData.rightHandType = 0; // RotationAndPosition, see IKTargets.h + + // turn on the right hand grip overlay + animationData.rightHandOverlayAlpha = 1.0; + + // make sure the right hand grip animation is the "grasp", not pointing or thumbs up. + animationData.isRightHandGrasp = true; + animationData.isRightIndexPoint = false; + animationData.isRightThumbRaise = false; + animationData.isRightIndexPointAndThumbRaise = false; } function shakeHandsAnimation() { return animationData; diff --git a/scripts/system/marketplaces/marketplaces.js b/scripts/system/marketplaces/marketplaces.js index be25d1265f..e4891a9bae 100644 --- a/scripts/system/marketplaces/marketplaces.js +++ b/scripts/system/marketplaces/marketplaces.js @@ -471,7 +471,7 @@ function onWebEventReceived(message) { wireQmlEventBridge(true); ui.open(MARKETPLACE_CHECKOUT_QML_PATH); ui.tablet.sendToQml({ - method: 'updateCheckoutQML', + method: 'updateCheckoutQMLItemID', params: message }); } else if (message.type === "REQUEST_SETTING") { @@ -649,8 +649,8 @@ var onQmlMessageReceived = function onQmlMessageReceived(message) { case 'purchases_openGoTo': case 'purchases_itemInfoClicked': case 'purchases_itemCertificateClicked': - case 'clearShouldShowDotHistory': - case 'giftAsset': + case 'clearShouldShowDotHistory': + case 'giftAsset': break; default: print('marketplaces.js: Unrecognized message from Checkout.qml'); diff --git a/tests-manual/gpu/src/TestFbx.cpp b/tests-manual/gpu/src/TestFbx.cpp index 9253f8bc91..d3eab9e8e3 100644 --- a/tests-manual/gpu/src/TestFbx.cpp +++ b/tests-manual/gpu/src/TestFbx.cpp @@ -12,7 +12,7 @@ #include -#include +#include struct MyVertex { vec3 position; @@ -100,7 +100,7 @@ bool TestFbx::isReady() const { void TestFbx::parseFbx(const QByteArray& fbxData) { QVariantHash mapping; - HFMModel* hfmModel = readFBX(fbxData, mapping); + HFMModel::Pointer hfmModel = FBXSerializer().read(fbxData, mapping); size_t totalVertexCount = 0; size_t totalIndexCount = 0; size_t totalPartCount = 0; @@ -163,7 +163,6 @@ void TestFbx::parseFbx(const QByteArray& fbxData) { _vertexBuffer->append(vertices); _indexBuffer->append(indices); _indirectBuffer->append(parts); - delete hfmModel; } void TestFbx::renderTest(size_t testId, RenderArgs* args) { diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 6ec9125ce8..ddf9a7b373 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -31,6 +31,6 @@ if (BUILD_TOOLS) add_subdirectory(oven) set_target_properties(oven PROPERTIES FOLDER "Tools") - add_subdirectory(auto-tester) - set_target_properties(auto-tester PROPERTIES FOLDER "Tools") + add_subdirectory(nitpick) + set_target_properties(nitpick PROPERTIES FOLDER "Tools") endif() diff --git a/tools/auto-tester/AppDataHighFidelity/Interface/AccountInfo.bin b/tools/auto-tester/AppDataHighFidelity/Interface/AccountInfo.bin deleted file mode 100644 index 65c971ea79..0000000000 Binary files a/tools/auto-tester/AppDataHighFidelity/Interface/AccountInfo.bin and /dev/null differ diff --git a/tools/auto-tester/AppDataHighFidelity/domain-server/AccountInfo.bin b/tools/auto-tester/AppDataHighFidelity/domain-server/AccountInfo.bin deleted file mode 100644 index 645e34895e..0000000000 Binary files a/tools/auto-tester/AppDataHighFidelity/domain-server/AccountInfo.bin and /dev/null differ diff --git a/tools/dissectors/1-hfudt.lua b/tools/dissectors/1-hfudt.lua index 9ad89462f9..3993b2d7a0 100644 --- a/tools/dissectors/1-hfudt.lua +++ b/tools/dissectors/1-hfudt.lua @@ -39,9 +39,9 @@ p_hfudt.fields = { local control_types = { [0] = { "ACK", "Acknowledgement" }, - [5] = { "Handshake", "Handshake" }, - [6] = { "HandshakeACK", "Acknowledgement of Handshake" }, - [8] = { "HandshakeRequest", "Request a Handshake" } + [1] = { "Handshake", "Handshake" }, + [2] = { "HandshakeACK", "Acknowledgement of Handshake" }, + [3] = { "HandshakeRequest", "Request a Handshake" } } local message_positions = { diff --git a/tools/auto-tester/AppDataHighFidelity/Interface.json b/tools/nitpick/AppDataHighFidelity/Interface.json similarity index 100% rename from tools/auto-tester/AppDataHighFidelity/Interface.json rename to tools/nitpick/AppDataHighFidelity/Interface.json diff --git a/tools/auto-tester/AppDataHighFidelity/Interface/avatarbookmarks.json b/tools/nitpick/AppDataHighFidelity/Interface/avatarbookmarks.json similarity index 100% rename from tools/auto-tester/AppDataHighFidelity/Interface/avatarbookmarks.json rename to tools/nitpick/AppDataHighFidelity/Interface/avatarbookmarks.json diff --git a/tools/auto-tester/AppDataHighFidelity/assignment-client/entities/models.json.gz b/tools/nitpick/AppDataHighFidelity/assignment-client/entities/models.json.gz similarity index 100% rename from tools/auto-tester/AppDataHighFidelity/assignment-client/entities/models.json.gz rename to tools/nitpick/AppDataHighFidelity/assignment-client/entities/models.json.gz diff --git a/tools/auto-tester/AppDataHighFidelity/domain-server/config.json b/tools/nitpick/AppDataHighFidelity/domain-server/config.json similarity index 100% rename from tools/auto-tester/AppDataHighFidelity/domain-server/config.json rename to tools/nitpick/AppDataHighFidelity/domain-server/config.json diff --git a/tools/auto-tester/AppDataHighFidelity/domain-server/entities/models.json.gz b/tools/nitpick/AppDataHighFidelity/domain-server/entities/models.json.gz similarity index 100% rename from tools/auto-tester/AppDataHighFidelity/domain-server/entities/models.json.gz rename to tools/nitpick/AppDataHighFidelity/domain-server/entities/models.json.gz diff --git a/tools/auto-tester/CMakeLists.txt b/tools/nitpick/CMakeLists.txt similarity index 76% rename from tools/auto-tester/CMakeLists.txt rename to tools/nitpick/CMakeLists.txt index c8c0a336d2..efb5125f69 100644 --- a/tools/auto-tester/CMakeLists.txt +++ b/tools/nitpick/CMakeLists.txt @@ -1,4 +1,4 @@ -set (TARGET_NAME auto-tester) +set (TARGET_NAME nitpick) project(${TARGET_NAME}) # Automatically run UIC and MOC. This replaces the older WRAP macros @@ -22,7 +22,7 @@ set (QT_LIBRARIES Qt5::Core Qt5::Widgets QT::Gui Qt5::Xml) if (WIN32) # Do not show Console - set_property (TARGET auto-tester PROPERTY WIN32_EXECUTABLE true) + set_property (TARGET nitpick PROPERTY WIN32_EXECUTABLE true) endif() target_zlib() @@ -50,10 +50,12 @@ if (WIN32) ) # add a custom command to copy the empty Apps/Data High Fidelity folder (i.e. - a valid folder with no entities) + # this also copied to the containing folder, to facilitate running from Visual Studio add_custom_command( TARGET ${TARGET_NAME} POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/AppDataHighFidelity" "$/AppDataHighFidelity" + COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/AppDataHighFidelity" "AppDataHighFidelity" ) # add a custom command to copy the SSL DLLs @@ -62,5 +64,12 @@ if (WIN32) POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy_directory "$ENV{VCPKG_ROOT}/installed/x64-windows/bin" "$" ) +elseif (APPLE) + # add a custom command to copy the empty Apps/Data High Fidelity folder (i.e. - a valid folder with no entities) + add_custom_command( + TARGET ${TARGET_NAME} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/AppDataHighFidelity" "$/AppDataHighFidelity" + ) +endif () -endif () \ No newline at end of file diff --git a/tools/auto-tester/Create.PNG b/tools/nitpick/Create.PNG similarity index 100% rename from tools/auto-tester/Create.PNG rename to tools/nitpick/Create.PNG diff --git a/tools/auto-tester/Evaluate.PNG b/tools/nitpick/Evaluate.PNG similarity index 100% rename from tools/auto-tester/Evaluate.PNG rename to tools/nitpick/Evaluate.PNG diff --git a/tools/auto-tester/README.md b/tools/nitpick/README.md similarity index 65% rename from tools/auto-tester/README.md rename to tools/nitpick/README.md index e029955edc..7d75d660d7 100644 --- a/tools/auto-tester/README.md +++ b/tools/nitpick/README.md @@ -1,63 +1,112 @@ -# Auto Tester +# nitpick -The auto-tester is a stand alone application that provides a mechanism for regression testing. The general idea is simple: +Nitpick is a stand alone application that provides a mechanism for regression testing. The general idea is simple: * Each test folder has a script that produces a set of snapshots. * The snapshots are compared to a 'canonical' set of images that have been produced beforehand. * The result, if any test failed, is a zipped folder describing the failure. -Auto-tester has 5 functions, separated into 4 tabs: +Nitpick has 5 functions, separated into 4 tabs: 1. Creating tests, MD files and recursive scripts 1. Windows task bar utility (Windows only) 1. Running tests 1. Evaluating the results of running tests 1. Web interface -## Installation -### Executable -1. Download the installer by browsing to [here](). -2. Double click on the installer and install to a convenient location -![](./setup_7z.PNG) -3. To run the auto-tester, double click **auto-tester.exe**. -### Python -The TestRail interface requires Python 3 to be installed. Auto-Tester has been tested with Python 3.7.0 but should work with newer versions. - -Python 3 can be downloaded from: -1. Windows installer -2. Linux (source) (**Gzipped source tarball**) -3. Mac (**macOS 64-bit/32-bit installer** or **macOS 64-bit/32-bit installer**) - -After installation - create an environment variable called PYTHON_PATH and set it to the folder containing the Python executable. -### AWS interface +## Build (for developers) +Nitpick is built as part of the High Fidelity build. +### Creating installers #### Windows -1. Download the AWS CLI from `https://aws.amazon.com/cli/` -1. Install (installer is named `AWSCLI64PY3.msi`) -1. Open a new command prompt and run `aws configure` -1. Enter the AWS account number -1. Enter the secret key -1. Leave region name and ouput format as default [None] +1. Verify that 7Zip is installed. +1. cd to the `build\tools\nitpick\Release` directory +1. Delete any existing installers (named nitpick-installer-###.exe) +1. Select all, right-click and select 7-Zip->Add to archive... +1. Set Archive format to 7z +1. Check "Create SFX archive +1. Enter installer name (i.e. `nitpick-installer-v1.1.exe`) +1. Click "OK" +1. Copy created installer to https://hifi-qa.s3.amazonaws.com/nitpick/Windows/nitpick-installer-v1.1.exe: aws s3 cp nitpick-installer-v1.1.exe s3://hifi-qa/nitpick/Mac/nitpick-installer-v1.1.exe +#### Mac +These steps assume the hifi repository has been cloned to `~/hifi`. +1. (first time) Install brew + In a terminal: `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)` +1. (First time) install create-dmg: + In a terminal: `brew install create-dmg` +1. In a terminal: cd to the `build/tools/nitpick/Release` folder +1. Copy the quazip dynamic library (note final period): + In a terminal: `cp ~/hifi/build/ext/Xcode/quazip/project/lib/libquazip5.1.dylib .` +1. Change the loader instruction to find the dynamic library locally + In a terminal: `install_name_tool -change ~/hifi/build/ext/Xcode/quazip/project/lib/libquazip5.1.dylib libquazip5.1.dylib nitpick` +1. Delete any existing disk images. In a terminal: `rm *.dmg` +1. Create installer (note final period).In a terminal: `create-dmg --volname nitpick-installer-v1.1 nitpick-installer-v1.1.dmg .` + Make sure to wait for completion. +1. Copy created installer to AWS: `~/Library/Python/3.7/bin/aws s3 cp nitpick-installer-v1.1.dmg s3://hifi-qa/nitpick/Mac/nitpick-installer-v1.1.dmg` +### Installation +#### Windows +1. (First time) download and install vc_redist.x64.exe (available at https://hifi-qa.s3.amazonaws.com/nitpick/Windows/nitpick-installer-v1.1.exe) +1. (First time) download and install Python 3 from https://hifi-qa.s3.amazonaws.com/nitpick/Windows/python-3.7.0-amd64.exe (also located at https://www.python.org/downloads/) + 1. After installation - create an environment variable called PYTHON_PATH and set it to the folder containing the Python executable. +1. (First time) download and install AWS CLI from https://hifi-qa.s3.amazonaws.com/nitpick/Windows/AWSCLI64PY3.msi (also available at https://aws.amazon.com/cli/ + 1. Open a new command prompt and run `aws configure` + 1. Enter the AWS account number + 1. Enter the secret key + 1. Leave region name and ouput format as default [None] + 1. Install the latest release of Boto3 via pip: `pip install boto3` -1. Install the latest release of Boto3 via pip: ->pip install boto3 -# Create +1. Download the installer by browsing to [here]() +1. Double click on the installer and install to a convenient location +![](./setup_7z.PNG) + +1. __To run nitpick, double click **nitpick.exe**__ +#### Mac +1. (first time) Install brew + In a terminal: `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)` +1. (First time) install Qt: + In a terminal: `brew install qt` +1. (First time) install Python from https://www.python.org/downloads/release/python-370/ (**macOS 64-bit installer** or **macOS 64-bit/32-bit installer**) + 1. After installation - In a terminal: run `open "/Applications/Python 3.6/Install Certificates.command"`. This is needed because the Mac Python supplied no longer links with the deprecated Apple-supplied system OpenSSL libraries but rather supplies a private copy of OpenSSL 1.0.2 which does not automatically access the system default root certificates. + 1. Verify that `/usr/local/bin/python3` exists. +1. (First time - AWS interface) Install pip with the script provided by the Python Packaging Authority: +In a terminal: `curl -O https://bootstrap.pypa.io/get-pip.py` +In a terminal: `python3 get-pip.py --user` + 1. Use pip to install the AWS CLI. + `pip3 install awscli --upgrade --user` + This will install aws in your user. For user XXX, aws will be located in ~/Library/Python/3.7/bin + 1. Open a new command prompt and run `~/Library/Python/3.7/bin/aws configure` + 1. Enter the AWS account number + 1. Enter the secret key + 1. Leave region name and ouput format as default [None] + 1. Install the latest release of Boto3 via pip: pip3 install boto3 +1. Download the installer by browsing to [here](). +1. Double-click on the downloaded image to mount it +1. Create a folder for the nitpick files (e.g. ~/nitpick) + If this folder exists then delete all it's contents. +1. Copy the downloaded files to the folder + In a terminal: + `cd ~/nitpick` + `cp -r /Volumes/nitpick-installer-v1.1/* .` + +1. __To run nitpick, cd to the folder that you copied to and run `./nitpick`__ +# Usage +## Create ![](./Create.PNG) The Create tab provides functions to create tests from snapshots, MD files, a test outline and recursive scripts. -## Create Tests -### Usage +### Create Tests +#### Usage This function is used to create/update Expected Images after a successful run of a test, or multiple tests. The user will be asked for the snapshot folder and then the tests root folder. All snapshots located in the snapshot folder will be used to create or update the expected images in the relevant tests. -### Details +#### Details As an example - if the snapshots folder contains an image named `tests.content.entity.zone.zoneOrientation.00003.png`, then this file will be copied to `tests/contente/enity/zone/zoneOrientation/ExpectedImage0003.png`. -## Create Tests Outline -### Usage +### Create Tests Outline +#### Usage This function creates an MD file in the (user-selected) tests root folder. The file provides links to both the tests and the MD files. -## Create MD file -### Usage +### Create MD file +#### Usage This function creates a file named `test.md` from a `test.js` script. The user will be asked for the folder containing the test script: -### Details +#### Details The process to produce the MD file is a simplistic parse of the test script. -- The string in the `autoTester.perform(...)` function call will be the title of the file +- The string in the `nitpick.perform(...)` function call will be the title of the file - Instructions to run the script are then provided: @@ -66,62 +115,62 @@ The process to produce the MD file is a simplistic parse of the test script. - The step description is the string in the addStep/addStepStepSnapshot commands - Image links are provided where applicable to the local Expected Images files -## Create all MD files -### Usage +### Create all MD files +#### Usage This function creates all MD files recursively from the user-selected root folder. This can be any folder in the tests hierarchy (e.g. all engine\material tests). The file provides a hierarchal list of all the tests -## Create testAuto script -### Usage +### Create testAuto script +#### Usage This function creates a script named `testAuto.js` in a user-selected test folder. -### Details +#### Details The script created runs the `test.js` script in the folder in automatic mode. The script is the same for all tests. -## Create all testAuto scripts -### Usage +### Create all testAuto scripts +#### Usage This function creates all testAuto scripts recursively from the user-selected root folder. This can be any folder in the tests hierarchy (e.g. all engine\material tests). The file provides a hierarchical list of all the tests -## Create Recursive Script -### Usage +### Create Recursive Script +#### Usage After the user selects a folder within the tests hierarchy, a script is created, named `testRecursive.js`. This script calls all `test.js` scripts in the sub-folders. -### Details +#### Details The various scripts are called in alphabetical order. An example of a recursive script is as follows: ``` -// This is an automatically generated file, created by auto-tester on Jul 5 2018, 10:19 +// This is an automatically generated file, created by nitpick on Jul 5 2018, 10:19 PATH_TO_THE_REPO_PATH_UTILS_FILE = "https://raw.githubusercontent.com/highfidelity/hifi_tests/master/tests/utils/branchUtils.js"; Script.include(PATH_TO_THE_REPO_PATH_UTILS_FILE); -var autoTester = createAutoTester(Script.resolvePath(".")); +var nitpick = createNitpick(Script.resolvePath(".")); -var testsRootPath = autoTester.getTestsRootPath(); +var testsRootPath = nitpick.getTestsRootPath(); if (typeof Test !== 'undefined') { Test.wait(10000); }; -autoTester.enableRecursive(); -autoTester.enableAuto(); +nitpick.enableRecursive(); +nitpick.enableAuto(); Script.include(testsRootPath + "content/overlay/layer/drawInFront/shape/test.js"); Script.include(testsRootPath + "content/overlay/layer/drawInFront/model/test.js"); Script.include(testsRootPath + "content/overlay/layer/drawHUDLayer/test.js"); -autoTester.runRecursive(); +nitpick.runRecursive(); ``` -## Create all Recursive Scripts -### Usage +### Create all Recursive Scripts +#### Usage In this case all recursive scripts, from the selected folder down, are created. Running this function in the tests root folder will create (or update) all the recursive scripts. -# Windows +## Windows ![](./Windows.PNG) This tab is Windows-specific. It provides buttons to hide and show the task bar. The task bar should be hidden for all tests that use the primary camera. This is required to ensure that the snapshots are the right size. -# Run +## Run ![](./Run.PNG) The run tab is used to run tests in automatic mode. The tests require the location of a folder to store files in; this folder can safely be re-used for any number of runs (the "Working Folder"). The test script that is run is `https://github.com/highfidelity/hifi_tests/blob/master/tests/testRecursive.js`. The user can use a different branch' or even repository, if required. @@ -143,7 +192,7 @@ The working folder will ultimately contain the following: 1. The `dev-builds.xml` file, if it was downloaded. 1. The HighFidelity installer. Note that this is always named `HighFidelity-Beta-latest-dev` so as not to store too many installers over time. 1. A log file describing the runs. This file is appended to after each run. -# Evaluate +## Evaluate ![](./Evaluate.PNG) The Evaluate tab provides a single function - evaluating the results of a test run. @@ -151,11 +200,11 @@ The Evaluate tab provides a single function - evaluating the results of a test r A checkbox (defaulting to checked) runs the evaluation in interactive mode. In this mode - every failure is shown to the user, who can then decide whether to pass the test, fail it or abort the whole evaluation. If any tests have failed, then a zipped folder will be created in the snapshots folder, with a description of each failed step in each test. -### Usage +#### Usage Before starting the evaluation, make sure the GitHub user and branch are set correctly. The user should not normally be changed, but the branch may need to be set to the appropriate RC. After setting the check-box as required and pressing Evaluate - the user will be asked for the snapshots folder. -### Details +#### Details Evaluation proceeds in a number of steps: 1. A folder is created to store any failures @@ -165,13 +214,13 @@ Evaluation proceeds in a number of steps: 1. The images are then pair-wise compared, using the SSIM algorithm. A fixed threshold is used to define a mismatch. 1. In interactive mode - a window is opened showing the expected image, actual image, difference image and error: -![](./autoTesterMismatchExample.PNG) +![](./nitpickMismatchExample.PNG) 1. If not in interactive mode, or the user has defined the results as an error, an error is written into the error folder. The error itself is a folder with the 3 images and a small text file containing details. 1. At the end of the test, the folder is zipped and the original folder is deleted. If there are no errors then the zipped folder will be empty. -# Web Interface +## Web Interface ![](./WebInterface.PNG) This tab has two functions: updating the TestRail cases, runs and results, and creating web page reports that are stored on AWS. @@ -186,8 +235,8 @@ Any access to TestRail will require the TestRail account (default is High Fideli - The Project ID defaults to 14 - Interface. - The Suite ID defaults to 1147 - Rendering. - The TestRail page provides 3 functions for writing to TestRail. -## Create Test Cases -### Usage +### Create Test Cases +#### Usage This function can either create an XML file that can then be imported into TestRail through TestRail itself, or automatically create the appropriate TestRail Sections. The user will be first asked for the tests root folder and a folder to store temporary files (this is the output folder). @@ -199,7 +248,7 @@ If Python is selected, the user will then be prompted for TestRail data. After After selecting the appropriate Release, press OK. The Python script will be created in the output folder, and the user will be prompted to run it. A busy window will appear until the process is complete. -### Details +#### Details A number of Python scripts are created: - `testrail.py` is the TestRail interface code. - `stack.py` is a simple stack class @@ -207,7 +256,7 @@ A number of Python scripts are created: - `addTestCases` is the script that writes to TestRail. In addition - a file containing all the releases will be created - `releases.txt` -## Create Run +### Create Run A Run is created from previously created Test Cases. The user will first be prompted for a temporary folder (for the Python scripts). @@ -217,7 +266,7 @@ After entering TestRail data and pressing `Accept` - the Sections combo will be After selecting the appropriate Section, press OK. The Python script will be created in the output folder, and the user will be prompted to run it. A busy window will appear until the process is complete. -### Details +#### Details A number of Python scripts are created: - `testrail.py` is the TestRail interface code. - `stack.py` is a simple stack class @@ -225,7 +274,7 @@ A number of Python scripts are created: - `addRun` is the script that writes to TestRail. In addition - a file containing all the releases will be created - `sections.txt` -## Update Run Results +### Update Run Results This function updates a Run with the results of an automated test. The user will first be prompted to enter the zipped results folder and a folder to store temporary files (this is the output folder). @@ -235,13 +284,13 @@ After entering TestRail data and pressing `Accept` - the Run combo will be popul After selecting the appropriate Run, press OK. The Python script will be created in the output folder, and the user will be prompted to run it. A busy window will appear until the process is complete. -### Details +#### Details A number of Python scripts are created: - `testrail.py` is the TestRail interface code. - `getRuns.py` reads the release names from TestRail - `addRun` is the script that writes to TestRail. In addition - a file containing all the releases will be created - `runs.txt`. -## Create Web Page +### Create Web Page This function requests a zipped results folder and converts it to a web page. The page is created in a user-selecetd working folder. If the `Update AWS` checkbox is checked then the page will also be copied to AWS, and the appropriate URL will be displayed in the window below the button. diff --git a/tools/auto-tester/Run.PNG b/tools/nitpick/Run.PNG similarity index 100% rename from tools/auto-tester/Run.PNG rename to tools/nitpick/Run.PNG diff --git a/tools/auto-tester/TestRailSelector.PNG b/tools/nitpick/TestRailSelector.PNG similarity index 100% rename from tools/auto-tester/TestRailSelector.PNG rename to tools/nitpick/TestRailSelector.PNG diff --git a/tools/auto-tester/Web Interface.PNG b/tools/nitpick/Web Interface.PNG similarity index 100% rename from tools/auto-tester/Web Interface.PNG rename to tools/nitpick/Web Interface.PNG diff --git a/tools/auto-tester/WebInterface.PNG b/tools/nitpick/WebInterface.PNG similarity index 100% rename from tools/auto-tester/WebInterface.PNG rename to tools/nitpick/WebInterface.PNG diff --git a/tools/auto-tester/Windows.PNG b/tools/nitpick/Windows.PNG similarity index 100% rename from tools/auto-tester/Windows.PNG rename to tools/nitpick/Windows.PNG diff --git a/tools/auto-tester/autoTesterMismatchExample.PNG b/tools/nitpick/nitpickMismatchExample.PNG similarity index 100% rename from tools/auto-tester/autoTesterMismatchExample.PNG rename to tools/nitpick/nitpickMismatchExample.PNG diff --git a/tools/auto-tester/setup_7z.PNG b/tools/nitpick/setup_7z.PNG similarity index 100% rename from tools/auto-tester/setup_7z.PNG rename to tools/nitpick/setup_7z.PNG diff --git a/tools/auto-tester/src/AWSInterface.cpp b/tools/nitpick/src/AWSInterface.cpp similarity index 89% rename from tools/auto-tester/src/AWSInterface.cpp rename to tools/nitpick/src/AWSInterface.cpp index 628db5329c..e43ef8dc75 100644 --- a/tools/auto-tester/src/AWSInterface.cpp +++ b/tools/nitpick/src/AWSInterface.cpp @@ -22,11 +22,11 @@ AWSInterface::AWSInterface(QObject* parent) : QObject(parent) { } void AWSInterface::createWebPageFromResults(const QString& testResults, - const QString& workingDirectory, + const QString& snapshotDirectory, QCheckBox* updateAWSCheckBox, QLineEdit* urlLineEdit) { _testResults = testResults; - _workingDirectory = workingDirectory; + _snapshotDirectory = snapshotDirectory; _urlLineEdit = urlLineEdit; _urlLineEdit->setEnabled(false); @@ -42,16 +42,15 @@ void AWSInterface::createWebPageFromResults(const QString& testResults, void AWSInterface::extractTestFailuresFromZippedFolder() { // For a test results zip file called `D:/tt/TestResults--2018-10-02_16-54-11(9426)[DESKTOP-PMKNLSQ].zip` // the folder will be called `TestResults--2018-10-02_16-54-11(9426)[DESKTOP-PMKNLSQ]` - // and, this folder will be in the workign directory + // and, this folder will be in the working directory QStringList parts =_testResults.split('/'); - QString zipFolderName = _workingDirectory + "/" + parts[parts.length() - 1].split('.')[0]; + QString zipFolderName = _snapshotDirectory + "/" + parts[parts.length() - 1].split('.')[0]; if (QDir(zipFolderName).exists()) { QDir dir = zipFolderName; dir.removeRecursively(); } - QDir().mkdir(_workingDirectory); - JlCompress::extractDir(_testResults, _workingDirectory); + JlCompress::extractDir(_testResults, _snapshotDirectory); } void AWSInterface::createHTMLFile() { @@ -61,7 +60,7 @@ void AWSInterface::createHTMLFile() { QString filename = pathComponents[pathComponents.length() - 1]; _resultsFolder = filename.left(filename.length() - 4); - QString resultsPath = _workingDirectory + "/" + _resultsFolder + "/"; + QString resultsPath = _snapshotDirectory + "/" + _resultsFolder + "/"; QDir().mkdir(resultsPath); _htmlFilename = resultsPath + HTML_FILENAME; @@ -157,7 +156,7 @@ void AWSInterface::writeTable(QTextStream& stream) { // Note that failures are processed first, then successes QStringList originalNamesFailures; QStringList originalNamesSuccesses; - QDirIterator it1(_workingDirectory.toStdString().c_str()); + QDirIterator it1(_snapshotDirectory.toStdString().c_str()); while (it1.hasNext()) { QString nextDirectory = it1.next(); @@ -191,10 +190,10 @@ void AWSInterface::writeTable(QTextStream& stream) { newNamesSuccesses.append(originalNamesSuccesses[i].split("--tests.")[1]); } - _htmlFailuresFolder = _workingDirectory + "/" + _resultsFolder + "/" + FAILURES_FOLDER; + _htmlFailuresFolder = _snapshotDirectory + "/" + _resultsFolder + "/" + FAILURES_FOLDER; QDir().mkdir(_htmlFailuresFolder); - _htmlSuccessesFolder = _workingDirectory + "/" + _resultsFolder + "/" + SUCCESSES_FOLDER; + _htmlSuccessesFolder = _snapshotDirectory + "/" + _resultsFolder + "/" + SUCCESSES_FOLDER; QDir().mkdir(_htmlSuccessesFolder); for (int i = 0; i < newNamesFailures.length(); ++i) { @@ -321,7 +320,7 @@ void AWSInterface::createEntry(int index, const QString& testResult, QTextStream } void AWSInterface::updateAWS() { - QString filename = _workingDirectory + "/updateAWS.py"; + QString filename = _snapshotDirectory + "/updateAWS.py"; if (QFile::exists(filename)) { QFile::remove(filename); } @@ -352,14 +351,23 @@ void AWSInterface::updateAWS() { QStringList parts = nextDirectory.split('/'); QString filename = parts[parts.length() - 3] + "/" + parts[parts.length() - 2] + "/" + parts[parts.length() - 1]; - stream << "data = open('" << _workingDirectory << "/" << filename << "/" << "Actual Image.png" << "', 'rb')\n"; + stream << "data = open('" << _snapshotDirectory << "/" << filename << "/" + << "Actual Image.png" + << "', 'rb')\n"; + stream << "s3.Bucket('hifi-content').put_object(Bucket='" << AWS_BUCKET << "', Key='" << filename << "/" << "Actual Image.png" << "', Body=data)\n\n"; - stream << "data = open('" << _workingDirectory << "/" << filename << "/" << "Expected Image.png" << "', 'rb')\n"; + stream << "data = open('" << _snapshotDirectory << "/" << filename << "/" + << "Expected Image.png" + << "', 'rb')\n"; + stream << "s3.Bucket('hifi-content').put_object(Bucket='" << AWS_BUCKET << "', Key='" << filename << "/" << "Expected Image.png" << "', Body=data)\n\n"; if (QFile::exists(_htmlFailuresFolder + "/" + parts[parts.length() - 1] + "/Difference Image.png")) { - stream << "data = open('" << _workingDirectory << "/" << filename << "/" << "Difference Image.png" << "', 'rb')\n"; + stream << "data = open('" << _snapshotDirectory << "/" << filename << "/" + << "Difference Image.png" + << "', 'rb')\n"; + stream << "s3.Bucket('hifi-content').put_object(Bucket='" << AWS_BUCKET << "', Key='" << filename << "/" << "Difference Image.png" << "', Body=data)\n\n"; } } @@ -378,19 +386,28 @@ void AWSInterface::updateAWS() { QStringList parts = nextDirectory.split('/'); QString filename = parts[parts.length() - 3] + "/" + parts[parts.length() - 2] + "/" + parts[parts.length() - 1]; - stream << "data = open('" << _workingDirectory << "/" << filename << "/" << "Actual Image.png" << "', 'rb')\n"; + stream << "data = open('" << _snapshotDirectory << "/" << filename << "/" + << "Actual Image.png" + << "', 'rb')\n"; + stream << "s3.Bucket('hifi-content').put_object(Bucket='" << AWS_BUCKET << "', Key='" << filename << "/" << "Actual Image.png" << "', Body=data)\n\n"; - stream << "data = open('" << _workingDirectory << "/" << filename << "/" << "Expected Image.png" << "', 'rb')\n"; + stream << "data = open('" << _snapshotDirectory << "/" << filename << "/" + << "Expected Image.png" + << "', 'rb')\n"; + stream << "s3.Bucket('hifi-content').put_object(Bucket='" << AWS_BUCKET << "', Key='" << filename << "/" << "Expected Image.png" << "', Body=data)\n\n"; if (QFile::exists(_htmlSuccessesFolder + "/" + parts[parts.length() - 1] + "/Difference Image.png")) { - stream << "data = open('" << _workingDirectory << "/" << filename << "/" << "Difference Image.png" << "', 'rb')\n"; + stream << "data = open('" << _snapshotDirectory << "/" << filename << "/" + << "Difference Image.png" + << "', 'rb')\n"; + stream << "s3.Bucket('hifi-content').put_object(Bucket='" << AWS_BUCKET << "', Key='" << filename << "/" << "Difference Image.png" << "', Body=data)\n\n"; } } - stream << "data = open('" << _workingDirectory << "/" << _resultsFolder << "/" << HTML_FILENAME << "', 'rb')\n"; + stream << "data = open('" << _snapshotDirectory << "/" << _resultsFolder << "/" << HTML_FILENAME << "', 'rb')\n"; stream << "s3.Bucket('hifi-content').put_object(Bucket='" << AWS_BUCKET << "', Key='" << _resultsFolder << "/" << HTML_FILENAME << "', Body=data, ContentType='text/html')\n"; @@ -408,6 +425,11 @@ void AWSInterface::updateAWS() { connect(process, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) { _busyWindow.hide(); }); +#ifdef Q_OS_WIN QStringList parameters = QStringList() << filename ; process->start(_pythonCommand, parameters); +#elif defined Q_OS_MAC + QStringList parameters = QStringList() << "-c" << _pythonCommand + " " + filename; + process->start("sh", parameters); +#endif } diff --git a/tools/auto-tester/src/AWSInterface.h b/tools/nitpick/src/AWSInterface.h similarity index 94% rename from tools/auto-tester/src/AWSInterface.h rename to tools/nitpick/src/AWSInterface.h index c5be5f35bb..f4084f1a14 100644 --- a/tools/auto-tester/src/AWSInterface.h +++ b/tools/nitpick/src/AWSInterface.h @@ -26,7 +26,7 @@ public: explicit AWSInterface(QObject* parent = 0); void createWebPageFromResults(const QString& testResults, - const QString& workingDirectory, + const QString& snapshotDirectory, QCheckBox* updateAWSCheckBox, QLineEdit* urlLineEdit); @@ -49,7 +49,7 @@ public: private: QString _testResults; - QString _workingDirectory; + QString _snapshotDirectory; QString _resultsFolder; QString _htmlFailuresFolder; QString _htmlSuccessesFolder; diff --git a/tools/auto-tester/src/Downloader.cpp b/tools/nitpick/src/Downloader.cpp similarity index 92% rename from tools/auto-tester/src/Downloader.cpp rename to tools/nitpick/src/Downloader.cpp index cb9863f34d..3256e79601 100644 --- a/tools/auto-tester/src/Downloader.cpp +++ b/tools/nitpick/src/Downloader.cpp @@ -12,13 +12,12 @@ #include Downloader::Downloader(QUrl fileURL, QObject *parent) : QObject(parent) { + _networkAccessManager.get(QNetworkRequest(fileURL)); + connect( &_networkAccessManager, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*)) ); - - QNetworkRequest request(fileURL); - _networkAccessManager.get(request); } void Downloader::fileDownloaded(QNetworkReply* reply) { @@ -37,4 +36,4 @@ void Downloader::fileDownloaded(QNetworkReply* reply) { QByteArray Downloader::downloadedData() const { return _downloadedData; -} \ No newline at end of file +} diff --git a/tools/auto-tester/src/Downloader.h b/tools/nitpick/src/Downloader.h similarity index 98% rename from tools/auto-tester/src/Downloader.h rename to tools/nitpick/src/Downloader.h index 6d1029698f..742a88b890 100644 --- a/tools/auto-tester/src/Downloader.h +++ b/tools/nitpick/src/Downloader.h @@ -37,7 +37,7 @@ public: signals: void downloaded(); - private slots: +private slots: void fileDownloaded(QNetworkReply* pReply); private: diff --git a/tools/auto-tester/src/ImageComparer.cpp b/tools/nitpick/src/ImageComparer.cpp similarity index 100% rename from tools/auto-tester/src/ImageComparer.cpp rename to tools/nitpick/src/ImageComparer.cpp diff --git a/tools/auto-tester/src/ImageComparer.h b/tools/nitpick/src/ImageComparer.h similarity index 100% rename from tools/auto-tester/src/ImageComparer.h rename to tools/nitpick/src/ImageComparer.h diff --git a/tools/auto-tester/src/PythonInterface.cpp b/tools/nitpick/src/PythonInterface.cpp similarity index 76% rename from tools/auto-tester/src/PythonInterface.cpp rename to tools/nitpick/src/PythonInterface.cpp index 4922b8a8df..9832ac9f8d 100644 --- a/tools/auto-tester/src/PythonInterface.cpp +++ b/tools/nitpick/src/PythonInterface.cpp @@ -14,17 +14,28 @@ #include PythonInterface::PythonInterface() { +#ifdef Q_OS_WIN if (QProcessEnvironment::systemEnvironment().contains("PYTHON_PATH")) { QString _pythonPath = QProcessEnvironment::systemEnvironment().value("PYTHON_PATH"); if (!QFile::exists(_pythonPath + "/" + _pythonExe)) { QMessageBox::critical(0, _pythonExe, QString("Python executable not found in ") + _pythonPath); + exit(-1); } + _pythonCommand = _pythonPath + "/" + _pythonExe; } else { QMessageBox::critical(0, "PYTHON_PATH not defined", "Please set PYTHON_PATH to directory containing the Python executable"); exit(-1); } +#elif defined Q_OS_MAC + _pythonCommand = "/usr/local/bin/python3"; + if (!QFile::exists(_pythonCommand)) { + QMessageBox::critical(0, "PYTHON_PATH not defined", + "python3 not found at " + _pythonCommand); + exit(-1); + } +#endif } QString PythonInterface::getPythonCommand() { diff --git a/tools/auto-tester/src/PythonInterface.h b/tools/nitpick/src/PythonInterface.h similarity index 83% rename from tools/auto-tester/src/PythonInterface.h rename to tools/nitpick/src/PythonInterface.h index f32a39a644..947b359037 100644 --- a/tools/auto-tester/src/PythonInterface.h +++ b/tools/nitpick/src/PythonInterface.h @@ -19,7 +19,13 @@ public: QString getPythonCommand(); private: +#ifdef Q_OS_WIN const QString _pythonExe{ "python.exe" }; +#else + // Both Mac and Linux use "python" + const QString _pythonExe{ "python" }; +#endif + QString _pythonCommand; }; diff --git a/tools/auto-tester/src/Test.cpp b/tools/nitpick/src/Test.cpp similarity index 93% rename from tools/auto-tester/src/Test.cpp rename to tools/nitpick/src/Test.cpp index 582f6209af..e17978d9d0 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/nitpick/src/Test.cpp @@ -19,8 +19,8 @@ #include #include -#include "ui/AutoTester.h" -extern AutoTester* autoTester; +#include "ui/Nitpick.h" +extern Nitpick* nitpick; #include @@ -30,9 +30,9 @@ Test::Test(QProgressBar* progressBar, QCheckBox* checkBoxInteractiveMode) { _mismatchWindow.setModal(true); - if (autoTester) { - autoTester->setUserText(GIT_HUB_DEFAULT_USER); - autoTester->setBranchText(GIT_HUB_DEFAULT_BRANCH); + if (nitpick) { + nitpick->setUserText(GIT_HUB_DEFAULT_USER); + nitpick->setBranchText(GIT_HUB_DEFAULT_BRANCH); } } @@ -167,7 +167,7 @@ void Test::appendTestResultsToFile(const QString& _testResultsFolderPath, TestRe // Create text file describing the failure QTextStream stream(&descriptionFile); - stream << "Test failed in folder " << testResult._pathname.left(testResult._pathname.length() - 1) << endl; // remove trailing '/' + stream << "Test in folder " << testResult._pathname.left(testResult._pathname.length() - 1) << endl; // remove trailing '/' stream << "Expected image was " << testResult._expectedImageFilename << endl; stream << "Actual image was " << testResult._actualImageFilename << endl; stream << "Similarity index was " << testResult._error << endl; @@ -240,8 +240,8 @@ void Test::startTestsEvaluation(const bool isRunningFromCommandLine, _expectedImagesFilenames.clear(); _expectedImagesFullFilenames.clear(); - QString branch = (branchFromCommandLine.isNull()) ? autoTester->getSelectedBranch() : branchFromCommandLine; - QString user = (userFromCommandLine.isNull()) ? autoTester->getSelectedUser() : userFromCommandLine; + QString branch = (branchFromCommandLine.isNull()) ? nitpick->getSelectedBranch() : branchFromCommandLine; + QString user = (userFromCommandLine.isNull()) ? nitpick->getSelectedUser() : userFromCommandLine; foreach(QString currentFilename, sortedTestResultsFilenames) { QString fullCurrentFilename = _snapshotDirectory + "/" + currentFilename; @@ -268,7 +268,7 @@ void Test::startTestsEvaluation(const bool isRunningFromCommandLine, } } - autoTester->downloadFiles(expectedImagesURLs, _snapshotDirectory, _expectedImagesFilenames, (void *)this); + nitpick->downloadFiles(expectedImagesURLs, _snapshotDirectory, _expectedImagesFilenames, (void *)this); } void Test::finishTestsEvaluation() { int numberOfFailures = compareImageLists(); @@ -288,7 +288,7 @@ void Test::finishTestsEvaluation() { } if (_isRunningInAutomaticTestRun) { - autoTester->automaticTestRunEvaluationComplete(zippedFolderName, numberOfFailures); + nitpick->automaticTestRunEvaluationComplete(zippedFolderName, numberOfFailures); } } @@ -429,22 +429,22 @@ ExtractedText Test::getTestScriptLines(QString testFileName) { QString line = stream.readLine(); // Name of test is the string in the following line: - // autoTester.perform("Apply Material Entities to Avatars", Script.resolvePath("."), function(testType) {... + // nitpick.perform("Apply Material Entities to Avatars", Script.resolvePath("."), function(testType) {... const QString ws("\\h*"); //white-space character - const QString functionPerformName(ws + "autoTester" + ws + "\\." + ws + "perform"); + const QString functionPerformName(ws + "nitpick" + ws + "\\." + ws + "perform"); const QString quotedString("\\\".+\\\""); QString regexTestTitle(ws + functionPerformName + "\\(" + quotedString); QRegularExpression lineContainingTitle = QRegularExpression(regexTestTitle); // Each step is either of the following forms: - // autoTester.addStepSnapshot("Take snapshot"... - // autoTester.addStep("Clean up after test"... - const QString functionAddStepSnapshotName(ws + "autoTester" + ws + "\\." + ws + "addStepSnapshot"); + // nitpick.addStepSnapshot("Take snapshot"... + // nitpick.addStep("Clean up after test"... + const QString functionAddStepSnapshotName(ws + "nitpick" + ws + "\\." + ws + "addStepSnapshot"); const QString regexStepSnapshot(ws + functionAddStepSnapshotName + ws + "\\(" + ws + quotedString + ".*"); const QRegularExpression lineStepSnapshot = QRegularExpression(regexStepSnapshot); - const QString functionAddStepName(ws + "autoTester" + ws + "\\." + ws + "addStep"); + const QString functionAddStepName(ws + "nitpick" + ws + "\\." + ws + "addStep"); const QString regexStep(ws + functionAddStepName + ws + "\\(" + ws + quotedString + ".*"); const QRegularExpression lineStep = QRegularExpression(regexStep); @@ -620,7 +620,7 @@ void Test::createTestAutoScript() { } if (createTestAutoScript(_testDirectory)) { - QMessageBox::information(0, "Success", "'autoTester.js` script has been created"); + QMessageBox::information(0, "Success", "'testAuto.js` script has been created"); } } @@ -653,7 +653,7 @@ void Test::createAllTestAutoScripts() { } } - QMessageBox::information(0, "Success", "'autoTester.js' scripts have been created"); + QMessageBox::information(0, "Success", "'nitpick.js' scripts have been created"); } bool Test::createTestAutoScript(const QString& directory) { @@ -677,8 +677,8 @@ bool Test::createTestAutoScript(const QString& directory) { stream << "if (typeof PATH_TO_THE_REPO_PATH_UTILS_FILE === 'undefined') PATH_TO_THE_REPO_PATH_UTILS_FILE = 'https://raw.githubusercontent.com/highfidelity/hifi_tests/master/tests/utils/branchUtils.js';\n"; stream << "Script.include(PATH_TO_THE_REPO_PATH_UTILS_FILE);\n"; - stream << "var autoTester = createAutoTester(Script.resolvePath('.'));\n\n"; - stream << "autoTester.enableAuto();\n\n"; + stream << "var nitpick = createNitpick(Script.resolvePath('.'));\n\n"; + stream << "nitpick.enableAuto();\n\n"; stream << "Script.include('./test.js?raw=true');\n"; testAutoScriptFile.close(); @@ -748,32 +748,32 @@ void Test::createRecursiveScript(const QString& topLevelDirectory, bool interact QTextStream textStream(&allTestsFilename); - textStream << "// This is an automatically generated file, created by auto-tester" << endl; + textStream << "// This is an automatically generated file, created by nitpick" << endl; - // Include 'autoTest.js' - QString branch = autoTester->getSelectedBranch(); - QString user = autoTester->getSelectedUser(); + // Include 'nitpick.js' + QString branch = nitpick->getSelectedBranch(); + QString user = nitpick->getSelectedUser(); textStream << "PATH_TO_THE_REPO_PATH_UTILS_FILE = \"https://raw.githubusercontent.com/" + user + "/hifi_tests/" + branch + "/tests/utils/branchUtils.js\";" << endl; textStream << "Script.include(PATH_TO_THE_REPO_PATH_UTILS_FILE);" << endl; - textStream << "var autoTester = createAutoTester(Script.resolvePath(\".\"));" << endl << endl; + textStream << "var nitpick = createNitpick(Script.resolvePath(\".\"));" << endl << endl; - textStream << "var testsRootPath = autoTester.getTestsRootPath();" << endl << endl; + textStream << "var testsRootPath = nitpick.getTestsRootPath();" << endl << endl; // Wait 10 seconds before starting textStream << "if (typeof Test !== 'undefined') {" << endl; textStream << " Test.wait(10000);" << endl; textStream << "};" << endl << endl; - textStream << "autoTester.enableRecursive();" << endl; - textStream << "autoTester.enableAuto();" << endl << endl; + textStream << "nitpick.enableRecursive();" << endl; + textStream << "nitpick.enableAuto();" << endl << endl; // This is used to verify that the recursive test contains at least one test bool testFound{ false }; - // Directories are included in reverse order. The autoTester scripts use a stack mechanism, + // Directories are included in reverse order. The nitpick scripts use a stack mechanism, // so this ensures that the tests run in alphabetical order (a convenience when debugging) QStringList directories; @@ -819,7 +819,7 @@ void Test::createRecursiveScript(const QString& topLevelDirectory, bool interact } textStream << endl; - textStream << "autoTester.runRecursive();" << endl; + textStream << "nitpick.runRecursive();" << endl; allTestsFilename.close(); } @@ -881,7 +881,7 @@ void Test::createTestsOutline() { // The directory name appears after the last slash (we are assured there is at least 1). QString directoryName = directory.right(directory.length() - directory.lastIndexOf("/") - 1); - // autoTester is run on a clone of the repository. We use relative paths, so we can use both local disk and GitHub + // nitpick is run on a clone of the repository. We use relative paths, so we can use both local disk and GitHub // For a test in "D:/GitHub/hifi_tests/tests/content/entity/zone/ambientLightInheritance" the // GitHub URL is "./content/entity/zone/ambientLightInheritance?raw=true" QString partialPath = directory.right(directory.length() - (directory.lastIndexOf("/tests/") + QString("/tests").length() + 1)); @@ -937,11 +937,11 @@ void Test::createTestRailTestCases() { } if (_testRailCreateMode == PYTHON) { - _testRailInterface.createTestSuitePython(_testDirectory, outputDirectory, autoTester->getSelectedUser(), - autoTester->getSelectedBranch()); + _testRailInterface.createTestSuitePython(_testDirectory, outputDirectory, nitpick->getSelectedUser(), + nitpick->getSelectedBranch()); } else { - _testRailInterface.createTestSuiteXML(_testDirectory, outputDirectory, autoTester->getSelectedUser(), - autoTester->getSelectedBranch()); + _testRailInterface.createTestSuiteXML(_testDirectory, outputDirectory, nitpick->getSelectedUser(), + nitpick->getSelectedBranch()); } } @@ -1052,11 +1052,11 @@ void Test::createWebPage(QCheckBox* updateAWSCheckBox, QLineEdit* urlLineEdit) { return; } - QString tempDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select a folder to store temporary files in", + QString snapshotDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select a folder to store temporary files in", nullptr, QFileDialog::ShowDirsOnly); - if (tempDirectory.isNull()) { + if (snapshotDirectory.isNull()) { return; } - _awsInterface.createWebPageFromResults(testResults, tempDirectory, updateAWSCheckBox, urlLineEdit); + _awsInterface.createWebPageFromResults(testResults, snapshotDirectory, updateAWSCheckBox, urlLineEdit); } \ No newline at end of file diff --git a/tools/auto-tester/src/Test.h b/tools/nitpick/src/Test.h similarity index 98% rename from tools/auto-tester/src/Test.h rename to tools/nitpick/src/Test.h index f653a91782..a79252b92a 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/nitpick/src/Test.h @@ -146,7 +146,7 @@ private: const QString DATETIME_FORMAT{ "yyyy-MM-dd_hh-mm-ss" }; - // NOTE: these need to match the appropriate var's in autoTester.js + // NOTE: these need to match the appropriate var's in nitpick.js // var advanceKey = "n"; // var pathSeparator = "."; const QString ADVANCE_KEY{ "n" }; diff --git a/tools/auto-tester/src/TestRailInterface.cpp b/tools/nitpick/src/TestRailInterface.cpp similarity index 97% rename from tools/auto-tester/src/TestRailInterface.cpp rename to tools/nitpick/src/TestRailInterface.cpp index f943935539..a0c0d74526 100644 --- a/tools/auto-tester/src/TestRailInterface.cpp +++ b/tools/nitpick/src/TestRailInterface.cpp @@ -357,8 +357,13 @@ void TestRailInterface::createAddTestCasesPythonScript(const QString& testDirect connect(process, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) { _busyWindow.hide(); }); +#ifdef Q_OS_WIN QStringList parameters = QStringList() << _outputDirectory + "/addTestCases.py"; process->start(_pythonCommand, parameters); +#elif defined Q_OS_MAC + QStringList parameters = QStringList() << "-c" << _pythonCommand + " " + _outputDirectory + "/addTestCases.py"; + process->start("sh", parameters); +#endif } } @@ -482,8 +487,13 @@ void TestRailInterface::addRun() { connect(process, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) { _busyWindow.hide(); }); +#ifdef Q_OS_WIN QStringList parameters = QStringList() << _outputDirectory + "/addRun.py"; process->start(_pythonCommand, parameters); +#elif defined Q_OS_MAC + QStringList parameters = QStringList() << "-c" << _pythonCommand + " " + _outputDirectory + "/addRun.py"; + process->start("sh", parameters); +#endif } } @@ -586,8 +596,13 @@ void TestRailInterface::updateRunWithResults() { connect(process, static_cast(&QProcess::finished), this, [=](int exitCode, QProcess::ExitStatus exitStatus) { _busyWindow.hide(); }); +#ifdef Q_OS_WIN QStringList parameters = QStringList() << _outputDirectory + "/updateRunWithResults.py"; process->start(_pythonCommand, parameters); +#elif defined Q_OS_MAC + QStringList parameters = QStringList() << "-c" << _pythonCommand + " " + _outputDirectory + "/updateRunWithResults.py"; + process->start("sh", parameters); +#endif } } @@ -759,8 +774,13 @@ void TestRailInterface::getReleasesFromTestRail() { [=](int exitCode, QProcess::ExitStatus exitStatus) { updateReleasesComboData(exitCode, exitStatus); }); connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); +#ifdef Q_OS_WIN QStringList parameters = QStringList() << filename; process->start(_pythonCommand, parameters); +#elif defined Q_OS_MAC + QStringList parameters = QStringList() << "-c" << _pythonCommand + " " + filename; + process->start("sh", parameters); +#endif } void TestRailInterface::createTestSuitePython(const QString& testDirectory, @@ -1078,8 +1098,13 @@ void TestRailInterface::getTestSectionsFromTestRail() { [=](int exitCode, QProcess::ExitStatus exitStatus) { updateSectionsComboData(exitCode, exitStatus); }); connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); +#ifdef Q_OS_WIN QStringList parameters = QStringList() << filename; process->start(_pythonCommand, parameters); +#elif defined Q_OS_MAC + QStringList parameters = QStringList() << "-c" << _pythonCommand + " " + filename; + process->start("sh", parameters); +#endif } void TestRailInterface::getRunsFromTestRail() { @@ -1117,9 +1142,13 @@ void TestRailInterface::getRunsFromTestRail() { [=](int exitCode, QProcess::ExitStatus exitStatus) { updateRunsComboData(exitCode, exitStatus); }); connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); +#ifdef Q_OS_WIN QStringList parameters = QStringList() << filename; - process->start(_pythonCommand, parameters); +#elif defined Q_OS_MAC + QStringList parameters = QStringList() << "-c" << _pythonCommand + " " + filename; + process->start("sh", parameters); +#endif } void TestRailInterface::createTestRailRun(const QString& outputDirectory) { @@ -1164,4 +1193,4 @@ void TestRailInterface::extractTestFailuresFromZippedFolder(const QString& testR QDir dir = tempSubDirectory; dir.mkdir(tempSubDirectory); JlCompress::extractDir(testResults, tempSubDirectory); -} \ No newline at end of file +} diff --git a/tools/auto-tester/src/TestRailInterface.h b/tools/nitpick/src/TestRailInterface.h similarity index 100% rename from tools/auto-tester/src/TestRailInterface.h rename to tools/nitpick/src/TestRailInterface.h diff --git a/tools/auto-tester/src/TestRunner.cpp b/tools/nitpick/src/TestRunner.cpp similarity index 61% rename from tools/auto-tester/src/TestRunner.cpp rename to tools/nitpick/src/TestRunner.cpp index 01ec04f254..12bdf87495 100644 --- a/tools/auto-tester/src/TestRunner.cpp +++ b/tools/nitpick/src/TestRunner.cpp @@ -13,14 +13,17 @@ #include #include -#include "ui/AutoTester.h" -extern AutoTester* autoTester; +#include "ui/Nitpick.h" +extern Nitpick* nitpick; #ifdef Q_OS_WIN #include #include #endif +// TODO: for debug +#include + TestRunner::TestRunner(std::vector dayCheckboxes, std::vector timeEditCheckboxes, std::vector timeEdits, @@ -40,27 +43,29 @@ TestRunner::TestRunner(std::vector dayCheckboxes, _url = url; _runNow = runNow; - installerThread = new QThread(); - installerWorker = new Worker(); - installerWorker->moveToThread(installerThread); - installerThread->start(); - connect(this, SIGNAL(startInstaller()), installerWorker, SLOT(runCommand())); - connect(installerWorker, SIGNAL(commandComplete()), this, SLOT(installationComplete())); + _installerThread = new QThread(); + _installerWorker = new Worker(); + + _installerWorker->moveToThread(_installerThread); + _installerThread->start(); + connect(this, SIGNAL(startInstaller()), _installerWorker, SLOT(runCommand())); + connect(_installerWorker, SIGNAL(commandComplete()), this, SLOT(installationComplete())); - interfaceThread = new QThread(); - interfaceWorker = new Worker(); - interfaceThread->start(); - interfaceWorker->moveToThread(interfaceThread); - connect(this, SIGNAL(startInterface()), interfaceWorker, SLOT(runCommand())); - connect(interfaceWorker, SIGNAL(commandComplete()), this, SLOT(interfaceExecutionComplete())); + _interfaceThread = new QThread(); + _interfaceWorker = new Worker(); + + _interfaceThread->start(); + _interfaceWorker->moveToThread(_interfaceThread); + connect(this, SIGNAL(startInterface()), _interfaceWorker, SLOT(runCommand())); + connect(_interfaceWorker, SIGNAL(commandComplete()), this, SLOT(interfaceExecutionComplete())); } TestRunner::~TestRunner() { - delete installerThread; - delete interfaceThread; + delete _installerThread; + delete _installerWorker; - delete interfaceThread; - delete interfaceWorker; + delete _interfaceThread; + delete _interfaceWorker; if (_timer) { delete _timer; @@ -84,15 +89,96 @@ void TestRunner::setWorkingFolder() { return; } +#ifdef Q_OS_WIN _installationFolder = _workingFolder + "/High Fidelity"; +#elif defined Q_OS_MAC + _installationFolder = _workingFolder + "/High_Fidelity"; +#endif + _logFile.setFileName(_workingFolder + "/log.txt"); - autoTester->enableRunTabControls(); + nitpick->enableRunTabControls(); _workingFolderLabel->setText(QDir::toNativeSeparators(_workingFolder)); _timer = new QTimer(this); connect(_timer, SIGNAL(timeout()), this, SLOT(checkTime())); _timer->start(30 * 1000); //time specified in ms + +#ifdef Q_OS_MAC + // Create MAC shell scripts + QFile script; + + // This script waits for a process to start + script.setFileName(_workingFolder + "/waitForStart.sh"); + if (!script.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Could not open 'waitForStart.sh'"); + exit(-1); + } + + script.write("#!/bin/sh\n\n"); + script.write("PROCESS=\"$1\"\n"); + script.write("until (pgrep -x $PROCESS >nul)\n"); + script.write("do\n"); + script.write("\techo waiting for \"$1\" to start\n"); + script.write("\tsleep 2\n"); + script.write("done\n"); + script.write("echo \"$1\" \"started\"\n"); + script.close(); + script.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner); + + // The Mac shell command returns immediately. This little script waits for a process to finish + script.setFileName(_workingFolder + "/waitForFinish.sh"); + if (!script.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Could not open 'waitForFinish.sh'"); + exit(-1); + } + + script.write("#!/bin/sh\n\n"); + script.write("PROCESS=\"$1\"\n"); + script.write("while (pgrep -x $PROCESS >nul)\n"); + script.write("do\n"); + script.write("\techo waiting for \"$1\" to finish\n"); + script.write("\tsleep 2\n"); + script.write("done\n"); + script.write("echo \"$1\" \"finished\"\n"); + script.close(); + script.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner); + + // Create an AppleScript to resize Interface. This is needed so that snapshots taken + // with the primary camera will be the correct size. + // This will be run from a normal shell script + script.setFileName(_workingFolder + "/setInterfaceSizeAndPosition.scpt"); + if (!script.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Could not open 'setInterfaceSizeAndPosition.scpt'"); + exit(-1); + } + + script.write("set width to 960\n"); + script.write("set height to 540\n"); + script.write("set x to 100\n"); + script.write("set y to 100\n\n"); + script.write("tell application \"System Events\" to tell application process \"interface\" to tell window 1 to set {size, position} to {{width, height}, {x, y}}\n"); + + script.close(); + script.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner); + + script.setFileName(_workingFolder + "/setInterfaceSizeAndPosition.sh"); + if (!script.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Could not open 'setInterfaceSizeAndPosition.sh'"); + exit(-1); + } + + script.write("#!/bin/sh\n\n"); + script.write("echo resizing interface\n"); + script.write(("osascript " + _workingFolder + "/setInterfaceSizeAndPosition.scpt\n").toStdString().c_str()); + script.write("echo resize complete\n"); + script.close(); + script.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner); +#endif } void TestRunner::run() { @@ -102,8 +188,8 @@ void TestRunner::run() { _automatedTestIsRunning = true; // Initial setup - _branch = autoTester->getSelectedBranch(); - _user = autoTester->getSelectedUser(); + _branch = nitpick->getSelectedBranch(); + _user = nitpick->getSelectedUser(); // This will be restored at the end of the tests saveExistingHighFidelityAppDataFolder(); @@ -120,7 +206,7 @@ void TestRunner::run() { updateStatusLabel("Downloading Build XML"); buildXMLDownloaded = false; - autoTester->downloadFiles(urls, _workingFolder, filenames, (void*)this); + nitpick->downloadFiles(urls, _workingFolder, filenames, (void*)this); // `downloadComplete` will run after download has completed } @@ -149,7 +235,7 @@ void TestRunner::downloadComplete() { updateStatusLabel("Downloading installer"); - autoTester->downloadFiles(urls, _workingFolder, filenames, (void*)this); + nitpick->downloadFiles(urls, _workingFolder, filenames, (void*)this); // `downloadComplete` will run again after download has completed @@ -176,10 +262,43 @@ void TestRunner::runInstaller() { QString installerFullPath = _workingFolder + "/" + _installerFilename; - QString commandLine = - "\"" + QDir::toNativeSeparators(installerFullPath) + "\"" + " /S /D=" + QDir::toNativeSeparators(_installationFolder); + QString commandLine; +#ifdef Q_OS_WIN + commandLine = "\"" + QDir::toNativeSeparators(installerFullPath) + "\"" + " /S /D=" + QDir::toNativeSeparators(_installationFolder); +#elif defined Q_OS_MAC + // Create installation shell script + QFile script; + script.setFileName(_workingFolder + "/install_app.sh"); + if (!script.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Could not open 'install_app.sh'"); + exit(-1); + } + + if (!QDir().exists(_installationFolder)) { + QDir().mkdir(_installationFolder); + } + + // This script installs High Fidelity. It is run as "yes | install_app.sh... so "yes" is killed at the end + script.write("#!/bin/sh\n\n"); + script.write("VOLUME=`hdiutil attach \"$1\" | grep Volumes | awk '{print $3}'`\n"); + + QString folderName {"High Fidelity"}; + if (!_runLatest->isChecked()) { + folderName += QString(" - ") + getPRNumberFromURL(_url->text()); + } - installerWorker->setCommandLine(commandLine); + script.write((QString("cp -rf \"$VOLUME/") + folderName + "/interface.app\" \"" + _workingFolder + "/High_Fidelity/\"\n").toStdString().c_str()); + script.write((QString("cp -rf \"$VOLUME/") + folderName + "/Sandbox.app\" \"" + _workingFolder + "/High_Fidelity/\"\n").toStdString().c_str()); + + script.write("hdiutil detach \"$VOLUME\"\n"); + script.write("killall yes\n"); + script.close(); + script.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner); + commandLine = "yes | " + _workingFolder + "/install_app.sh " + installerFullPath; +#endif + appendLog(commandLine); + _installerWorker->setCommandLine(commandLine); emit startInstaller(); } @@ -214,23 +333,22 @@ void TestRunner::verifyInstallationSucceeded() { void TestRunner::saveExistingHighFidelityAppDataFolder() { QString dataDirectory{ "NOT FOUND" }; - #ifdef Q_OS_WIN dataDirectory = qgetenv("USERPROFILE") + "\\AppData\\Roaming"; +#elif defined Q_OS_MAC + dataDirectory = QDir::homePath() + "/Library/Application Support"; #endif - if (_runLatest->isChecked()) { - _appDataFolder = dataDirectory + "\\High Fidelity"; + _appDataFolder = dataDirectory + "/High Fidelity"; } else { // We are running a PR build - _appDataFolder = dataDirectory + "\\High Fidelity - " + getPRNumberFromURL(_url->text()); + _appDataFolder = dataDirectory + "/High Fidelity - " + getPRNumberFromURL(_url->text()); } _savedAppDataFolder = dataDirectory + "/" + UNIQUE_FOLDER_NAME; - if (_savedAppDataFolder.exists()) { + if (QDir(_savedAppDataFolder).exists()) { _savedAppDataFolder.removeRecursively(); } - if (_appDataFolder.exists()) { // The original folder is saved in a unique name _appDataFolder.rename(_appDataFolder.path(), _savedAppDataFolder.path()); @@ -307,28 +425,42 @@ void TestRunner::killProcesses() { QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "unknown error"); exit(-1); } +#elif defined Q_OS_MAC + QString commandLine; + + commandLine = QString("killall interface") + "; " + _workingFolder +"/waitForFinish.sh interface"; + system(commandLine.toStdString().c_str()); + + commandLine = QString("killall Sandbox") + "; " + _workingFolder +"/waitForFinish.sh Sandbox"; + system(commandLine.toStdString().c_str()); + + commandLine = QString("killall Console") + "; " + _workingFolder +"/waitForFinish.sh Console"; + system(commandLine.toStdString().c_str()); #endif } void TestRunner::startLocalServerProcesses() { -#ifdef Q_OS_WIN QString commandLine; - - commandLine = "start \"domain-server.exe\" \"" + QDir::toNativeSeparators(_installationFolder) + "\\domain-server.exe\""; + +#ifdef Q_OS_WIN + commandLine = + "start \"domain-server.exe\" \"" + QDir::toNativeSeparators(_installationFolder) + "\\domain-server.exe\""; system(commandLine.toStdString().c_str()); commandLine = "start \"assignment-client.exe\" \"" + QDir::toNativeSeparators(_installationFolder) + "\\assignment-client.exe\" -n 6"; system(commandLine.toStdString().c_str()); + +#elif defined Q_OS_MAC + commandLine = "open \"" +_installationFolder + "/Sandbox.app\""; + system(commandLine.toStdString().c_str()); #endif + // Give server processes time to stabilize QThread::sleep(20); } void TestRunner::runInterfaceWithTestScript() { - QString exeFile = QString("\"") + QDir::toNativeSeparators(_installationFolder) + "\\interface.exe\""; - QString snapshotFolder = QString("\"") + QDir::toNativeSeparators(_snapshotFolder) + "\""; - QString url = QString("hifi://localhost"); if (_runServerless->isChecked()) { // Move to an empty area @@ -340,31 +472,76 @@ void TestRunner::runInterfaceWithTestScript() { QString testScript = QString("https://raw.githubusercontent.com/") + _user + "/hifi_tests/" + _branch + "/tests/testRecursive.js"; - QString commandLine = exeFile + " --url " + url + " --no-updater --no-login-suggestion" + " --testScript " + testScript + - " quitWhenFinished --testResultsLocation " + snapshotFolder; + QString commandLine; +#ifdef Q_OS_WIN + QString exeFile = QString("\"") + QDir::toNativeSeparators(_installationFolder) + "\\interface.exe\""; + commandLine = exeFile + + " --url " + url + + " --no-updater" + + " --no-login-suggestion" + " --testScript " + testScript + " quitWhenFinished" + + " --testResultsLocation " + _snapshotFolder; - interfaceWorker->setCommandLine(commandLine); + _interfaceWorker->setCommandLine(commandLine); emit startInterface(); +#elif defined Q_OS_MAC + // On The Mac, we need to resize Interface. The Interface window opens a few seconds after the process + // has started. + // Before starting interface, start a process that will resize interface 10s after it opens + // This is performed by creating a bash script that runs to processes + QFile script; + script.setFileName(_workingFolder + "/runInterfaceTests.sh"); + if (!script.open(QIODevice::WriteOnly | QIODevice::Text)) { + QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), + "Could not open 'runInterfaceTests.sh'"); + exit(-1); + } + + script.write("#!/bin/sh\n\n"); + + commandLine = _workingFolder +"/waitForStart.sh interface && sleep 10 && " + _workingFolder +"/setInterfaceSizeAndPosition.sh &\n"; + script.write(commandLine.toStdString().c_str()); + + commandLine = + "open \"" +_installationFolder + "/interface.app\" --args" + + " --url " + url + + " --no-updater" + + " --no-login-suggestion" + " --testScript " + testScript + " quitWhenFinished" + + " --testResultsLocation " + _snapshotFolder + + " && " + _workingFolder +"/waitForFinish.sh interface"; + + script.write(commandLine.toStdString().c_str()); + + script.close(); + script.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner); + + commandLine = _workingFolder + "/runInterfaceTests.sh"; + _interfaceWorker->setCommandLine(commandLine); + + emit startInterface(); +#endif + + // Helpful for debugging + appendLog(commandLine); } void TestRunner::interfaceExecutionComplete() { - killProcesses(); - QFileInfo testCompleted(QDir::toNativeSeparators(_snapshotFolder) +"/tests_completed.txt"); if (!testCompleted.exists()) { - QMessageBox::critical(0, "Tests not completed", "Interface seems to have crashed before completion of the test scripts"); - _runNow->setEnabled(true); - return; + QMessageBox::critical(0, "Tests not completed", "Interface seems to have crashed before completion of the test scripts\nExisting images will be evaluated"); } evaluateResults(); + killProcesses(); + // The High Fidelity AppData folder will be restored after evaluation has completed } void TestRunner::evaluateResults() { updateStatusLabel("Evaluating results"); - autoTester->startTestsEvaluation(false, true, _snapshotFolder, _branch, _user); + nitpick->startTestsEvaluation(false, true, _snapshotFolder, _branch, _user); } void TestRunner::automaticTestRunEvaluationComplete(QString zippedFolder, int numberOfFailures) { @@ -473,7 +650,7 @@ void TestRunner::checkTime() { } void TestRunner::updateStatusLabel(const QString& message) { - autoTester->updateStatusLabel(message); + nitpick->updateStatusLabel(message); } void TestRunner::appendLog(const QString& message) { @@ -487,11 +664,12 @@ void TestRunner::appendLog(const QString& message) { _logFile.write("\n"); _logFile.close(); - autoTester->appendLogWindow(message); + nitpick->appendLogWindow(message); } QString TestRunner::getInstallerNameFromURL(const QString& url) { // An example URL: https://deployment.highfidelity.com/jobs/pr-build/label%3Dwindows/13023/HighFidelity-Beta-Interface-PR14006-be76c43.exe + // On Mac, replace `exe` with `dmg` try { QStringList urlParts = url.split("/"); return urlParts[urlParts.size() - 1]; @@ -509,7 +687,11 @@ QString TestRunner::getPRNumberFromURL(const QString& url) { QStringList urlParts = url.split("/"); QStringList filenameParts = urlParts[urlParts.size() - 1].split("-"); if (filenameParts.size() <= 3) { +#ifdef Q_OS_WIN throw "URL not in expected format, should look like `https://deployment.highfidelity.com/jobs/pr-build/label%3Dwindows/13023/HighFidelity-Beta-Interface-PR14006-be76c43.exe`"; +#elif defined Q_OS_MAC + throw "URL not in expected format, should look like `https://deployment.highfidelity.com/jobs/pr-build/label%3Dwindows/13023/HighFidelity-Beta-Interface-PR14006-be76c43.dmg`"; +#endif } return filenameParts[filenameParts.size() - 2]; } catch (QString errorMessage) { @@ -536,6 +718,7 @@ void TestRunner::parseBuildInformation() { #elif defined(Q_OS_MAC) platformOfInterest = "mac"; #endif + QDomElement element = domDocument.documentElement(); // Verify first element is "projects" @@ -552,42 +735,48 @@ void TestRunner::parseBuildInformation() { throw("File is not from 'interface' build"); } - // Now loop over the platforms + // Now loop over the platforms, looking for ours + bool platformFound{ false }; + element = element.firstChild().toElement(); while (!element.isNull()) { - element = element.firstChild().toElement(); - if (element.tagName() != "platform" || element.attribute("name") != platformOfInterest) { - continue; + if (element.attribute("name") == platformOfInterest) { + platformFound = true; + break; } - - // Next element should be the build - element = element.firstChild().toElement(); - if (element.tagName() != "build") { - throw("File seems to be in wrong format"); - } - - // Next element should be the version - element = element.firstChild().toElement(); - if (element.tagName() != "version") { - throw("File seems to be in wrong format"); - } - - // Add the build number to the end of the filename - _buildInformation.build = element.text(); - - // First sibling should be stable_version element = element.nextSibling().toElement(); - if (element.tagName() != "stable_version") { - throw("File seems to be in wrong format"); - } - - // Next sibling should be url - element = element.nextSibling().toElement(); - if (element.tagName() != "url") { - throw("File seems to be in wrong format"); - } - _buildInformation.url = element.text(); } + if (!platformFound) { + throw("File seems to be in wrong format - platform " + platformOfInterest + " not found"); + } + + element = element.firstChild().toElement(); + if (element.tagName() != "build") { + throw("File seems to be in wrong format"); + } + + // Next element should be the version + element = element.firstChild().toElement(); + if (element.tagName() != "version") { + throw("File seems to be in wrong format"); + } + + // Add the build number to the end of the filename + _buildInformation.build = element.text(); + + // First sibling should be stable_version + element = element.nextSibling().toElement(); + if (element.tagName() != "stable_version") { + throw("File seems to be in wrong format"); + } + + // Next sibling should be url + element = element.nextSibling().toElement(); + if (element.tagName() != "url") { + throw("File seems to be in wrong format"); + } + _buildInformation.url = element.text(); + } catch (QString errorMessage) { QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), errorMessage); exit(-1); @@ -605,4 +794,4 @@ int Worker::runCommand() { int result = system(_commandLine.toStdString().c_str()); emit commandComplete(); return result; -} \ No newline at end of file +} diff --git a/tools/auto-tester/src/TestRunner.h b/tools/nitpick/src/TestRunner.h similarity index 90% rename from tools/auto-tester/src/TestRunner.h rename to tools/nitpick/src/TestRunner.h index e6cb7cd764..00f0f66ecf 100644 --- a/tools/auto-tester/src/TestRunner.h +++ b/tools/nitpick/src/TestRunner.h @@ -84,11 +84,18 @@ private slots: signals: void startInstaller(); void startInterface(); - + void startResize(); + private: bool _automatedTestIsRunning{ false }; +#ifdef Q_OS_WIN const QString INSTALLER_FILENAME_LATEST{ "HighFidelity-Beta-latest-dev.exe" }; +#elif defined(Q_OS_MAC) + const QString INSTALLER_FILENAME_LATEST{ "HighFidelity-Beta-latest-dev.dmg" }; +#else + const QString INSTALLER_FILENAME_LATEST{ "" }; +#endif QString _installerURL; QString _installerFilename; @@ -124,11 +131,12 @@ private: QDateTime _testStartDateTime; - QThread* installerThread; - QThread* interfaceThread; - Worker* installerWorker; - Worker* interfaceWorker; + QThread* _installerThread; + QThread* _interfaceThread; + Worker* _installerWorker; + Worker* _interfaceWorker; + BuildInformation _buildInformation; }; @@ -144,8 +152,8 @@ signals: void commandComplete(); void startInstaller(); void startInterface(); - + private: QString _commandLine; }; -#endif // hifi_testRunner_h \ No newline at end of file +#endif // hifi_testRunner_h diff --git a/tools/auto-tester/src/common.h b/tools/nitpick/src/common.h similarity index 100% rename from tools/auto-tester/src/common.h rename to tools/nitpick/src/common.h diff --git a/tools/auto-tester/src/main.cpp b/tools/nitpick/src/main.cpp similarity index 89% rename from tools/auto-tester/src/main.cpp rename to tools/nitpick/src/main.cpp index ac4b4593c5..089a72e6ce 100644 --- a/tools/auto-tester/src/main.cpp +++ b/tools/nitpick/src/main.cpp @@ -8,11 +8,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include -#include "ui/AutoTester.h" +#include "ui/Nitpick.h" #include -AutoTester* autoTester; +Nitpick* nitpick; int main(int argc, char *argv[]) { // If no parameters then run in interactive mode @@ -62,13 +62,13 @@ int main(int argc, char *argv[]) { QApplication application(argc, argv); - autoTester = new AutoTester(); - autoTester->setup(); + nitpick = new Nitpick(); + nitpick->setup(); if (!testFolder.isNull()) { - autoTester->startTestsEvaluation(true ,false, testFolder, branch, user); + nitpick->startTestsEvaluation(true ,false, testFolder, branch, user); } else { - autoTester->show(); + nitpick->show(); } return application.exec(); diff --git a/tools/auto-tester/src/ui/BusyWindow.cpp b/tools/nitpick/src/ui/BusyWindow.cpp similarity index 100% rename from tools/auto-tester/src/ui/BusyWindow.cpp rename to tools/nitpick/src/ui/BusyWindow.cpp diff --git a/tools/auto-tester/src/ui/BusyWindow.h b/tools/nitpick/src/ui/BusyWindow.h similarity index 100% rename from tools/auto-tester/src/ui/BusyWindow.h rename to tools/nitpick/src/ui/BusyWindow.h diff --git a/tools/auto-tester/src/ui/BusyWindow.ui b/tools/nitpick/src/ui/BusyWindow.ui similarity index 100% rename from tools/auto-tester/src/ui/BusyWindow.ui rename to tools/nitpick/src/ui/BusyWindow.ui diff --git a/tools/auto-tester/src/ui/HelpWindow.cpp b/tools/nitpick/src/ui/HelpWindow.cpp similarity index 100% rename from tools/auto-tester/src/ui/HelpWindow.cpp rename to tools/nitpick/src/ui/HelpWindow.cpp diff --git a/tools/auto-tester/src/ui/HelpWindow.h b/tools/nitpick/src/ui/HelpWindow.h similarity index 100% rename from tools/auto-tester/src/ui/HelpWindow.h rename to tools/nitpick/src/ui/HelpWindow.h diff --git a/tools/auto-tester/src/ui/HelpWindow.ui b/tools/nitpick/src/ui/HelpWindow.ui similarity index 96% rename from tools/auto-tester/src/ui/HelpWindow.ui rename to tools/nitpick/src/ui/HelpWindow.ui index d2aa0da0d4..1ce6e8c321 100644 --- a/tools/auto-tester/src/ui/HelpWindow.ui +++ b/tools/nitpick/src/ui/HelpWindow.ui @@ -14,7 +14,7 @@ - AutoTester Help + Nitpick Help diff --git a/tools/auto-tester/src/ui/MismatchWindow.cpp b/tools/nitpick/src/ui/MismatchWindow.cpp similarity index 100% rename from tools/auto-tester/src/ui/MismatchWindow.cpp rename to tools/nitpick/src/ui/MismatchWindow.cpp diff --git a/tools/auto-tester/src/ui/MismatchWindow.h b/tools/nitpick/src/ui/MismatchWindow.h similarity index 100% rename from tools/auto-tester/src/ui/MismatchWindow.h rename to tools/nitpick/src/ui/MismatchWindow.h diff --git a/tools/auto-tester/src/ui/MismatchWindow.ui b/tools/nitpick/src/ui/MismatchWindow.ui similarity index 100% rename from tools/auto-tester/src/ui/MismatchWindow.ui rename to tools/nitpick/src/ui/MismatchWindow.ui diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/nitpick/src/ui/Nitpick.cpp similarity index 72% rename from tools/auto-tester/src/ui/AutoTester.cpp rename to tools/nitpick/src/ui/Nitpick.cpp index 32457c2224..201d6e562d 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/nitpick/src/ui/Nitpick.cpp @@ -1,5 +1,5 @@ // -// AutoTester.cpp +// Nitpick.cpp // zone/ambientLightInheritence // // Created by Nissim Hadar on 2 Nov 2017. @@ -8,14 +8,14 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "AutoTester.h" +#include "Nitpick.h" #ifdef Q_OS_WIN #include #include #endif -AutoTester::AutoTester(QWidget* parent) : QMainWindow(parent) { +Nitpick::Nitpick(QWidget* parent) : QMainWindow(parent) { _ui.setupUi(this); _ui.checkBoxInteractiveMode->setChecked(true); @@ -24,9 +24,9 @@ AutoTester::AutoTester(QWidget* parent) : QMainWindow(parent) { _signalMapper = new QSignalMapper(); - connect(_ui.actionClose, &QAction::triggered, this, &AutoTester::on_closeButton_clicked); - connect(_ui.actionAbout, &QAction::triggered, this, &AutoTester::about); - connect(_ui.actionContent, &QAction::triggered, this, &AutoTester::content); + connect(_ui.actionClose, &QAction::triggered, this, &Nitpick::on_closeButton_clicked); + connect(_ui.actionAbout, &QAction::triggered, this, &Nitpick::about); + connect(_ui.actionContent, &QAction::triggered, this, &Nitpick::content); // The second tab hides and shows the Windows task bar #ifndef Q_OS_WIN @@ -36,13 +36,13 @@ AutoTester::AutoTester(QWidget* parent) : QMainWindow(parent) { _ui.statusLabel->setText(""); _ui.plainTextEdit->setReadOnly(true); - setWindowTitle("Auto Tester - v6.7"); + setWindowTitle("Nitpick - v1.1"); - // Coming soon to an auto-tester near you... + // Coming soon to a nitpick near you... //// _helpWindow.textBrowser->setText() } -AutoTester::~AutoTester() { +Nitpick::~Nitpick() { delete _signalMapper; if (_test) { @@ -54,7 +54,7 @@ AutoTester::~AutoTester() { } } -void AutoTester::setup() { +void Nitpick::setup() { if (_test) { delete _test; } @@ -87,7 +87,7 @@ void AutoTester::setup() { _testRunner = new TestRunner(dayCheckboxes, timeEditCheckboxes, timeEdits, _ui.workingFolderLabel, _ui.checkBoxServerless, _ui.checkBoxRunLatest, _ui.urlLineEdit, _ui.runNowButton); } -void AutoTester::startTestsEvaluation(const bool isRunningFromCommandLine, +void Nitpick::startTestsEvaluation(const bool isRunningFromCommandLine, const bool isRunningInAutomaticTestRun, const QString& snapshotDirectory, const QString& branch, @@ -96,8 +96,13 @@ void AutoTester::startTestsEvaluation(const bool isRunningFromCommandLine, _test->startTestsEvaluation(isRunningFromCommandLine, isRunningInAutomaticTestRun, snapshotDirectory, branch, user); } -void AutoTester::on_tabWidget_currentChanged(int index) { +void Nitpick::on_tabWidget_currentChanged(int index) { +// Enable the GitHub edit boxes as required +#ifdef Q_OS_WIN if (index == 0 || index == 2 || index == 3) { +#else + if (index == 0 || index == 1 || index == 2) { +#endif _ui.userLineEdit->setDisabled(false); _ui.branchLineEdit->setDisabled(false); } else { @@ -106,73 +111,73 @@ void AutoTester::on_tabWidget_currentChanged(int index) { } } -void AutoTester::on_evaluateTestsButton_clicked() { +void Nitpick::on_evaluateTestsButton_clicked() { _test->startTestsEvaluation(false, false); } -void AutoTester::on_createRecursiveScriptButton_clicked() { +void Nitpick::on_createRecursiveScriptButton_clicked() { _test->createRecursiveScript(); } -void AutoTester::on_createAllRecursiveScriptsButton_clicked() { +void Nitpick::on_createAllRecursiveScriptsButton_clicked() { _test->createAllRecursiveScripts(); } -void AutoTester::on_createTestsButton_clicked() { +void Nitpick::on_createTestsButton_clicked() { _test->createTests(); } -void AutoTester::on_createMDFileButton_clicked() { +void Nitpick::on_createMDFileButton_clicked() { _test->createMDFile(); } -void AutoTester::on_createAllMDFilesButton_clicked() { +void Nitpick::on_createAllMDFilesButton_clicked() { _test->createAllMDFiles(); } -void AutoTester::on_createTestAutoScriptButton_clicked() { +void Nitpick::on_createTestAutoScriptButton_clicked() { _test->createTestAutoScript(); } -void AutoTester::on_createAllTestAutoScriptsButton_clicked() { +void Nitpick::on_createAllTestAutoScriptsButton_clicked() { _test->createAllTestAutoScripts(); } -void AutoTester::on_createTestsOutlineButton_clicked() { +void Nitpick::on_createTestsOutlineButton_clicked() { _test->createTestsOutline(); } -void AutoTester::on_createTestRailTestCasesButton_clicked() { +void Nitpick::on_createTestRailTestCasesButton_clicked() { _test->createTestRailTestCases(); } -void AutoTester::on_createTestRailRunButton_clicked() { +void Nitpick::on_createTestRailRunButton_clicked() { _test->createTestRailRun(); } -void AutoTester::on_setWorkingFolderButton_clicked() { +void Nitpick::on_setWorkingFolderButton_clicked() { _testRunner->setWorkingFolder(); } -void AutoTester::enableRunTabControls() { +void Nitpick::enableRunTabControls() { _ui.runNowButton->setEnabled(true); _ui.daysGroupBox->setEnabled(true); _ui.timesGroupBox->setEnabled(true); } -void AutoTester::on_runNowButton_clicked() { +void Nitpick::on_runNowButton_clicked() { _testRunner->run(); } -void AutoTester::on_checkBoxRunLatest_clicked() { +void Nitpick::on_checkBoxRunLatest_clicked() { _ui.urlLineEdit->setEnabled(!_ui.checkBoxRunLatest->isChecked()); } -void AutoTester::automaticTestRunEvaluationComplete(QString zippedFolderName, int numberOfFailures) { +void Nitpick::automaticTestRunEvaluationComplete(QString zippedFolderName, int numberOfFailures) { _testRunner->automaticTestRunEvaluationComplete(zippedFolderName, numberOfFailures); } -void AutoTester::on_updateTestRailRunResultsButton_clicked() { +void Nitpick::on_updateTestRailRunResultsButton_clicked() { _test->updateTestRailRunResult(); } @@ -180,7 +185,7 @@ void AutoTester::on_updateTestRailRunResultsButton_clicked() { // if (uState & ABS_AUTOHIDE) on_showTaskbarButton_clicked(); // else on_hideTaskbarButton_clicked(); // -void AutoTester::on_hideTaskbarButton_clicked() { +void Nitpick::on_hideTaskbarButton_clicked() { #ifdef Q_OS_WIN APPBARDATA abd = { sizeof abd }; UINT uState = (UINT)SHAppBarMessage(ABM_GETSTATE, &abd); @@ -190,7 +195,7 @@ void AutoTester::on_hideTaskbarButton_clicked() { #endif } -void AutoTester::on_showTaskbarButton_clicked() { +void Nitpick::on_showTaskbarButton_clicked() { #ifdef Q_OS_WIN APPBARDATA abd = { sizeof abd }; UINT uState = (UINT)SHAppBarMessage(ABM_GETSTATE, &abd); @@ -200,23 +205,23 @@ void AutoTester::on_showTaskbarButton_clicked() { #endif } -void AutoTester::on_closeButton_clicked() { +void Nitpick::on_closeButton_clicked() { exit(0); } -void AutoTester::on_createPythonScriptRadioButton_clicked() { +void Nitpick::on_createPythonScriptRadioButton_clicked() { _test->setTestRailCreateMode(PYTHON); } -void AutoTester::on_createXMLScriptRadioButton_clicked() { +void Nitpick::on_createXMLScriptRadioButton_clicked() { _test->setTestRailCreateMode(XML); } -void AutoTester::on_createWebPagePushButton_clicked() { +void Nitpick::on_createWebPagePushButton_clicked() { _test->createWebPage(_ui.updateAWSCheckBox, _ui.awsURLLineEdit); } -void AutoTester::downloadFile(const QUrl& url) { +void Nitpick::downloadFile(const QUrl& url) { _downloaders.emplace_back(new Downloader(url, this)); connect(_downloaders[_index], SIGNAL(downloaded()), _signalMapper, SLOT(map())); @@ -225,7 +230,7 @@ void AutoTester::downloadFile(const QUrl& url) { ++_index; } -void AutoTester::downloadFiles(const QStringList& URLs, const QString& directoryName, const QStringList& filenames, void *caller) { +void Nitpick::downloadFiles(const QStringList& URLs, const QString& directoryName, const QStringList& filenames, void *caller) { connect(_signalMapper, SIGNAL(mapped(int)), this, SLOT(saveFile(int))); _directoryName = directoryName; @@ -251,7 +256,7 @@ void AutoTester::downloadFiles(const QStringList& URLs, const QString& directory } } -void AutoTester::saveFile(int index) { +void Nitpick::saveFile(int index) { try { QFile file(_directoryName + "/" + _filenames[index]); file.open(QIODevice::WriteOnly); @@ -277,34 +282,34 @@ void AutoTester::saveFile(int index) { } } -void AutoTester::about() { +void Nitpick::about() { QMessageBox::information(0, "About", QString("Built ") + __DATE__ + ", " + __TIME__); } -void AutoTester::content() { +void Nitpick::content() { _helpWindow.show(); } -void AutoTester::setUserText(const QString& user) { +void Nitpick::setUserText(const QString& user) { _ui.userLineEdit->setText(user); } -QString AutoTester::getSelectedUser() { +QString Nitpick::getSelectedUser() { return _ui.userLineEdit->text(); } -void AutoTester::setBranchText(const QString& branch) { +void Nitpick::setBranchText(const QString& branch) { _ui.branchLineEdit->setText(branch); } -QString AutoTester::getSelectedBranch() { +QString Nitpick::getSelectedBranch() { return _ui.branchLineEdit->text(); } -void AutoTester::updateStatusLabel(const QString& status) { +void Nitpick::updateStatusLabel(const QString& status) { _ui.statusLabel->setText(status); } -void AutoTester::appendLogWindow(const QString& message) { +void Nitpick::appendLogWindow(const QString& message) { _ui.plainTextEdit->appendPlainText(message); -} \ No newline at end of file +} diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/nitpick/src/ui/Nitpick.h similarity index 92% rename from tools/auto-tester/src/ui/AutoTester.h rename to tools/nitpick/src/ui/Nitpick.h index 429a8b60e1..21b917654b 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/nitpick/src/ui/Nitpick.h @@ -1,5 +1,5 @@ // -// AutoTester.h +// Nitpick.h // // Created by Nissim Hadar on 2 Nov 2017. // Copyright 2013 High Fidelity, Inc. @@ -7,13 +7,13 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_AutoTester_h -#define hifi_AutoTester_h +#ifndef hifi_Nitpick_h +#define hifi_Nitpick_h #include #include #include -#include "ui_AutoTester.h" +#include "ui_Nitpick.h" #include "../Downloader.h" #include "../Test.h" @@ -22,12 +22,12 @@ #include "../TestRunner.h" #include "../AWSInterface.h" -class AutoTester : public QMainWindow { +class Nitpick : public QMainWindow { Q_OBJECT public: - AutoTester(QWidget* parent = Q_NULLPTR); - ~AutoTester(); + Nitpick(QWidget* parent = Q_NULLPTR); + ~Nitpick(); void setup(); @@ -95,7 +95,7 @@ private slots: void content(); private: - Ui::AutoTesterClass _ui; + Ui::NitpickClass _ui; Test* _test{ nullptr }; TestRunner* _testRunner{ nullptr }; @@ -121,4 +121,4 @@ private: void* _caller; }; -#endif // hifi_AutoTester_h \ No newline at end of file +#endif // hifi_Nitpick_h \ No newline at end of file diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/nitpick/src/ui/Nitpick.ui similarity index 98% rename from tools/auto-tester/src/ui/AutoTester.ui rename to tools/nitpick/src/ui/Nitpick.ui index b277fbdb2a..5e20e75553 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/nitpick/src/ui/Nitpick.ui @@ -1,7 +1,7 @@ - AutoTesterClass - + NitpickClass + 0 @@ -17,7 +17,7 @@ - AutoTester + Nitpick @@ -198,7 +198,7 @@ 10 160 161 - 28 + 51 @@ -525,7 +525,7 @@ 128 95 - 21 + 31 31 @@ -539,7 +539,7 @@ - 160 + 170 100 451 21 @@ -554,9 +554,9 @@ - 200 + 190 180 - 120 + 131 20 @@ -572,8 +572,8 @@ 330 170 - 101 - 40 + 181 + 51 @@ -684,10 +684,10 @@ - 240 + 270 30 160 - 40 + 51 @@ -699,7 +699,7 @@ 150 42 - 81 + 111 17 @@ -803,7 +803,7 @@ 0 0 720 - 21 + 22 diff --git a/tools/auto-tester/src/ui/TestRailResultsSelectorWindow.cpp b/tools/nitpick/src/ui/TestRailResultsSelectorWindow.cpp similarity index 100% rename from tools/auto-tester/src/ui/TestRailResultsSelectorWindow.cpp rename to tools/nitpick/src/ui/TestRailResultsSelectorWindow.cpp diff --git a/tools/auto-tester/src/ui/TestRailResultsSelectorWindow.h b/tools/nitpick/src/ui/TestRailResultsSelectorWindow.h similarity index 100% rename from tools/auto-tester/src/ui/TestRailResultsSelectorWindow.h rename to tools/nitpick/src/ui/TestRailResultsSelectorWindow.h diff --git a/tools/auto-tester/src/ui/TestRailResultsSelectorWindow.ui b/tools/nitpick/src/ui/TestRailResultsSelectorWindow.ui similarity index 100% rename from tools/auto-tester/src/ui/TestRailResultsSelectorWindow.ui rename to tools/nitpick/src/ui/TestRailResultsSelectorWindow.ui diff --git a/tools/auto-tester/src/ui/TestRailRunSelectorWindow.cpp b/tools/nitpick/src/ui/TestRailRunSelectorWindow.cpp similarity index 100% rename from tools/auto-tester/src/ui/TestRailRunSelectorWindow.cpp rename to tools/nitpick/src/ui/TestRailRunSelectorWindow.cpp diff --git a/tools/auto-tester/src/ui/TestRailRunSelectorWindow.h b/tools/nitpick/src/ui/TestRailRunSelectorWindow.h similarity index 100% rename from tools/auto-tester/src/ui/TestRailRunSelectorWindow.h rename to tools/nitpick/src/ui/TestRailRunSelectorWindow.h diff --git a/tools/auto-tester/src/ui/TestRailRunSelectorWindow.ui b/tools/nitpick/src/ui/TestRailRunSelectorWindow.ui similarity index 100% rename from tools/auto-tester/src/ui/TestRailRunSelectorWindow.ui rename to tools/nitpick/src/ui/TestRailRunSelectorWindow.ui diff --git a/tools/auto-tester/src/ui/TestRailTestCasesSelectorWindow.cpp b/tools/nitpick/src/ui/TestRailTestCasesSelectorWindow.cpp similarity index 100% rename from tools/auto-tester/src/ui/TestRailTestCasesSelectorWindow.cpp rename to tools/nitpick/src/ui/TestRailTestCasesSelectorWindow.cpp diff --git a/tools/auto-tester/src/ui/TestRailTestCasesSelectorWindow.h b/tools/nitpick/src/ui/TestRailTestCasesSelectorWindow.h similarity index 100% rename from tools/auto-tester/src/ui/TestRailTestCasesSelectorWindow.h rename to tools/nitpick/src/ui/TestRailTestCasesSelectorWindow.h diff --git a/tools/auto-tester/src/ui/TestRailTestCasesSelectorWindow.ui b/tools/nitpick/src/ui/TestRailTestCasesSelectorWindow.ui similarity index 100% rename from tools/auto-tester/src/ui/TestRailTestCasesSelectorWindow.ui rename to tools/nitpick/src/ui/TestRailTestCasesSelectorWindow.ui diff --git a/tools/skeleton-dump/src/SkeletonDumpApp.cpp b/tools/skeleton-dump/src/SkeletonDumpApp.cpp index 10b13aef36..42a1c78090 100644 --- a/tools/skeleton-dump/src/SkeletonDumpApp.cpp +++ b/tools/skeleton-dump/src/SkeletonDumpApp.cpp @@ -12,7 +12,7 @@ #include "SkeletonDumpApp.h" #include #include -#include +#include #include SkeletonDumpApp::SkeletonDumpApp(int argc, char* argv[]) : QCoreApplication(argc, argv) { @@ -54,7 +54,7 @@ SkeletonDumpApp::SkeletonDumpApp(int argc, char* argv[]) : QCoreApplication(argc return; } QByteArray blob = file.readAll(); - std::unique_ptr geometry(readFBX(blob, QVariantHash())); + HFMModel::Pointer geometry = FBXSerializer().read(blob, QVariantHash()); std::unique_ptr skeleton(new AnimSkeleton(*geometry)); skeleton->dump(verbose); } diff --git a/tools/vhacd-util/src/VHACDUtil.cpp b/tools/vhacd-util/src/VHACDUtil.cpp index 8de9c39da9..9401da4314 100644 --- a/tools/vhacd-util/src/VHACDUtil.cpp +++ b/tools/vhacd-util/src/VHACDUtil.cpp @@ -15,9 +15,11 @@ #include #include +#include +#include -// FBXReader jumbles the order of the meshes by reading them back out of a hashtable. This will put +// FBXSerializer jumbles the order of the meshes by reading them back out of a hashtable. This will put // them back in the order in which they appeared in the file. bool HFMModelLessThan(const HFMMesh& e1, const HFMMesh& e2) { return e1.meshIndex < e2.meshIndex; @@ -43,10 +45,9 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) { QByteArray fbxContents = fbx.readAll(); HFMModel::Pointer hfmModel; if (filename.toLower().endsWith(".obj")) { - bool combineParts = false; - hfmModel = OBJReader().readOBJ(fbxContents, QVariantHash(), combineParts); + hfmModel = OBJSerializer().read(fbxContents, QVariantHash(), filename); } else if (filename.toLower().endsWith(".fbx")) { - hfmModel.reset(readFBX(fbxContents, QVariantHash(), filename)); + hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), filename); } else { qWarning() << "file has unknown extension" << filename; return false; diff --git a/tools/vhacd-util/src/VHACDUtil.h b/tools/vhacd-util/src/VHACDUtil.h index dd8f606756..0fb70e8af7 100644 --- a/tools/vhacd-util/src/VHACDUtil.h +++ b/tools/vhacd-util/src/VHACDUtil.h @@ -18,10 +18,10 @@ #include #include //c++11 feature #include -#include -#include #include +#include + namespace vhacd { class VHACDUtil { public: diff --git a/tools/vhacd-util/src/VHACDUtilApp.h b/tools/vhacd-util/src/VHACDUtilApp.h index 7dadad20b3..1cbb29bb88 100644 --- a/tools/vhacd-util/src/VHACDUtilApp.h +++ b/tools/vhacd-util/src/VHACDUtilApp.h @@ -15,7 +15,7 @@ #include -#include +#include const int VHACD_RETURN_CODE_FAILURE_TO_READ = 1; const int VHACD_RETURN_CODE_FAILURE_TO_WRITE = 2;