From ca6a323d541dc7311054090acf4df784ebbc05d3 Mon Sep 17 00:00:00 2001 From: Elisa Lupin-Jimenez Date: Wed, 26 Jul 2017 15:21:39 -0700 Subject: [PATCH] Can drag blocks zip folder into hifi and upload the .obj --- interface/src/Application.cpp | 19 ++++++- interface/src/Application.h | 3 ++ .../src/FileScriptingInterface.cpp | 50 +++++++++++-------- .../src/FileScriptingInterface.h | 2 +- scripts/system/html/js/marketplacesInject.js | 24 +++++++-- scripts/system/html/marketplaces.html | 36 ++++++++----- 6 files changed, 96 insertions(+), 38 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 549e5338a0..4fa973f68c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -230,6 +230,9 @@ static const QString OBJ_EXTENSION = ".obj"; static const QString AVA_JSON_EXTENSION = ".ava.json"; static const QString WEB_VIEW_TAG = "noDownload=true"; +// temporary zip handling for Emily +static const QString ZIP_EXTENSION = ".zip"; + static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f; static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND; @@ -260,7 +263,10 @@ const QHash Application::_acceptedExtensi { AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl }, { JSON_EXTENSION, &Application::importJSONFromURL }, { JS_EXTENSION, &Application::askToLoadScript }, - { FST_EXTENSION, &Application::askToSetAvatarUrl } + { FST_EXTENSION, &Application::askToSetAvatarUrl }, + + // temporary zip handling for Emily + { ZIP_EXTENSION, &Application::importFromZIP } }; class DeadlockWatchdogThread : public QThread { @@ -2779,6 +2785,15 @@ void Application::onPresent(quint32 frameCount) { } } +bool Application::importFromZIP(const QString& filePath) { + qDebug() << "A zip file has been dropped in: " << filePath; + QUrl empty = ""; + qApp->getFileDownloadInterface()->runUnzip(filePath, empty, false, true); + return true; +} + +bool _renderRequested { false }; + bool Application::event(QEvent* event) { if (!Menu::getInstance()) { return false; @@ -6218,7 +6233,7 @@ void Application::addAssetToWorldFromURLRequestFinished() { if (tempFile.open(QIODevice::WriteOnly)) { tempFile.write(request->getData()); addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key. - qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true); + qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false); } else { QString errorInfo = "Couldn't open temporary file for download"; qWarning(interfaceapp) << errorInfo; diff --git a/interface/src/Application.h b/interface/src/Application.h index 300bd4ac02..dcd1a9a532 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -482,6 +482,9 @@ private: bool importJSONFromURL(const QString& urlString); bool importSVOFromURL(const QString& urlString); + // temporary zip handling for Emily + bool importFromZIP(const QString& filePath); + bool nearbyEntitiesAreReadyForPhysics(); int processOctreeStats(ReceivedMessage& message, SharedNodePointer sendingNode); void trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket); diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index 30d0a3a201..7d8458598d 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -32,12 +32,19 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent // nothing for now } -void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { +void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks) { qCDebug(scriptengine) << "Url that was downloaded: " + url.toString(); qCDebug(scriptengine) << "Path where download is saved: " + path; QString fileName = "/" + path.section("/", -1); QString tempDir = path; - tempDir.remove(fileName); + if (!isBlocks) { + tempDir.remove(fileName); + } else { + QTemporaryDir blocks; + tempDir = blocks.path(); + path.remove("file:///"); + } + qCDebug(scriptengine) << "Temporary directory at: " + tempDir; if (!isTempDir(tempDir)) { qCDebug(scriptengine) << "Temporary directory mismatch; risk of losing files"; @@ -45,6 +52,7 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { } QString file = unzipFile(path, tempDir); + qCDebug(scriptengine) << "Unzipped file: " << file; QString filename = QUrl::fromLocalFile(file).toString(); if (file != "") { qCDebug(scriptengine) << "File to upload: " + filename; @@ -54,6 +62,26 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { emit unzipResult(path, filename, autoAdd); } +QString FileScriptingInterface::unzipFile(QString path, QString tempDir) { + + QDir dir(path); + QString dirName = dir.path(); + qCDebug(scriptengine) << "Directory to unzip: " << dirName; + QString target = tempDir + "/model_repo"; + QStringList list = JlCompress::extractDir(dirName, target); + + qCDebug(scriptengine) << list; + + if (!list.isEmpty()) { + return list.front(); + } + else { + qCDebug(scriptengine) << "Extraction failed"; + return ""; + } + +} + // fix to check that we are only referring to a temporary directory bool FileScriptingInterface::isTempDir(QString tempDir) { QString folderName = "/" + tempDir.section("/", -1); @@ -92,24 +120,6 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { request->send(); } -QString FileScriptingInterface::unzipFile(QString path, QString tempDir) { - - QDir dir(path); - QString dirName = dir.path(); - QString target = tempDir + "/model_repo"; - QStringList list = JlCompress::extractDir(dirName, target); - - qCDebug(scriptengine) << list; - - if (!list.isEmpty()) { - return list.front(); - } else { - qCDebug(scriptengine) << "Extraction failed"; - return ""; - } - -} - // this function is not in use void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) { /*if (!file.isDir()) { diff --git a/libraries/script-engine/src/FileScriptingInterface.h b/libraries/script-engine/src/FileScriptingInterface.h index 5e9a6029e8..dc5ffdace8 100644 --- a/libraries/script-engine/src/FileScriptingInterface.h +++ b/libraries/script-engine/src/FileScriptingInterface.h @@ -24,7 +24,7 @@ public: public slots: QString convertUrlToPath(QUrl url); - void runUnzip(QString path, QUrl url, bool autoAdd); + void runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks); QString getTempDir(); signals: diff --git a/scripts/system/html/js/marketplacesInject.js b/scripts/system/html/js/marketplacesInject.js index 45b2e99018..0ee337a2ef 100644 --- a/scripts/system/html/js/marketplacesInject.js +++ b/scripts/system/html/js/marketplacesInject.js @@ -33,8 +33,8 @@ $("head").append( '' + ); + } + function updateClaraCode() { // Have to repeatedly update Clara page because its content can change dynamically without location.href changing. @@ -322,10 +335,12 @@ var DIRECTORY = 0; var HIFI = 1; - var CLARA = 2; + var BLOCKS = 2; + var CLARA = 3; var pageType = DIRECTORY; if (location.href.indexOf("highfidelity.com/") !== -1) { pageType = HIFI; } + if (location.href.indexOf("google.com/") !== -1) { pageType = BLOCKS; } if (location.href.indexOf("clara.io/") !== -1) { pageType = CLARA; } injectCommonCode(pageType === DIRECTORY); @@ -336,6 +351,9 @@ case HIFI: injectHiFiCode(); break; + case BLOCKS: + injectBlocksCode(); + break; case CLARA: injectClaraCode(); break; diff --git a/scripts/system/html/marketplaces.html b/scripts/system/html/marketplaces.html index 6051a9df96..8c5fe15429 100644 --- a/scripts/system/html/marketplaces.html +++ b/scripts/system/html/marketplaces.html @@ -30,19 +30,31 @@
-
-
- +
+
+
+ +
+
+

Blocks, released by Google, allows anyone to create 3D models using just a few simple tools. Browse through other users' creations for low-poly assets to add to your world.

+
+
-
-

Clara.io has thousands of models available for importing into High Fidelity. Follow these steps for the best experience:

-
    -
  1. Create an account here or log in as an existing user.
  2. -
  3. Choose a model from the list and click “Download to High Fidelity”.
  4. -
-
- -
+
+
+
+
+
+ +
+
+

Clara.io has thousands of models available for importing into High Fidelity. Follow these steps for the best experience:

+
    +
  1. Create an account here or log in as an existing user.
  2. +
  3. Choose a model from the list and click “Download to High Fidelity”.
  4. +
+
+