Move outputFiles from FBXBaker to Baker

This commit is contained in:
Ryan Huffman 2017-08-25 16:21:00 -07:00
parent 39f04adc8d
commit 7d08a5788f
4 changed files with 24 additions and 24 deletions

View file

@ -61,28 +61,24 @@ void BakeAssetTask::run() {
qRegisterMetaType<QVector<QString> >("QVector<QString>");
TextureBakerThreadGetter fn = []() -> QThread* { return QThread::currentThread(); };
if (_filePath.endsWith(".fbx")) {
FBXBaker baker(QUrl("file:///" + _filePath), fn, PathUtils::generateTemporaryDir());
std::unique_ptr<Baker> baker;
QEventLoop loop;
connect(&baker, &Baker::finished, &loop, &QEventLoop::quit);
QMetaObject::invokeMethod(&baker, "bake", Qt::QueuedConnection);
qDebug() << "Running the bake!";
loop.exec();
qDebug() << "Finished baking: " << _assetHash << _assetPath << baker.getOutputFiles();
emit bakeComplete(_assetHash, _assetPath, QVector<QString>::fromStdVector(baker.getOutputFiles()));
if (_assetPath.endsWith(".fbx")) {
baker = std::make_unique<FBXBaker>(QUrl("file:///" + _filePath), fn, PathUtils::generateTemporaryDir());
} else {
TextureBaker baker(QUrl("file:///" + _filePath), image::TextureUsage::CUBE_TEXTURE, PathUtils::generateTemporaryDir());
baker = std::make_unique<TextureBaker>(QUrl("file:///" + _filePath), image::TextureUsage::CUBE_TEXTURE, PathUtils::generateTemporaryDir());
}
QEventLoop loop;
connect(&baker, &Baker::finished, &loop, &QEventLoop::quit);
QMetaObject::invokeMethod(&baker, "bake", Qt::QueuedConnection);
qDebug() << "Running the bake!";
loop.exec();
QEventLoop loop;
connect(baker.get(), &Baker::finished, &loop, &QEventLoop::quit);
QMetaObject::invokeMethod(baker.get(), "bake", Qt::QueuedConnection);
loop.exec();
qDebug() << "Finished baking: " << _assetHash << _assetPath << baker.getBakedTextureFileName();
emit bakeComplete(_assetHash, _assetPath, { baker.getDestinationFilePath() });
if (baker->hasErrors()) {
qDebug() << "Failed to bake: " << _assetHash << _assetPath;
} else {
qDebug() << "Finished baking: " << _assetHash << _assetPath << baker->getOutputFiles();
emit bakeComplete(_assetHash, _assetPath, QVector<QString>::fromStdVector(baker->getOutputFiles()));
}
}
@ -454,7 +450,6 @@ void AssetServer::handleGetMappingOperation(ReceivedMessage& message, SharedNode
replyPacket.write(QByteArray::fromHex(originalAssetHash.toUtf8()));
replyPacket.writePrimitive(wasRedirected);
auto query = QUrlQuery(url.query());
bool isSkybox = query.hasQueryItem("skybox");
qDebug() << "Is skybox? " << isSkybox;

View file

@ -24,6 +24,8 @@ public:
bool hasWarnings() const { return !_warningList.isEmpty(); }
QStringList getWarnings() const { return _warningList; }
std::vector<QString> getOutputFiles() const { return _outputFiles; }
public slots:
virtual void bake() = 0;
@ -36,6 +38,10 @@ protected:
void handleErrors(const QStringList& errors);
// List of baked output files. For instance, for an FBX this would
// include the .fbx and all of its texture files.
std::vector<QString> _outputFiles;
QStringList _errorList;
QStringList _warningList;
};

View file

@ -44,7 +44,6 @@ public:
QUrl getFBXUrl() const { return _fbxURL; }
QString getBakedFBXFilePath() const { return _bakedFBXFilePath; }
std::vector<QString> getOutputFiles() const { return _outputFiles; }
public slots:
// all calls to FBXBaker::bake for FBXBaker instances must be from the same thread
@ -88,9 +87,6 @@ private:
QDir _tempDir;
QString _originalFBXFilePath;
// List of baked output files, includes the FBX and textures
std::vector<QString> _outputFiles;
static FBXSDKManagerUniquePointer _sdkManager;
fbxsdk::FbxScene* _scene { nullptr };

View file

@ -120,10 +120,13 @@ void TextureBaker::processTexture() {
const size_t length = memKTX->_storage->size();
// attempt to write the baked texture to the destination file path
QFile bakedTextureFile { _outputDirectory.absoluteFilePath(_bakedTextureFileName) };
auto filePath = _outputDirectory.absoluteFilePath(_bakedTextureFileName);
QFile bakedTextureFile { filePath };
if (!bakedTextureFile.open(QIODevice::WriteOnly) || bakedTextureFile.write(data, length) == -1) {
handleError("Could not write baked texture for " + _textureURL.toString());
} else {
_outputFiles.push_back(filePath);
}
qCDebug(model_baking) << "Baked texture" << _textureURL;