Merge pull request #2619 from Atlante45/master

Moved ModelUploader to interface + New error messages
This commit is contained in:
Stephen Birarda 2014-04-09 14:38:36 -07:00
commit 49a9653399
2 changed files with 58 additions and 36 deletions

View file

@ -18,7 +18,9 @@
#include <QTextStream> #include <QTextStream>
#include <QVariant> #include <QVariant>
#include "AccountManager.h" #include <AccountManager.h>
#include "renderer/FBXReader.h"
#include "ModelUploader.h" #include "ModelUploader.h"
@ -59,11 +61,14 @@ bool ModelUploader::zip() {
"Select your .fst file ...", "Select your .fst file ...",
QStandardPaths::writableLocation(QStandardPaths::HomeLocation), QStandardPaths::writableLocation(QStandardPaths::HomeLocation),
"*.fst"); "*.fst");
qDebug() << QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
if (filename == "") { if (filename == "") {
// If the user canceled we return. // If the user canceled we return.
return false; return false;
} }
bool _nameIsPresent = false;
QString texDir;
QString fbxFile;
// First we check the FST file // First we check the FST file
QFile fst(filename); QFile fst(filename);
@ -99,23 +104,26 @@ bool ModelUploader::zip() {
textPart.setBody(line[1].toUtf8()); textPart.setBody(line[1].toUtf8());
_dataMultiPart->append(textPart); _dataMultiPart->append(textPart);
_url = S3_URL + ((_isHead)? "/models/heads/" : "/models/skeletons/") + line[1].toUtf8() + ".fst"; _url = S3_URL + ((_isHead)? "/models/heads/" : "/models/skeletons/") + line[1].toUtf8() + ".fst";
_nameIsPresent = true;
} else if (line[0] == FILENAME_FIELD) { } else if (line[0] == FILENAME_FIELD) {
QFileInfo fbx(QFileInfo(fst).path() + "/" + line[1]); fbxFile = QFileInfo(fst).path() + "/" + line[1];
if (!fbx.exists() || !fbx.isFile()) { // Check existence QFileInfo fbxInfo(fbxFile);
if (!fbxInfo.exists() || !fbxInfo.isFile()) { // Check existence
QMessageBox::warning(NULL, QMessageBox::warning(NULL,
QString("ModelUploader::zip()"), QString("ModelUploader::zip()"),
QString("FBX file %1 could not be found.").arg(fbx.fileName()), QString("FBX file %1 could not be found.").arg(fbxInfo.fileName()),
QMessageBox::Ok); QMessageBox::Ok);
qDebug() << "[Warning] " << QString("FBX file %1 could not be found.").arg(fbx.fileName()); qDebug() << "[Warning] " << QString("FBX file %1 could not be found.").arg(fbxInfo.fileName());
return false; return false;
} }
// Compress and copy // Compress and copy
if (!addPart(fbx.filePath(), "fbx")) { if (!addPart(fbxInfo.filePath(), "fbx")) {
return false; return false;
} }
} else if (line[0] == TEXDIR_FIELD) { // Check existence } else if (line[0] == TEXDIR_FIELD) { // Check existence
QFileInfo texdir(QFileInfo(fst).path() + "/" + line[1]); texDir = QFileInfo(fst).path() + "/" + line[1];
if (!texdir.exists() || !texdir.isDir()) { QFileInfo texInfo(texDir);
if (!texInfo.exists() || !texInfo.isDir()) {
QMessageBox::warning(NULL, QMessageBox::warning(NULL,
QString("ModelUploader::zip()"), QString("ModelUploader::zip()"),
QString("Texture directory could not be found."), QString("Texture directory could not be found."),
@ -123,18 +131,14 @@ bool ModelUploader::zip() {
qDebug() << "[Warning] " << QString("Texture directory could not be found."); qDebug() << "[Warning] " << QString("Texture directory could not be found.");
return false; return false;
} }
if (!addTextures(texdir)) { // Recursive compress and copy
return false;
}
} else if (line[0] == LOD_FIELD) { } else if (line[0] == LOD_FIELD) {
QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]); QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]);
if (!lod.exists() || !lod.isFile()) { // Check existence if (!lod.exists() || !lod.isFile()) { // Check existence
QMessageBox::warning(NULL, QMessageBox::warning(NULL,
QString("ModelUploader::zip()"), QString("ModelUploader::zip()"),
QString("FBX file %1 could not be found.").arg(lod.fileName()), QString("LOD file %1 could not be found.").arg(lod.fileName()),
QMessageBox::Ok); QMessageBox::Ok);
qDebug() << "[Warning] " << QString("FBX file %1 could not be found.").arg(lod.fileName()); qDebug() << "[Warning] " << QString("FBX file %1 could not be found.").arg(lod.fileName());
return false;
} }
// Compress and copy // Compress and copy
if (!addPart(lod.filePath(), QString("lod%1").arg(++_lodCount))) { if (!addPart(lod.filePath(), QString("lod%1").arg(++_lodCount))) {
@ -143,6 +147,10 @@ bool ModelUploader::zip() {
} }
} }
if (!addTextures(texDir, fbxFile)) {
return false;
}
QHttpPart textPart; QHttpPart textPart;
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;" textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;"
" name=\"model_category\""); " name=\"model_category\"");
@ -153,12 +161,22 @@ bool ModelUploader::zip() {
} }
_dataMultiPart->append(textPart); _dataMultiPart->append(textPart);
if (!_nameIsPresent) {
QMessageBox::warning(NULL,
QString("ModelUploader::zip()"),
QString("Model name is missing in the .fst file."),
QMessageBox::Ok);
qDebug() << "[Warning] " << QString("Model name is missing in the .fst file.");
return false;
}
_readyToSend = true; _readyToSend = true;
return true; return true;
} }
void ModelUploader::send() { void ModelUploader::send() {
if (!zip()) { if (!zip()) {
deleteLater();
return; return;
} }
@ -202,7 +220,7 @@ void ModelUploader::uploadSuccess(const QJsonObject& jsonResponse) {
} }
QMessageBox::information(NULL, QMessageBox::information(NULL,
QString("ModelUploader::uploadSuccess()"), QString("ModelUploader::uploadSuccess()"),
QString("Your model is being processed by the system."), QString("We are reading your model information."),
QMessageBox::Ok); QMessageBox::Ok);
qDebug() << "Model sent with success"; qDebug() << "Model sent with success";
checkS3(); checkS3();
@ -214,7 +232,7 @@ void ModelUploader::uploadFailed(QNetworkReply::NetworkError errorCode, const QS
} }
QMessageBox::warning(NULL, QMessageBox::warning(NULL,
QString("ModelUploader::uploadFailed()"), QString("ModelUploader::uploadFailed()"),
QString("Model could not be sent to the data server."), QString("There was a problem with your upload, please try again later."),
QMessageBox::Ok); QMessageBox::Ok);
qDebug() << "Model upload failed (" << errorCode << "): " << errorString; qDebug() << "Model upload failed (" << errorCode << "): " << errorString;
deleteLater(); deleteLater();
@ -247,7 +265,8 @@ void ModelUploader::processCheck() {
default: default:
QMessageBox::warning(NULL, QMessageBox::warning(NULL,
QString("ModelUploader::processCheck()"), QString("ModelUploader::processCheck()"),
QString("Could not verify that the model is present on the server."), QString("We could not verify that your model was sent sucessfully\n"
"but it may have. If you do not see it in the model browser, try to upload again."),
QMessageBox::Ok); QMessageBox::Ok);
deleteLater(); deleteLater();
break; break;
@ -256,24 +275,29 @@ void ModelUploader::processCheck() {
delete reply; delete reply;
} }
bool ModelUploader::addTextures(const QFileInfo& texdir) { bool ModelUploader::addTextures(const QString& texdir, const QString fbxFile) {
QStringList filter; QFile fbx(fbxFile);
filter << "*.png" << "*.tif" << "*.jpg" << "*.jpeg"; if (!fbx.open(QIODevice::ReadOnly)) {
return false;
}
QFileInfoList list = QDir(texdir.filePath()).entryInfoList(filter, QByteArray buffer = fbx.readAll();
QDir::Files | QVariantHash variantHash = readMapping(buffer);
QDir::AllDirs | FBXGeometry geometry = readFBX(buffer, variantHash);
QDir::NoDotAndDotDot |
QDir::NoSymLinks); foreach (FBXMesh mesh, geometry.meshes) {
foreach (QFileInfo info, list) { foreach (FBXMeshPart part, mesh.parts) {
if (info.isFile()) { if (!part.diffuseFilename.isEmpty()) {
// Compress and copy if (!addPart(QFileInfo(fbxFile).path() + "/" + part.diffuseFilename,
if (!addPart(info.filePath(), QString("texture%1").arg(++_texturesCount))) { QString("texture%1").arg(++_texturesCount))) {
return false; return false;
}
} }
} else if (info.isDir()) { if (!part.normalFilename.isEmpty()) {
if (!addTextures(info)) { if (!addPart(QFileInfo(fbxFile).path() + "/" + part.normalFilename,
return false; QString("texture%1").arg(++_texturesCount))) {
return false;
}
} }
} }
} }

View file

@ -17,8 +17,6 @@ class QFileInfo;
class QHttpMultiPart; class QHttpMultiPart;
class QProgressBar; class QProgressBar;
class TemporaryDir;
class ModelUploader : public QObject { class ModelUploader : public QObject {
Q_OBJECT Q_OBJECT
@ -55,7 +53,7 @@ private:
bool zip(); bool zip();
bool addTextures(const QFileInfo& texdir); bool addTextures(const QString& texdir, const QString fbxFile);
bool addPart(const QString& path, const QString& name); bool addPart(const QString& path, const QString& name);
}; };