mirror of
https://github.com/overte-org/overte.git
synced 2025-07-28 21:50:24 +02:00
Moved common variables between base and derived classes to base class
This commit is contained in:
parent
54f9d52aa1
commit
d7f2e21dca
6 changed files with 68 additions and 79 deletions
|
@ -34,14 +34,12 @@
|
||||||
#include "FBXBaker.h"
|
#include "FBXBaker.h"
|
||||||
|
|
||||||
FBXBaker::FBXBaker(const QUrl& fbxURL, TextureBakerThreadGetter textureThreadGetter,
|
FBXBaker::FBXBaker(const QUrl& fbxURL, TextureBakerThreadGetter textureThreadGetter,
|
||||||
const QString& bakedOutputDir, const QString& originalOutputDir) :
|
const QString& bakedOutputDir, const QString& originalOutputDir) :
|
||||||
_fbxURL(fbxURL),
|
ModelBaker(fbxURL, textureThreadGetter, bakedOutputDir, originalOutputDir)
|
||||||
_bakedOutputDir(bakedOutputDir),
|
{
|
||||||
_originalOutputDir(originalOutputDir),
|
|
||||||
_textureThreadGetter(textureThreadGetter) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FBXBaker::~FBXBaker() {
|
FBXBaker::~FBXBaker() {
|
||||||
if (_tempDir.exists()) {
|
if (_tempDir.exists()) {
|
||||||
if (!_tempDir.remove(_originalFBXFilePath)) {
|
if (!_tempDir.remove(_originalFBXFilePath)) {
|
||||||
|
@ -64,7 +62,7 @@ void FBXBaker::abort() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FBXBaker::bake() {
|
void FBXBaker::bake() {
|
||||||
qDebug() << "FBXBaker" << _fbxURL << "bake starting";
|
qDebug() << "FBXBaker" << _modelURL << "bake starting";
|
||||||
|
|
||||||
auto tempDir = PathUtils::generateTemporaryDir();
|
auto tempDir = PathUtils::generateTemporaryDir();
|
||||||
|
|
||||||
|
@ -75,7 +73,7 @@ void FBXBaker::bake() {
|
||||||
|
|
||||||
_tempDir = tempDir;
|
_tempDir = tempDir;
|
||||||
|
|
||||||
_originalFBXFilePath = _tempDir.filePath(_fbxURL.fileName());
|
_originalFBXFilePath = _tempDir.filePath(_modelURL.fileName());
|
||||||
qDebug() << "Made temporary dir " << _tempDir;
|
qDebug() << "Made temporary dir " << _tempDir;
|
||||||
qDebug() << "Origin file path: " << _originalFBXFilePath;
|
qDebug() << "Origin file path: " << _originalFBXFilePath;
|
||||||
|
|
||||||
|
@ -146,22 +144,22 @@ void FBXBaker::setupOutputFolder() {
|
||||||
|
|
||||||
void FBXBaker::loadSourceFBX() {
|
void FBXBaker::loadSourceFBX() {
|
||||||
// check if the FBX is local or first needs to be downloaded
|
// check if the FBX is local or first needs to be downloaded
|
||||||
if (_fbxURL.isLocalFile()) {
|
if (_modelURL.isLocalFile()) {
|
||||||
// load up the local file
|
// load up the local file
|
||||||
QFile localFBX { _fbxURL.toLocalFile() };
|
QFile localFBX { _modelURL.toLocalFile() };
|
||||||
|
|
||||||
qDebug() << "Local file url: " << _fbxURL << _fbxURL.toString() << _fbxURL.toLocalFile() << ", copying to: " << _originalFBXFilePath;
|
qDebug() << "Local file url: " << _modelURL << _modelURL.toString() << _modelURL.toLocalFile() << ", copying to: " << _originalFBXFilePath;
|
||||||
|
|
||||||
if (!localFBX.exists()) {
|
if (!localFBX.exists()) {
|
||||||
//QMessageBox::warning(this, "Could not find " + _fbxURL.toString(), "");
|
//QMessageBox::warning(this, "Could not find " + _fbxURL.toString(), "");
|
||||||
handleError("Could not find " + _fbxURL.toString());
|
handleError("Could not find " + _modelURL.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make a copy in the output folder
|
// make a copy in the output folder
|
||||||
if (!_originalOutputDir.isEmpty()) {
|
if (!_originalOutputDir.isEmpty()) {
|
||||||
qDebug() << "Copying to: " << _originalOutputDir << "/" << _fbxURL.fileName();
|
qDebug() << "Copying to: " << _originalOutputDir << "/" << _modelURL.fileName();
|
||||||
localFBX.copy(_originalOutputDir + "/" + _fbxURL.fileName());
|
localFBX.copy(_originalOutputDir + "/" + _modelURL.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
localFBX.copy(_originalFBXFilePath);
|
localFBX.copy(_originalFBXFilePath);
|
||||||
|
@ -179,9 +177,9 @@ void FBXBaker::loadSourceFBX() {
|
||||||
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
|
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
|
||||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||||
|
|
||||||
networkRequest.setUrl(_fbxURL);
|
networkRequest.setUrl(_modelURL);
|
||||||
|
|
||||||
qCDebug(model_baking) << "Downloading" << _fbxURL;
|
qCDebug(model_baking) << "Downloading" << _modelURL;
|
||||||
auto networkReply = networkAccessManager.get(networkRequest);
|
auto networkReply = networkAccessManager.get(networkRequest);
|
||||||
|
|
||||||
connect(networkReply, &QNetworkReply::finished, this, &FBXBaker::handleFBXNetworkReply);
|
connect(networkReply, &QNetworkReply::finished, this, &FBXBaker::handleFBXNetworkReply);
|
||||||
|
@ -192,7 +190,7 @@ void FBXBaker::handleFBXNetworkReply() {
|
||||||
auto requestReply = qobject_cast<QNetworkReply*>(sender());
|
auto requestReply = qobject_cast<QNetworkReply*>(sender());
|
||||||
|
|
||||||
if (requestReply->error() == QNetworkReply::NoError) {
|
if (requestReply->error() == QNetworkReply::NoError) {
|
||||||
qCDebug(model_baking) << "Downloaded" << _fbxURL;
|
qCDebug(model_baking) << "Downloaded" << _modelURL;
|
||||||
|
|
||||||
// grab the contents of the reply and make a copy in the output folder
|
// grab the contents of the reply and make a copy in the output folder
|
||||||
QFile copyOfOriginal(_originalFBXFilePath);
|
QFile copyOfOriginal(_originalFBXFilePath);
|
||||||
|
@ -201,11 +199,11 @@ void FBXBaker::handleFBXNetworkReply() {
|
||||||
|
|
||||||
if (!copyOfOriginal.open(QIODevice::WriteOnly)) {
|
if (!copyOfOriginal.open(QIODevice::WriteOnly)) {
|
||||||
// add an error to the error list for this FBX stating that a duplicate of the original FBX could not be made
|
// add an error to the error list for this FBX stating that a duplicate of the original FBX could not be made
|
||||||
handleError("Could not create copy of " + _fbxURL.toString() + " (Failed to open " + _originalFBXFilePath + ")");
|
handleError("Could not create copy of " + _modelURL.toString() + " (Failed to open " + _originalFBXFilePath + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (copyOfOriginal.write(requestReply->readAll()) == -1) {
|
if (copyOfOriginal.write(requestReply->readAll()) == -1) {
|
||||||
handleError("Could not create copy of " + _fbxURL.toString() + " (Failed to write)");
|
handleError("Could not create copy of " + _modelURL.toString() + " (Failed to write)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,14 +211,14 @@ void FBXBaker::handleFBXNetworkReply() {
|
||||||
copyOfOriginal.close();
|
copyOfOriginal.close();
|
||||||
|
|
||||||
if (!_originalOutputDir.isEmpty()) {
|
if (!_originalOutputDir.isEmpty()) {
|
||||||
copyOfOriginal.copy(_originalOutputDir + "/" + _fbxURL.fileName());
|
copyOfOriginal.copy(_originalOutputDir + "/" + _modelURL.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// emit our signal to start the import of the FBX source copy
|
// emit our signal to start the import of the FBX source copy
|
||||||
emit sourceCopyReadyToLoad();
|
emit sourceCopyReadyToLoad();
|
||||||
} else {
|
} else {
|
||||||
// add an error to our list stating that the FBX could not be downloaded
|
// add an error to our list stating that the FBX could not be downloaded
|
||||||
handleError("Failed to download " + _fbxURL.toString());
|
handleError("Failed to download " + _modelURL.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,9 +233,9 @@ void FBXBaker::importScene() {
|
||||||
|
|
||||||
FBXReader reader;
|
FBXReader reader;
|
||||||
|
|
||||||
qCDebug(model_baking) << "Parsing" << _fbxURL;
|
qCDebug(model_baking) << "Parsing" << _modelURL;
|
||||||
_rootNode = reader._rootNode = reader.parseFBX(&fbxFile);
|
_rootNode = reader._rootNode = reader.parseFBX(&fbxFile);
|
||||||
_geometry = reader.extractFBXGeometry({}, _fbxURL.toString());
|
_geometry = reader.extractFBXGeometry({}, _modelURL.toString());
|
||||||
_textureContent = reader._textureContent;
|
_textureContent = reader._textureContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,8 +373,7 @@ void FBXBaker::rewriteAndBakeSceneTextures() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compress the texture information and return the new filename to be added into the FBX scene
|
// Compress the texture information and return the new filename to be added into the FBX scene
|
||||||
QByteArray* bakedTextureFile = this->compressTexture(fbxTextureFileName, _fbxURL, _bakedOutputDir, _textureThreadGetter,
|
QByteArray* bakedTextureFile = this->compressTexture(fbxTextureFileName, textureTypeCallback);
|
||||||
textureTypeCallback, _originalOutputDir);
|
|
||||||
|
|
||||||
// If no errors or warnings have occurred during texture compression add the filename to the FBX scene
|
// If no errors or warnings have occurred during texture compression add the filename to the FBX scene
|
||||||
if (bakedTextureFile) {
|
if (bakedTextureFile) {
|
||||||
|
@ -407,7 +404,7 @@ void FBXBaker::rewriteAndBakeSceneTextures() {
|
||||||
|
|
||||||
void FBXBaker::exportScene() {
|
void FBXBaker::exportScene() {
|
||||||
// save the relative path to this FBX inside our passed output folder
|
// save the relative path to this FBX inside our passed output folder
|
||||||
auto fileName = _fbxURL.fileName();
|
auto fileName = _modelURL.fileName();
|
||||||
auto baseName = fileName.left(fileName.lastIndexOf('.'));
|
auto baseName = fileName.left(fileName.lastIndexOf('.'));
|
||||||
auto bakedFilename = baseName + BAKED_FBX_EXTENSION;
|
auto bakedFilename = baseName + BAKED_FBX_EXTENSION;
|
||||||
|
|
||||||
|
@ -426,5 +423,5 @@ void FBXBaker::exportScene() {
|
||||||
|
|
||||||
_outputFiles.push_back(_bakedFBXFilePath);
|
_outputFiles.push_back(_bakedFBXFilePath);
|
||||||
|
|
||||||
qCDebug(model_baking) << "Exported" << _fbxURL << "with re-written paths to" << _bakedFBXFilePath;
|
qCDebug(model_baking) << "Exported" << _modelURL << "with re-written paths to" << _bakedFBXFilePath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
const QString& bakedOutputDir, const QString& originalOutputDir = "");
|
const QString& bakedOutputDir, const QString& originalOutputDir = "");
|
||||||
~FBXBaker() override;
|
~FBXBaker() override;
|
||||||
|
|
||||||
QUrl getFBXUrl() const { return _fbxURL; }
|
QUrl getFBXUrl() const { return _modelURL; }
|
||||||
QString getBakedFBXFilePath() const { return _bakedFBXFilePath; }
|
QString getBakedFBXFilePath() const { return _bakedFBXFilePath; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -62,18 +62,11 @@ private:
|
||||||
void exportScene();
|
void exportScene();
|
||||||
void removeEmbeddedMediaFolder();
|
void removeEmbeddedMediaFolder();
|
||||||
|
|
||||||
QUrl _fbxURL;
|
|
||||||
|
|
||||||
FBXNode _rootNode;
|
FBXNode _rootNode;
|
||||||
FBXGeometry* _geometry;
|
FBXGeometry* _geometry;
|
||||||
|
|
||||||
QString _bakedFBXFilePath;
|
QString _bakedFBXFilePath;
|
||||||
|
|
||||||
QString _bakedOutputDir;
|
|
||||||
|
|
||||||
// If set, the original FBX and textures will also be copied here
|
|
||||||
QString _originalOutputDir;
|
|
||||||
|
|
||||||
QDir _tempDir;
|
QDir _tempDir;
|
||||||
QString _originalFBXFilePath;
|
QString _originalFBXFilePath;
|
||||||
|
|
||||||
|
@ -81,8 +74,6 @@ private:
|
||||||
QHash<QString, int> _textureNameMatchCount;
|
QHash<QString, int> _textureNameMatchCount;
|
||||||
QHash<QUrl, QString> _remappedTexturePaths;
|
QHash<QUrl, QString> _remappedTexturePaths;
|
||||||
|
|
||||||
TextureBakerThreadGetter _textureThreadGetter;
|
|
||||||
|
|
||||||
bool _pendingErrorEmission { false };
|
bool _pendingErrorEmission { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,15 @@
|
||||||
#pragma warning( pop )
|
#pragma warning( pop )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ModelBaker::ModelBaker() {}
|
ModelBaker::ModelBaker(const QUrl& modelURL, TextureBakerThreadGetter textureThreadGetter,
|
||||||
|
const QString& bakedOutputDir, const QString& originalOutputDir) :
|
||||||
|
_modelURL(modelURL),
|
||||||
|
_textureThreadGetter(textureThreadGetter),
|
||||||
|
_bakedOutputDir(bakedOutputDir),
|
||||||
|
_originalOutputDir(originalOutputDir)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ModelBaker::bake() {}
|
void ModelBaker::bake() {}
|
||||||
|
|
||||||
|
@ -206,12 +214,7 @@ bool ModelBaker::compressMesh(FBXMesh& mesh, bool hasDeformers,FBXNode& dracoMes
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, QUrl modelURL, QString bakedOutputDir, TextureBakerThreadGetter textureThreadGetter,
|
QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, getTextureTypeCallback textureTypeCallback) {
|
||||||
getTextureTypeCallback textureTypeCallback, const QString& originalOutputDir) {
|
|
||||||
_modelURL = modelURL;
|
|
||||||
_textureThreadGetter = textureThreadGetter;
|
|
||||||
_originalOutputDir = originalOutputDir;
|
|
||||||
|
|
||||||
static QByteArray textureChild;
|
static QByteArray textureChild;
|
||||||
QByteArray textureContent;
|
QByteArray textureContent;
|
||||||
image::TextureUsage::Type textureType;
|
image::TextureUsage::Type textureType;
|
||||||
|
@ -260,7 +263,7 @@ QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, QUrl model
|
||||||
<< "to" << bakedTextureFileName;
|
<< "to" << bakedTextureFileName;
|
||||||
|
|
||||||
QString bakedTextureFilePath{
|
QString bakedTextureFilePath{
|
||||||
bakedOutputDir + "/" + bakedTextureFileName
|
_bakedOutputDir + "/" + bakedTextureFileName
|
||||||
};
|
};
|
||||||
|
|
||||||
textureChild = bakedTextureFileName.toLocal8Bit();
|
textureChild = bakedTextureFileName.toLocal8Bit();
|
||||||
|
@ -269,7 +272,7 @@ QByteArray* ModelBaker::compressTexture(QString modelTextureFileName, QUrl model
|
||||||
_outputFiles.push_back(bakedTextureFilePath);
|
_outputFiles.push_back(bakedTextureFilePath);
|
||||||
|
|
||||||
// bake this texture asynchronously
|
// bake this texture asynchronously
|
||||||
bakeTexture(urlToTexture, textureType, bakedOutputDir, bakedTextureFileName, textureContent);
|
bakeTexture(urlToTexture, textureType, _bakedOutputDir, bakedTextureFileName, textureContent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,15 +34,20 @@ class ModelBaker : public Baker{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModelBaker();
|
ModelBaker(const QUrl& modelURL, TextureBakerThreadGetter textureThreadGetter,
|
||||||
|
const QString& bakedOutputDir, const QString& originalOutputDir);
|
||||||
bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, getMaterialIDCallback materialIDCallback = NULL);
|
bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, getMaterialIDCallback materialIDCallback = NULL);
|
||||||
QByteArray* compressTexture(QString textureFileName, QUrl modelUrl, QString bakedOutputDir, TextureBakerThreadGetter textureThreadGetter,
|
QByteArray* compressTexture(QString textureFileName, getTextureTypeCallback textureTypeCallback = NULL);
|
||||||
getTextureTypeCallback textureTypeCallback = NULL, const QString& originalOutputDir = "");
|
|
||||||
virtual void setWasAborted(bool wasAborted) override;
|
virtual void setWasAborted(bool wasAborted) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void checkIfTexturesFinished();
|
void checkIfTexturesFinished();
|
||||||
|
|
||||||
QHash<QByteArray, QByteArray> _textureContent;
|
QHash<QByteArray, QByteArray> _textureContent;
|
||||||
|
QString _bakedOutputDir;
|
||||||
|
QString _originalOutputDir;
|
||||||
|
TextureBakerThreadGetter _textureThreadGetter;
|
||||||
|
QUrl _modelURL;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void bake() override;
|
virtual void bake() override;
|
||||||
|
@ -61,10 +66,10 @@ private:
|
||||||
|
|
||||||
QHash<QString, int> _textureNameMatchCount;
|
QHash<QString, int> _textureNameMatchCount;
|
||||||
QHash<QUrl, QString> _remappedTexturePaths;
|
QHash<QUrl, QString> _remappedTexturePaths;
|
||||||
QUrl _modelURL;
|
//QUrl _modelURL;
|
||||||
QMultiHash<QUrl, QSharedPointer<TextureBaker>> _bakingTextures;
|
QMultiHash<QUrl, QSharedPointer<TextureBaker>> _bakingTextures;
|
||||||
TextureBakerThreadGetter _textureThreadGetter;
|
//TextureBakerThreadGetter _textureThreadGetter;
|
||||||
QString _originalOutputDir;
|
//QString _originalOutputDir;
|
||||||
bool _pendingErrorEmission{ false };
|
bool _pendingErrorEmission{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,7 @@ const QByteArray MESH = "Mesh";
|
||||||
|
|
||||||
OBJBaker::OBJBaker(const QUrl& objURL, TextureBakerThreadGetter textureThreadGetter,
|
OBJBaker::OBJBaker(const QUrl& objURL, TextureBakerThreadGetter textureThreadGetter,
|
||||||
const QString& bakedOutputDir, const QString& originalOutputDir) :
|
const QString& bakedOutputDir, const QString& originalOutputDir) :
|
||||||
_objURL(objURL),
|
ModelBaker(objURL, textureThreadGetter, bakedOutputDir, originalOutputDir)
|
||||||
_bakedOutputDir(bakedOutputDir),
|
|
||||||
_originalOutputDir(originalOutputDir),
|
|
||||||
_textureThreadGetter(textureThreadGetter)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,7 +53,7 @@ OBJBaker::~OBJBaker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBJBaker::bake() {
|
void OBJBaker::bake() {
|
||||||
qDebug() << "OBJBaker" << _objURL << "bake starting";
|
qDebug() << "OBJBaker" << _modelURL << "bake starting";
|
||||||
|
|
||||||
auto tempDir = PathUtils::generateTemporaryDir();
|
auto tempDir = PathUtils::generateTemporaryDir();
|
||||||
|
|
||||||
|
@ -67,7 +64,7 @@ void OBJBaker::bake() {
|
||||||
|
|
||||||
_tempDir = tempDir;
|
_tempDir = tempDir;
|
||||||
|
|
||||||
_originalOBJFilePath = _tempDir.filePath(_objURL.fileName());
|
_originalOBJFilePath = _tempDir.filePath(_modelURL.fileName());
|
||||||
qDebug() << "Made temporary dir " << _tempDir;
|
qDebug() << "Made temporary dir " << _tempDir;
|
||||||
qDebug() << "Origin file path: " << _originalOBJFilePath;
|
qDebug() << "Origin file path: " << _originalOBJFilePath;
|
||||||
|
|
||||||
|
@ -80,21 +77,21 @@ void OBJBaker::bake() {
|
||||||
|
|
||||||
void OBJBaker::loadOBJ() {
|
void OBJBaker::loadOBJ() {
|
||||||
// check if the OBJ is local or it needs to be downloaded
|
// check if the OBJ is local or it needs to be downloaded
|
||||||
if (_objURL.isLocalFile()) {
|
if (_modelURL.isLocalFile()) {
|
||||||
// loading the local OBJ
|
// loading the local OBJ
|
||||||
QFile localOBJ{ _objURL.toLocalFile() };
|
QFile localOBJ{ _modelURL.toLocalFile() };
|
||||||
|
|
||||||
qDebug() << "Local file url: " << _objURL << _objURL.toString() << _objURL.toLocalFile() << ", copying to: " << _originalOBJFilePath;
|
qDebug() << "Local file url: " << _modelURL << _modelURL.toString() << _modelURL.toLocalFile() << ", copying to: " << _originalOBJFilePath;
|
||||||
|
|
||||||
if (!localOBJ.exists()) {
|
if (!localOBJ.exists()) {
|
||||||
handleError("Could not find " + _objURL.toString());
|
handleError("Could not find " + _modelURL.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make a copy in the output folder
|
// make a copy in the output folder
|
||||||
if (!_originalOutputDir.isEmpty()) {
|
if (!_originalOutputDir.isEmpty()) {
|
||||||
qDebug() << "Copying to: " << _originalOutputDir << "/" << _objURL.fileName();
|
qDebug() << "Copying to: " << _originalOutputDir << "/" << _modelURL.fileName();
|
||||||
localOBJ.copy(_originalOutputDir + "/" + _objURL.fileName());
|
localOBJ.copy(_originalOutputDir + "/" + _modelURL.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
localOBJ.copy(_originalOBJFilePath);
|
localOBJ.copy(_originalOBJFilePath);
|
||||||
|
@ -111,9 +108,9 @@ void OBJBaker::loadOBJ() {
|
||||||
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||||
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
|
networkRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
|
||||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||||
networkRequest.setUrl(_objURL);
|
networkRequest.setUrl(_modelURL);
|
||||||
|
|
||||||
qCDebug(model_baking) << "Downloading" << _objURL;
|
qCDebug(model_baking) << "Downloading" << _modelURL;
|
||||||
auto networkReply = networkAccessManager.get(networkRequest);
|
auto networkReply = networkAccessManager.get(networkRequest);
|
||||||
|
|
||||||
connect(networkReply, &QNetworkReply::finished, this, &OBJBaker::handleOBJNetworkReply);
|
connect(networkReply, &QNetworkReply::finished, this, &OBJBaker::handleOBJNetworkReply);
|
||||||
|
@ -124,7 +121,7 @@ void OBJBaker::handleOBJNetworkReply() {
|
||||||
auto requestReply = qobject_cast<QNetworkReply*>(sender());
|
auto requestReply = qobject_cast<QNetworkReply*>(sender());
|
||||||
|
|
||||||
if (requestReply->error() == QNetworkReply::NoError) {
|
if (requestReply->error() == QNetworkReply::NoError) {
|
||||||
qCDebug(model_baking) << "Downloaded" << _objURL;
|
qCDebug(model_baking) << "Downloaded" << _modelURL;
|
||||||
|
|
||||||
// grab the contents of the reply and make a copy in the output folder
|
// grab the contents of the reply and make a copy in the output folder
|
||||||
QFile copyOfOriginal(_originalOBJFilePath);
|
QFile copyOfOriginal(_originalOBJFilePath);
|
||||||
|
@ -133,11 +130,11 @@ void OBJBaker::handleOBJNetworkReply() {
|
||||||
|
|
||||||
if (!copyOfOriginal.open(QIODevice::WriteOnly)) {
|
if (!copyOfOriginal.open(QIODevice::WriteOnly)) {
|
||||||
// add an error to the error list for this obj stating that a duplicate of the original obj could not be made
|
// add an error to the error list for this obj stating that a duplicate of the original obj could not be made
|
||||||
handleError("Could not create copy of " + _objURL.toString() + " (Failed to open " + _originalOBJFilePath + ")");
|
handleError("Could not create copy of " + _modelURL.toString() + " (Failed to open " + _originalOBJFilePath + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (copyOfOriginal.write(requestReply->readAll()) == -1) {
|
if (copyOfOriginal.write(requestReply->readAll()) == -1) {
|
||||||
handleError("Could not create copy of " + _objURL.toString() + " (Failed to write)");
|
handleError("Could not create copy of " + _modelURL.toString() + " (Failed to write)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,14 +142,14 @@ void OBJBaker::handleOBJNetworkReply() {
|
||||||
copyOfOriginal.close();
|
copyOfOriginal.close();
|
||||||
|
|
||||||
if (!_originalOutputDir.isEmpty()) {
|
if (!_originalOutputDir.isEmpty()) {
|
||||||
copyOfOriginal.copy(_originalOutputDir + "/" + _objURL.fileName());
|
copyOfOriginal.copy(_originalOutputDir + "/" + _modelURL.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// remote OBJ is loaded emit signal to trigger its baking
|
// remote OBJ is loaded emit signal to trigger its baking
|
||||||
emit OBJLoaded();
|
emit OBJLoaded();
|
||||||
} else {
|
} else {
|
||||||
// add an error to our list stating that the OBJ could not be downloaded
|
// add an error to our list stating that the OBJ could not be downloaded
|
||||||
handleError("Failed to download " + _objURL.toString());
|
handleError("Failed to download " + _modelURL.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +166,7 @@ void OBJBaker::bakeOBJ() {
|
||||||
|
|
||||||
bool combineParts = true; // set true so that OBJReader reads material info from material library
|
bool combineParts = true; // set true so that OBJReader reads material info from material library
|
||||||
OBJReader reader;
|
OBJReader reader;
|
||||||
FBXGeometry* geometry = reader.readOBJ(objData, QVariantHash(), combineParts, _objURL);
|
FBXGeometry* geometry = reader.readOBJ(objData, QVariantHash(), combineParts, _modelURL);
|
||||||
|
|
||||||
// Write OBJ Data as FBX tree nodes
|
// Write OBJ Data as FBX tree nodes
|
||||||
FBXNode rootNode;
|
FBXNode rootNode;
|
||||||
|
@ -179,7 +176,7 @@ void OBJBaker::bakeOBJ() {
|
||||||
auto encodedFBX = FBXWriter::encodeFBX(rootNode);
|
auto encodedFBX = FBXWriter::encodeFBX(rootNode);
|
||||||
|
|
||||||
// Export as baked FBX
|
// Export as baked FBX
|
||||||
auto fileName = _objURL.fileName();
|
auto fileName = _modelURL.fileName();
|
||||||
auto baseName = fileName.left(fileName.lastIndexOf('.'));
|
auto baseName = fileName.left(fileName.lastIndexOf('.'));
|
||||||
auto bakedFilename = baseName + ".baked.fbx";
|
auto bakedFilename = baseName + ".baked.fbx";
|
||||||
|
|
||||||
|
@ -196,7 +193,7 @@ void OBJBaker::bakeOBJ() {
|
||||||
|
|
||||||
// Export successful
|
// Export successful
|
||||||
_outputFiles.push_back(_bakedOBJFilePath);
|
_outputFiles.push_back(_bakedOBJFilePath);
|
||||||
qCDebug(model_baking) << "Exported" << _objURL << "to" << _bakedOBJFilePath;
|
qCDebug(model_baking) << "Exported" << _modelURL << "to" << _bakedOBJFilePath;
|
||||||
|
|
||||||
// Export done emit finished
|
// Export done emit finished
|
||||||
emit finished();
|
emit finished();
|
||||||
|
@ -293,7 +290,7 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, FBXGeometry& geometry) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compress the texture using ModelBaker::compressTexture() and store compressed file's name in the node
|
// Compress the texture using ModelBaker::compressTexture() and store compressed file's name in the node
|
||||||
QByteArray* textureFile = this->compressTexture(textureFileName, _objURL, _bakedOutputDir, _textureThreadGetter, textureContentTypeCallback, _originalOutputDir);
|
QByteArray* textureFile = this->compressTexture(textureFileName, textureContentTypeCallback);
|
||||||
if (textureFile) {
|
if (textureFile) {
|
||||||
textureProperty = QVariant::fromValue(QByteArray(textureFile->data(), (int)textureFile->size()));
|
textureProperty = QVariant::fromValue(QByteArray(textureFile->data(), (int)textureFile->size()));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -45,13 +45,9 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
qlonglong _nodeID = 0;
|
qlonglong _nodeID = 0;
|
||||||
QUrl _objURL;
|
|
||||||
QString _bakedOBJFilePath;
|
QString _bakedOBJFilePath;
|
||||||
QString _bakedOutputDir;
|
|
||||||
QString _originalOutputDir;
|
|
||||||
QDir _tempDir;
|
QDir _tempDir;
|
||||||
QString _originalOBJFilePath;
|
QString _originalOBJFilePath;
|
||||||
TextureBakerThreadGetter _textureThreadGetter;
|
|
||||||
QMultiHash<QUrl, QSharedPointer<TextureBaker>> _bakingTextures;
|
QMultiHash<QUrl, QSharedPointer<TextureBaker>> _bakingTextures;
|
||||||
|
|
||||||
qlonglong _geometryID;
|
qlonglong _geometryID;
|
||||||
|
|
Loading…
Reference in a new issue