History

added gltf import feature, getAssetList() not working

Elisa Lupin-Jimenez committed 8 years ago

Commit 1ee84451 parent e7fad052 files · +46 −19Browse files

Showing the changes to interface/src/scripting/GooglePolyScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

interface/src/scripting/GooglePolyScriptingInterface.cpp+42−18
@@ -36,17 +36,39 @@ GooglePolyScriptingInterface::GooglePolyScriptingInterface() { · 35 unmodified lines
3636 // nothing to be implemented
3737 }
3838
39−QJsonArray GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) {
39+void GooglePolyScriptingInterface::setAPIKey(QString key) {
40+ authCode = key;
41+}
42+
43+QByteArray GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) {
44+ QUrl url = formatURLQuery(keyword, category, format);
45+ if (!url.isEmpty()) {
46+ //QJsonArray json = parseJSON(url, 0).toJsonArray();
47+ //qCDebug(scriptengine) << "first asset name: " << json.at(0).toObject().value("displayName");
48+ QByteArray json = parseJSON(url, 0).toJsonDocument().toJson();
49+ qCDebug(scriptengine) << "asset list as string is: " << json;
50+ return json;
51+ } else {
52+ qCDebug(scriptengine) << "Invalid filters were specified.";
53+ //return QJsonArray();
54+ return "";
55+ }
56+}
57+
58+/*QJsonArray GooglePolyScriptingInterface::getAssetList(QString keyword, QString category, QString format) {
4059 QUrl url = formatURLQuery(keyword, category, format);
4160 if (!url.isEmpty()) {
61+ //QJsonArray json = parseJSON(url, 0).toJsonArray();
62+ //qCDebug(scriptengine) << "first asset name: " << json.at(0).toObject().value("displayName");
4263 QJsonArray json = parseJSON(url, 0).toJsonArray();
43− qCDebug(scriptengine) << "first asset name: " << json.at(0).toObject().value("displayName");
64+ qCDebug(scriptengine) << "asset list as array is: " << json;
4465 return json;
4566 } else {
4667 qCDebug(scriptengine) << "Invalid filters were specified.";
4768 return QJsonArray();
69+ //return "";
4870 }
49−}
71+}*/
5072
5173 QString GooglePolyScriptingInterface::getFBX(QString keyword, QString category) {
5274 QUrl url = formatURLQuery(keyword, category, "FBX");
@@ -60,7 +82,16 @@ QString GooglePolyScriptingInterface::getOBJ(QString keyword, QString category) · 7 unmodified lines
6082
6183 QString GooglePolyScriptingInterface::getBlocks(QString keyword, QString category) {
6284 QUrl url = formatURLQuery(keyword, category, "BLOCKS");
63− qCDebug(scriptengine) << "Google url request: " << url;
85+ return getModelURL(url);
86+}
87+
88+QString GooglePolyScriptingInterface::getGLTF(QString keyword, QString category) {
89+ QUrl url = formatURLQuery(keyword, category, "GLTF");
90+ return getModelURL(url);
91+}
92+
93+QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category) {
94+ QUrl url = formatURLQuery(keyword, category, "GLTF2");
6495 return getModelURL(url);
6596 }
6697
@@ -74,15 +105,15 @@ QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) · 7 unmodified lines
74105
75106 // can provide asset name or full URL to model
76107 QString GooglePolyScriptingInterface::getModelInfo(QString name) {
77− if (name.contains("poly.googleapis")) {
108+ if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {
78109 QStringList list = name.split("/");
79110 name = list[4];
80111 }
81112 QString urlString = QString(getPolyUrl);
82113 urlString = urlString.replace("model", name) + "key=" + authCode;
83− qCDebug(scriptengine) << "google get url: " << urlString;
114+ qCDebug(scriptengine) << "Google URL request: " << urlString;
84115 QUrl url(urlString);
85− QByteArray json = parseJSON(url, 2).toByteArray();
116+ QString json = parseJSON(url, 2).toString();
86117 return json;
87118 }
88119
@@ -90,10 +121,6 @@ void GooglePolyScriptingInterface::testPrint(QString input) { · 1 unmodified line
90121 qCDebug(scriptengine) << "Google message: " << input;
91122 }
92123
93−void GooglePolyScriptingInterface::setAPIKey(QString key) {
94− authCode = key;
95−}
96−
97124 int GooglePolyScriptingInterface::getRandIntInRange(int length) {
98125 QTime time = QTime::currentTime();
99126 qsrand((uint)time.msec());
@@ -121,7 +148,7 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 21 unmodified lines
121148 }
122149
123150 QString GooglePolyScriptingInterface::getModelURL(QUrl url) {
124− qCDebug(scriptengine) << "Google url request: " << url;
151+ qCDebug(scriptengine) << "Google URL request: " << url;
125152 if (!url.isEmpty()) {
126153 return parseJSON(url, 1).toString();
127154 } else {
@@ -150,9 +177,8 @@ QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) { · 22 unmodified lines
150177 if (obj.keys().first() == "error") {
151178 QString error = obj.value("error").toObject().value("message").toString();
152179 qCDebug(scriptengine) << error;
153− return QJsonObject();
180+ return "";
154181 }
155− qCDebug(scriptengine) << "the assets: " << obj.value("assets");
156182 if (fileType == 0 || fileType == 1) {
157183 QJsonArray arr = obj.value("assets").toArray();
158184 // return model url
@@ -163,11 +189,10 @@ QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) { · 4 unmodified lines
163189 return json.value("formats").toArray().at(0).toObject().value("root").toObject().value("url");
164190 }
165191 // return whole asset list
166− return arr;
192+ //return arr;
193+ return QJsonDocument(arr);
167194 // return specific object
168195 } else {
169− //return obj;
170− //return doc.toJson();
171196 return jsonString;
172197 }
173198 }
@@ -269,5 +294,4 @@ or this :(( http://blog.mathieu-leplatre.info/access-a-json-webservice-with-qt-c · 95 unmodified lines
269294 qCDebug(scriptengine) << "first item: " << firstItem;
270295 }
271296
272−<<<<<<< HEAD
273297 */