Showing the changes to interface/src/scripting/GooglePolyScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -25,11 +25,11 @@ · 24 unmodified lines | ||
| 25 | 25 | #include "GooglePolyScriptingInterface.h" |
| 26 | 26 | #include "ScriptEngineLogging.h" |
| 27 | 27 | |
| 28 | −const QString listPolyUrl = "https://poly.googleapis.com/v1/assets?"; | |
| 29 | −const QString getPolyUrl = "https://poly.googleapis.com/v1/assets/model?"; | |
| 28 | +const QString LIST_POLY_URL = "https://poly.googleapis.com/v1/assets?"; | |
| 29 | +const QString GET_POLY_URL = "https://poly.googleapis.com/v1/assets/model?"; | |
| 30 | 30 | |
| 31 | −const QStringList validFormats = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << ""; | |
| 32 | −const QStringList validCategories = QStringList() << "animals" << "architecture" << "art" << "food" << | |
| 31 | +const QStringList VALID_FORMATS = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << ""; | |
| 32 | +const QStringList VALID_CATEGORIES = QStringList() << "animals" << "architecture" << "art" << "food" << | |
| 33 | 33 | "nature" << "objects" << "people" << "scenes" << "technology" << "transport" << ""; |
| 34 | 34 | |
| 35 | 35 | GooglePolyScriptingInterface::GooglePolyScriptingInterface() { |
| @@ -75,22 +75,24 @@ QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category · 39 unmodified lines | ||
| 75 | 75 | QUrl url = formatURLQuery(keyword, category, "GLTF2"); |
| 76 | 76 | return getModelURL(url); |
| 77 | 77 | } |
| 78 | − | |
| 79 | −/* | |
| 80 | −// This method will not work until we support Tilt models | |
| 78 | + | |
| 79 | +// This method will not be useful until we support Tilt models | |
| 81 | 80 | QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) { |
| 82 | 81 | QUrl url = formatURLQuery(keyword, category, "TILT"); |
| 83 | 82 | return getModelURL(url); |
| 84 | 83 | } |
| 85 | −*/ | |
| 86 | 84 | |
| 87 | 85 | // Can provide asset name or full URL to model |
| 88 | 86 | QString GooglePolyScriptingInterface::getModelInfo(QString name) { |
| 89 | 87 | if (name.contains("poly.googleapis") || name.contains("poly.google.com")) { |
| 90 | 88 | QStringList list = name.split("/"); |
| 91 | − name = list[4]; | |
| 89 | + if (name.contains("poly.googleapis")) { | |
| 90 | + name = list[4]; | |
| 91 | + } else { | |
| 92 | + name = list.last(); | |
| 93 | + } | |
| 92 | 94 | } |
| 93 | − QString urlString = QString(getPolyUrl); | |
| 95 | + QString urlString(GET_POLY_URL); | |
| 94 | 96 | urlString = urlString.replace("model", name) + "key=" + authCode; |
| 95 | 97 | qCDebug(scriptengine) << "Google URL request: " << urlString; |
| 96 | 98 | QUrl url(urlString); |
| @@ -106,7 +108,7 @@ int GooglePolyScriptingInterface::getRandIntInRange(int length) { · 9 unmodified lines | ||
| 106 | 108 | |
| 107 | 109 | QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) { |
| 108 | 110 | QString queries; |
| 109 | − if (!validFormats.contains(format, Qt::CaseInsensitive) || !validCategories.contains(category, Qt::CaseInsensitive)) { | |
| 111 | + if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) { | |
| 110 | 112 | return QUrl(""); |
| 111 | 113 | } else { |
| 112 | 114 | if (!keyword.isEmpty()) { |
| @@ -119,7 +121,7 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 6 unmodified lines | ||
| 119 | 121 | if (!format.isEmpty()) { |
| 120 | 122 | queries.append("&format=" + format); |
| 121 | 123 | } |
| 122 | − QString urlString = QString(listPolyUrl + "key=" + authCode + queries); | |
| 124 | + QString urlString = QString(LIST_POLY_URL + "key=" + authCode + queries); | |
| 123 | 125 | return QUrl(urlString); |
| 124 | 126 | } |
| 125 | 127 | } |
| @@ -147,7 +149,6 @@ QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) { · 21 unmodified lines | ||
| 147 | 149 | |
| 148 | 150 | // 0 = asset list, 1 = model from asset list, 2 = specific model |
| 149 | 151 | QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) { |
| 150 | − //QString firstItem = QString::fromUtf8(response->readAll()); | |
| 151 | 152 | QByteArray jsonString = getHTTPRequest(url); |
| 152 | 153 | QJsonDocument doc = QJsonDocument::fromJson(jsonString); |
| 153 | 154 | QJsonObject obj = doc.object(); |