diff --git a/.eslintrc.js b/.eslintrc.js index 631d17a792..f778512ac9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -42,7 +42,6 @@ module.exports = { "EventBridge": false, "FaceTracker": false, "GlobalServices": false, - "GooglePoly": false, "Graphics": false, "HifiAbout": false, "HMD": false, diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4ff848fabe..b9b496e496 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -232,7 +232,6 @@ #include #include -#include #include #include @@ -906,7 +905,6 @@ bool setupEssentials(const QCommandLineParser& parser, bool runningMarkerExisted auto entityScriptServerLog = DependencyManager::get(); QObject::connect(scriptEngines.data(), &ScriptEngines::requestingEntityScriptServerLog, entityScriptServerLog.data(), &EntityScriptServerLogClient::requestMessagesForScriptEngines); - DependencyManager::set(); DependencyManager::set(nullptr, qApp->getOcteeSceneStats()); DependencyManager::set(); DependencyManager::set(); @@ -4083,11 +4081,8 @@ bool Application::importFromZIP(const QString& filePath) { qDebug() << "A zip file has been dropped in: " << filePath; QUrl empty; // handle Blocks download from Marketplace - if (filePath.contains("poly.google.com/downloads")) { - addAssetToWorldFromURL(filePath); - } else { - qApp->getFileDownloadInterface()->runUnzip(filePath, empty, true, true, false); - } + qApp->getFileDownloadInterface()->runUnzip(filePath, empty, true, true, false); + return true; } @@ -7657,8 +7652,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptManagerPoint scriptEngine->registerGlobalObject("UserActivityLogger", DependencyManager::get().data()); scriptEngine->registerGlobalObject("Users", DependencyManager::get().data()); - //scriptEngine->registerGlobalObject("GooglePoly", DependencyManager::get().data()); - if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) { scriptEngine->registerGlobalObject("Steam", new SteamScriptingInterface(scriptManager.get(), steamClient.get())); } @@ -7984,15 +7977,6 @@ void Application::addAssetToWorldFromURL(QString url) { if (url.contains("filename")) { filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL. } - if (url.contains("poly.google.com/downloads")) { - filename = url.section('/', -1); - if (url.contains("noDownload")) { - filename.remove(".zip?noDownload=false"); - } else { - filename.remove(".zip"); - } - - } if (!DependencyManager::get()->getThisNodeCanWriteAssets()) { QString errorInfo = "You do not have permissions to write to the Asset Server."; @@ -8021,15 +8005,6 @@ void Application::addAssetToWorldFromURLRequestFinished() { if (url.contains("filename")) { filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL. } - if (url.contains("poly.google.com/downloads")) { - filename = url.section('/', -1); - if (url.contains("noDownload")) { - filename.remove(".zip?noDownload=false"); - } else { - filename.remove(".zip"); - } - isBlocks = true; - } if (result == ResourceRequest::Success) { QTemporaryDir temporaryDir; diff --git a/interface/src/scripting/GooglePolyScriptingInterface.cpp b/interface/src/scripting/GooglePolyScriptingInterface.cpp deleted file mode 100644 index ba4afaba27..0000000000 --- a/interface/src/scripting/GooglePolyScriptingInterface.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// -// GooglePolyScriptingInterface.cpp -// interface/src/scripting -// -// Created by Elisa Lupin-Jimenez on 12/3/2017. -// 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 -// - -#include "GooglePolyScriptingInterface.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ScriptEngineLogging.h" - -const QString LIST_POLY_URL = "https://poly.googleapis.com/v1/assets?"; -const QString GET_POLY_URL = "https://poly.googleapis.com/v1/assets/model?"; - -const QStringList VALID_FORMATS = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << ""; -const QStringList VALID_CATEGORIES = QStringList() << "animals" << "architecture" << "art" << "food" << - "nature" << "objects" << "people" << "scenes" << "technology" << "transport" << ""; - -GooglePolyScriptingInterface::GooglePolyScriptingInterface() { - // nothing to be implemented -} - -void GooglePolyScriptingInterface::setAPIKey(const QString& key) { - _authCode = key; -} - -QString GooglePolyScriptingInterface::getAssetList(const QString& keyword, const QString& category, const QString& format) { - QUrl url = formatURLQuery(keyword, category, format); - if (!url.isEmpty()) { - QByteArray json = parseJSON(url, 0).toJsonDocument().toJson(); - return (QString) json; - } else { - qCDebug(scriptengine) << "Invalid filters were specified."; - return ""; - } -} - -QString GooglePolyScriptingInterface::getFBX(const QString& keyword, const QString& category) { - QUrl url = formatURLQuery(keyword, category, "FBX"); - return getModelURL(url); -} - -QString GooglePolyScriptingInterface::getOBJ(const QString& keyword, const QString& category) { - QUrl url = formatURLQuery(keyword, category, "OBJ"); - return getModelURL(url); -} - -QString GooglePolyScriptingInterface::getBlocks(const QString& keyword, const QString& category) { - QUrl url = formatURLQuery(keyword, category, "BLOCKS"); - return getModelURL(url); -} - -QString GooglePolyScriptingInterface::getGLTF(const QString& keyword, const QString& category) { - QUrl url = formatURLQuery(keyword, category, "GLTF"); - return getModelURL(url); -} - -QString GooglePolyScriptingInterface::getGLTF2(const QString& keyword, const QString& category) { - QUrl url = formatURLQuery(keyword, category, "GLTF2"); - return getModelURL(url); -} - -// This method will not be useful until we support Tilt models -QString GooglePolyScriptingInterface::getTilt(const QString& keyword, const QString& category) { - QUrl url = formatURLQuery(keyword, category, "TILT"); - return getModelURL(url); -} - -// Can provide asset name or full URL to model -QString GooglePolyScriptingInterface::getModelInfo(const QString& input) { - QString name(input); - if (input.contains("poly.googleapis") || input.contains("poly.google.com")) { - QStringList list = input.split("/"); - if (input.contains("poly.googleapis")) { - name = list[4]; - } else { - name = list.last(); - } - } - QString urlString(GET_POLY_URL); - urlString = urlString.replace("model", name) + "key=" + _authCode; - qCDebug(scriptengine) << "Google URL request"; - QUrl url(urlString); - QString json = parseJSON(url, 2).toString(); - return json; -} - -int GooglePolyScriptingInterface::getRandIntInRange(int length) { - return QRandomGenerator::global()->bounded(length); -} - -QUrl GooglePolyScriptingInterface::formatURLQuery(const QString& keyword, const QString& category, const QString& format) { - QString queries; - if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) { - return QUrl(""); - } else { - if (!keyword.isEmpty()) { - QString keywords(keyword); - keywords.replace(" ", "+"); - queries.append("&keywords=" + keywords); - } - if (!category.isEmpty()) { - queries.append("&category=" + category); - } - if (!format.isEmpty()) { - queries.append("&format=" + format); - } - QString urlString(LIST_POLY_URL + "key=" + _authCode + queries); - return QUrl(urlString); - } -} - -QString GooglePolyScriptingInterface::getModelURL(const QUrl& url) { - qCDebug(scriptengine) << "Google URL request"; - if (!url.isEmpty()) { - return parseJSON(url, 1).toString(); - } else { - qCDebug(scriptengine) << "Invalid filters were specified."; - return ""; - } -} - -// FIXME: synchronous -QByteArray GooglePolyScriptingInterface::getHTTPRequest(const QUrl& url) { - QNetworkAccessManager manager; - QNetworkReply *response = manager.get(QNetworkRequest(url)); - QEventLoop event; - connect(response, SIGNAL(finished()), &event, SLOT(quit())); - event.exec(); - - return response->readAll(); -} - -// 0 = asset list, 1 = model from asset list, 2 = specific model -QVariant GooglePolyScriptingInterface::parseJSON(const QUrl& url, int fileType) { - QByteArray jsonString = getHTTPRequest(url); - QJsonDocument doc = QJsonDocument::fromJson(jsonString); - QJsonObject obj = doc.object(); - if (obj.isEmpty()) { - qCDebug(scriptengine) << "Assets with specified filters not found"; - return ""; - } - if (obj.keys().first() == "error") { - QString error = obj.value("error").toObject().value("message").toString(); - qCDebug(scriptengine) << error; - return ""; - } - if (fileType == 0 || fileType == 1) { - QJsonArray arr = obj.value("assets").toArray(); - // return model url - if (fileType == 1) { - int random = getRandIntInRange(arr.size()); - QJsonObject json = arr.at(random).toObject(); - // nested JSONs - return json.value("formats").toArray().at(0).toObject().value("root").toObject().value("url"); - } - // return whole asset list - return QJsonDocument(arr); - // return specific object - } else { - return jsonString; - } -} diff --git a/interface/src/scripting/GooglePolyScriptingInterface.h b/interface/src/scripting/GooglePolyScriptingInterface.h deleted file mode 100644 index 693b07f18e..0000000000 --- a/interface/src/scripting/GooglePolyScriptingInterface.h +++ /dev/null @@ -1,116 +0,0 @@ -// -// GooglePolyScriptingInterface.h -// interface/src/scripting -// -// Created by Elisa Lupin-Jimenez on 12/3/2017. -// 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 -// - -#ifndef hifi_GooglePolyScriptingInterface_h -#define hifi_GooglePolyScriptingInterface_h - -#include -#include - -/*@jsdoc - * The GooglePoly API allows you to interact with Google Poly models direct from inside High Fidelity. - * @namespace GooglePoly - * - * @hifi-interface - * @hifi-client-entity - * @hifi-avatar - */ - -class GooglePolyScriptingInterface : public QObject, public Dependency { - Q_OBJECT - -public: - GooglePolyScriptingInterface(); - -public slots: - - /*@jsdoc - * @function GooglePoly.setAPIKey - * @param {string} key - */ - void setAPIKey(const QString& key); - - /*@jsdoc - * @function GooglePoly.getAssetList - * @param {string} keyword - * @param {string} category - * @param {string} format - * @returns {string} - */ - QString getAssetList(const QString& keyword, const QString& category, const QString& format); - - /*@jsdoc - * @function GooglePoly.getFBX - * @param {string} keyword - * @param {string} category - * @returns {string} - */ - QString getFBX(const QString& keyword, const QString& category); - - /*@jsdoc - * @function GooglePoly.getOBJ - * @param {string} keyword - * @param {string} category - * @returns {string} - */ - QString getOBJ(const QString& keyword, const QString& category); - - /*@jsdoc - * @function GooglePoly.getBlocks - * @param {string} keyword - * @param {string} category - * @returns {string} - */ - QString getBlocks(const QString& keyword, const QString& category); - - /*@jsdoc - * @function GooglePoly.getGLTF - * @param {string} keyword - * @param {string} category - * @returns {string} - */ - QString getGLTF(const QString& keyword, const QString& category); - - /*@jsdoc - * @function GooglePoly.getGLTF2 - * @param {string} keyword - * @param {string} category - * @returns {string} - */ - QString getGLTF2(const QString& keyword, const QString& category); - - /*@jsdoc - * @function GooglePoly.getTilt - * @param {string} keyword - * @param {string} category - * @returns {string} - */ - QString getTilt(const QString& keyword, const QString& category); - - /*@jsdoc - * @function GooglePoly.getModelInfo - * @param {string} input - * @returns {string} - */ - QString getModelInfo(const QString& input); - -private: - QString _authCode; - - QUrl formatURLQuery(const QString& keyword, const QString& category, const QString& format); - QString getModelURL(const QUrl& url); - QByteArray getHTTPRequest(const QUrl& url); - QVariant parseJSON(const QUrl& url, int fileType); - int getRandIntInRange(int length); - -}; - -#endif // hifi_GooglePolyScriptingInterface_h