From 8ad7c3b239c4b3998069414f8183f995105e00a6 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 8 Apr 2014 14:03:27 -0700 Subject: [PATCH] Moved ModelUploader to interface + New error messages --- .../src/ModelUploader.cpp | 80 +++++++++++-------- .../shared => interface}/src/ModelUploader.h | 4 +- 2 files changed, 48 insertions(+), 36 deletions(-) rename {libraries/shared => interface}/src/ModelUploader.cpp (82%) rename {libraries/shared => interface}/src/ModelUploader.h (94%) diff --git a/libraries/shared/src/ModelUploader.cpp b/interface/src/ModelUploader.cpp similarity index 82% rename from libraries/shared/src/ModelUploader.cpp rename to interface/src/ModelUploader.cpp index 4386704559..1881d84d85 100644 --- a/libraries/shared/src/ModelUploader.cpp +++ b/interface/src/ModelUploader.cpp @@ -18,7 +18,9 @@ #include #include -#include "AccountManager.h" +#include + +#include "renderer/FBXReader.h" #include "ModelUploader.h" @@ -59,11 +61,13 @@ bool ModelUploader::zip() { "Select your .fst file ...", QStandardPaths::writableLocation(QStandardPaths::HomeLocation), "*.fst"); - qDebug() << QStandardPaths::writableLocation(QStandardPaths::HomeLocation); if (filename == "") { // If the user canceled we return. return false; } + QString texDir; + QString fbxFile; + // First we check the FST file QFile fst(filename); @@ -100,22 +104,24 @@ bool ModelUploader::zip() { _dataMultiPart->append(textPart); _url = S3_URL + ((_isHead)? "/models/heads/" : "/models/skeletons/") + line[1].toUtf8() + ".fst"; } else if (line[0] == FILENAME_FIELD) { - QFileInfo fbx(QFileInfo(fst).path() + "/" + line[1]); - if (!fbx.exists() || !fbx.isFile()) { // Check existence + fbxFile = QFileInfo(fst).path() + "/" + line[1]; + QFileInfo fbxInfo(fbxFile); + if (!fbxInfo.exists() || !fbxInfo.isFile()) { // Check existence QMessageBox::warning(NULL, 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); - 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; } // Compress and copy - if (!addPart(fbx.filePath(), "fbx")) { + if (!addPart(fbxInfo.filePath(), "fbx")) { return false; } } else if (line[0] == TEXDIR_FIELD) { // Check existence - QFileInfo texdir(QFileInfo(fst).path() + "/" + line[1]); - if (!texdir.exists() || !texdir.isDir()) { + texDir = QFileInfo(fst).path() + "/" + line[1]; + QFileInfo texInfo(texDir); + if (!texInfo.exists() || !texInfo.isDir()) { QMessageBox::warning(NULL, QString("ModelUploader::zip()"), QString("Texture directory could not be found."), @@ -123,18 +129,14 @@ bool ModelUploader::zip() { qDebug() << "[Warning] " << QString("Texture directory could not be found."); return false; } - if (!addTextures(texdir)) { // Recursive compress and copy - return false; - } } else if (line[0] == LOD_FIELD) { QFileInfo lod(QFileInfo(fst).path() + "/" + line[1]); if (!lod.exists() || !lod.isFile()) { // Check existence QMessageBox::warning(NULL, 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); qDebug() << "[Warning] " << QString("FBX file %1 could not be found.").arg(lod.fileName()); - return false; } // Compress and copy if (!addPart(lod.filePath(), QString("lod%1").arg(++_lodCount))) { @@ -143,6 +145,10 @@ bool ModelUploader::zip() { } } + if (!addTextures(texDir, fbxFile)) { + return false; + } + QHttpPart textPart; textPart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data;" " name=\"model_category\""); @@ -159,6 +165,7 @@ bool ModelUploader::zip() { void ModelUploader::send() { if (!zip()) { + deleteLater(); return; } @@ -202,7 +209,7 @@ void ModelUploader::uploadSuccess(const QJsonObject& jsonResponse) { } QMessageBox::information(NULL, QString("ModelUploader::uploadSuccess()"), - QString("Your model is being processed by the system."), + QString("We are reading your model information."), QMessageBox::Ok); qDebug() << "Model sent with success"; checkS3(); @@ -214,7 +221,7 @@ void ModelUploader::uploadFailed(QNetworkReply::NetworkError errorCode, const QS } QMessageBox::warning(NULL, 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); qDebug() << "Model upload failed (" << errorCode << "): " << errorString; deleteLater(); @@ -247,7 +254,8 @@ void ModelUploader::processCheck() { default: QMessageBox::warning(NULL, 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); deleteLater(); break; @@ -256,24 +264,29 @@ void ModelUploader::processCheck() { delete reply; } -bool ModelUploader::addTextures(const QFileInfo& texdir) { - QStringList filter; - filter << "*.png" << "*.tif" << "*.jpg" << "*.jpeg"; +bool ModelUploader::addTextures(const QString& texdir, const QString fbxFile) { + QFile fbx(fbxFile); + if (!fbx.open(QIODevice::ReadOnly)) { + return false; + } - QFileInfoList list = QDir(texdir.filePath()).entryInfoList(filter, - QDir::Files | - QDir::AllDirs | - QDir::NoDotAndDotDot | - QDir::NoSymLinks); - foreach (QFileInfo info, list) { - if (info.isFile()) { - // Compress and copy - if (!addPart(info.filePath(), QString("texture%1").arg(++_texturesCount))) { - return false; + QByteArray buffer = fbx.readAll(); + QVariantHash variantHash = readMapping(buffer); + FBXGeometry geometry = readFBX(buffer, variantHash); + + foreach (FBXMesh mesh, geometry.meshes) { + foreach (FBXMeshPart part, mesh.parts) { + if (!part.diffuseFilename.isEmpty()) { + if (!addPart(QFileInfo(fbxFile).path() + "/" + part.diffuseFilename, + QString("texture%1").arg(++_texturesCount))) { + return false; + } } - } else if (info.isDir()) { - if (!addTextures(info)) { - return false; + if (!part.normalFilename.isEmpty()) { + if (!addPart(QFileInfo(fbxFile).path() + "/" + part.normalFilename, + QString("texture%1").arg(++_texturesCount))) { + return false; + } } } } @@ -282,6 +295,7 @@ bool ModelUploader::addTextures(const QFileInfo& texdir) { } bool ModelUploader::addPart(const QString &path, const QString& name) { + qDebug() << path; QFile file(path); if (!file.open(QIODevice::ReadOnly)) { QMessageBox::warning(NULL, diff --git a/libraries/shared/src/ModelUploader.h b/interface/src/ModelUploader.h similarity index 94% rename from libraries/shared/src/ModelUploader.h rename to interface/src/ModelUploader.h index 0e62ab8705..0d18ef9022 100644 --- a/libraries/shared/src/ModelUploader.h +++ b/interface/src/ModelUploader.h @@ -17,8 +17,6 @@ class QFileInfo; class QHttpMultiPart; class QProgressBar; -class TemporaryDir; - class ModelUploader : public QObject { Q_OBJECT @@ -55,7 +53,7 @@ private: bool zip(); - bool addTextures(const QFileInfo& texdir); + bool addTextures(const QString& texdir, const QString fbxFile); bool addPart(const QString& path, const QString& name); };