mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 17:24:58 +02:00
fixed constant names, added another URL check
This commit is contained in:
parent
03f06aadf4
commit
01c1032540
3 changed files with 17 additions and 16 deletions
Binary file not shown.
|
@ -25,11 +25,11 @@
|
||||||
#include "GooglePolyScriptingInterface.h"
|
#include "GooglePolyScriptingInterface.h"
|
||||||
#include "ScriptEngineLogging.h"
|
#include "ScriptEngineLogging.h"
|
||||||
|
|
||||||
const QString listPolyUrl = "https://poly.googleapis.com/v1/assets?";
|
const QString LIST_POLY_URL = "https://poly.googleapis.com/v1/assets?";
|
||||||
const QString getPolyUrl = "https://poly.googleapis.com/v1/assets/model?";
|
const QString GET_POLY_URL = "https://poly.googleapis.com/v1/assets/model?";
|
||||||
|
|
||||||
const QStringList validFormats = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << "";
|
const QStringList VALID_FORMATS = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << "";
|
||||||
const QStringList validCategories = QStringList() << "animals" << "architecture" << "art" << "food" <<
|
const QStringList VALID_CATEGORIES = QStringList() << "animals" << "architecture" << "art" << "food" <<
|
||||||
"nature" << "objects" << "people" << "scenes" << "technology" << "transport" << "";
|
"nature" << "objects" << "people" << "scenes" << "technology" << "transport" << "";
|
||||||
|
|
||||||
GooglePolyScriptingInterface::GooglePolyScriptingInterface() {
|
GooglePolyScriptingInterface::GooglePolyScriptingInterface() {
|
||||||
|
@ -76,21 +76,23 @@ QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// This method will not be useful until we support Tilt models
|
||||||
// This method will not work until we support Tilt models
|
|
||||||
QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {
|
QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {
|
||||||
QUrl url = formatURLQuery(keyword, category, "TILT");
|
QUrl url = formatURLQuery(keyword, category, "TILT");
|
||||||
return getModelURL(url);
|
return getModelURL(url);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Can provide asset name or full URL to model
|
// Can provide asset name or full URL to model
|
||||||
QString GooglePolyScriptingInterface::getModelInfo(QString name) {
|
QString GooglePolyScriptingInterface::getModelInfo(QString name) {
|
||||||
if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {
|
if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {
|
||||||
QStringList list = name.split("/");
|
QStringList list = name.split("/");
|
||||||
|
if (name.contains("poly.googleapis")) {
|
||||||
name = list[4];
|
name = list[4];
|
||||||
|
} else {
|
||||||
|
name = list.last();
|
||||||
}
|
}
|
||||||
QString urlString = QString(getPolyUrl);
|
}
|
||||||
|
QString urlString(GET_POLY_URL);
|
||||||
urlString = urlString.replace("model", name) + "key=" + authCode;
|
urlString = urlString.replace("model", name) + "key=" + authCode;
|
||||||
qCDebug(scriptengine) << "Google URL request: " << urlString;
|
qCDebug(scriptengine) << "Google URL request: " << urlString;
|
||||||
QUrl url(urlString);
|
QUrl url(urlString);
|
||||||
|
@ -106,7 +108,7 @@ int GooglePolyScriptingInterface::getRandIntInRange(int length) {
|
||||||
|
|
||||||
QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {
|
QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {
|
||||||
QString queries;
|
QString queries;
|
||||||
if (!validFormats.contains(format, Qt::CaseInsensitive) || !validCategories.contains(category, Qt::CaseInsensitive)) {
|
if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {
|
||||||
return QUrl("");
|
return QUrl("");
|
||||||
} else {
|
} else {
|
||||||
if (!keyword.isEmpty()) {
|
if (!keyword.isEmpty()) {
|
||||||
|
@ -119,7 +121,7 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ
|
||||||
if (!format.isEmpty()) {
|
if (!format.isEmpty()) {
|
||||||
queries.append("&format=" + format);
|
queries.append("&format=" + format);
|
||||||
}
|
}
|
||||||
QString urlString = QString(listPolyUrl + "key=" + authCode + queries);
|
QString urlString = QString(LIST_POLY_URL + "key=" + authCode + queries);
|
||||||
return QUrl(urlString);
|
return QUrl(urlString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +149,6 @@ QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) {
|
||||||
|
|
||||||
// 0 = asset list, 1 = model from asset list, 2 = specific model
|
// 0 = asset list, 1 = model from asset list, 2 = specific model
|
||||||
QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {
|
QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {
|
||||||
//QString firstItem = QString::fromUtf8(response->readAll());
|
|
||||||
QByteArray jsonString = getHTTPRequest(url);
|
QByteArray jsonString = getHTTPRequest(url);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(jsonString);
|
QJsonDocument doc = QJsonDocument::fromJson(jsonString);
|
||||||
QJsonObject obj = doc.object();
|
QJsonObject obj = doc.object();
|
||||||
|
|
|
@ -30,18 +30,18 @@ public slots:
|
||||||
QString getBlocks(QString keyword, QString category);
|
QString getBlocks(QString keyword, QString category);
|
||||||
QString getGLTF(QString keyword, QString category);
|
QString getGLTF(QString keyword, QString category);
|
||||||
QString getGLTF2(QString keyword, QString category);
|
QString getGLTF2(QString keyword, QString category);
|
||||||
//QString getTilt(QString keyword, QString category);
|
QString getTilt(QString keyword, QString category);
|
||||||
QString getModelInfo(QString name);
|
QString getModelInfo(QString name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString authCode;
|
||||||
|
|
||||||
QUrl formatURLQuery(QString keyword, QString category, QString format);
|
QUrl formatURLQuery(QString keyword, QString category, QString format);
|
||||||
QString getModelURL(QUrl url);
|
QString getModelURL(QUrl url);
|
||||||
QByteArray getHTTPRequest(QUrl url);
|
QByteArray getHTTPRequest(QUrl url);
|
||||||
QVariant parseJSON(QUrl url, int fileType);
|
QVariant parseJSON(QUrl url, int fileType);
|
||||||
int getRandIntInRange(int length);
|
int getRandIntInRange(int length);
|
||||||
|
|
||||||
QString authCode;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_GooglePolyScriptingInterface_h
|
#endif // hifi_GooglePolyScriptingInterface_h
|
||||||
|
|
Loading…
Reference in a new issue