mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 12:08:54 +02:00
Moved ModelUploader to interface + New error messages
This commit is contained in:
parent
8e097be28d
commit
8ad7c3b239
2 changed files with 48 additions and 36 deletions
|
@ -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,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
QString texDir;
|
||||||
|
QString fbxFile;
|
||||||
|
|
||||||
|
|
||||||
// First we check the FST file
|
// First we check the FST file
|
||||||
QFile fst(filename);
|
QFile fst(filename);
|
||||||
|
@ -100,22 +104,24 @@ bool ModelUploader::zip() {
|
||||||
_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";
|
||||||
} 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 +129,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 +145,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\"");
|
||||||
|
@ -159,6 +165,7 @@ bool ModelUploader::zip() {
|
||||||
|
|
||||||
void ModelUploader::send() {
|
void ModelUploader::send() {
|
||||||
if (!zip()) {
|
if (!zip()) {
|
||||||
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +209,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 +221,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 +254,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,32 +264,38 @@ 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)) {
|
||||||
|
|
||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (info.isDir()) {
|
|
||||||
if (!addTextures(info)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!part.normalFilename.isEmpty()) {
|
||||||
|
if (!addPart(QFileInfo(fbxFile).path() + "/" + part.normalFilename,
|
||||||
|
QString("texture%1").arg(++_texturesCount))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelUploader::addPart(const QString &path, const QString& name) {
|
bool ModelUploader::addPart(const QString &path, const QString& name) {
|
||||||
|
qDebug() << path;
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
QMessageBox::warning(NULL,
|
QMessageBox::warning(NULL,
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue