mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 11:57:58 +02:00
Add OBJ support to domain baker
This commit is contained in:
parent
004e15d2d9
commit
a5e491e29d
5 changed files with 44 additions and 26 deletions
|
@ -405,6 +405,8 @@ void ModelBaker::handleAbortedTexture() {
|
||||||
// grab the texture bake that was aborted and remove it from our hash since we don't need to track it anymore
|
// grab the texture bake that was aborted and remove it from our hash since we don't need to track it anymore
|
||||||
TextureBaker* bakedTexture = qobject_cast<TextureBaker*>(sender());
|
TextureBaker* bakedTexture = qobject_cast<TextureBaker*>(sender());
|
||||||
|
|
||||||
|
qDebug() << "Texture aborted: " << bakedTexture->getTextureURL();
|
||||||
|
|
||||||
if (bakedTexture) {
|
if (bakedTexture) {
|
||||||
_bakingTextures.remove(bakedTexture->getTextureURL());
|
_bakingTextures.remove(bakedTexture->getTextureURL());
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
ModelBaker(const QUrl& inputModelURL, TextureBakerThreadGetter inputTextureThreadGetter,
|
ModelBaker(const QUrl& inputModelURL, TextureBakerThreadGetter inputTextureThreadGetter,
|
||||||
const QString& bakedOutputDirectory, const QString& originalOutputDirectory = "");
|
const QString& bakedOutputDirectory, const QString& originalOutputDirectory = "");
|
||||||
virtual ~ModelBaker();
|
virtual ~ModelBaker();
|
||||||
|
|
||||||
bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, GetMaterialIDCallback materialIDCallback = nullptr);
|
bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, GetMaterialIDCallback materialIDCallback = nullptr);
|
||||||
QString compressTexture(QString textureFileName, image::TextureUsage::Type = image::TextureUsage::Type::DEFAULT_TEXTURE);
|
QString compressTexture(QString textureFileName, image::TextureUsage::Type = image::TextureUsage::Type::DEFAULT_TEXTURE);
|
||||||
virtual void setWasAborted(bool wasAborted) override;
|
virtual void setWasAborted(bool wasAborted) override;
|
||||||
|
|
|
@ -45,6 +45,16 @@ void OBJBaker::bake() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBJBaker::loadOBJ() {
|
void OBJBaker::loadOBJ() {
|
||||||
|
if (!QDir().mkpath(_bakedOutputDir)) {
|
||||||
|
handleError("Failed to create baked OBJ output folder " + _bakedOutputDir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!QDir().mkpath(_originalOutputDir)) {
|
||||||
|
handleError("Failed to create original OBJ output folder " + _originalOutputDir);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 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 (_modelURL.isLocalFile()) {
|
if (_modelURL.isLocalFile()) {
|
||||||
// loading the local OBJ
|
// loading the local OBJ
|
||||||
|
@ -150,16 +160,6 @@ void OBJBaker::bakeOBJ() {
|
||||||
|
|
||||||
_bakedModelFilePath = _bakedOutputDir + "/" + bakedFilename;
|
_bakedModelFilePath = _bakedOutputDir + "/" + bakedFilename;
|
||||||
|
|
||||||
if (!QDir().mkpath(_bakedOutputDir)) {
|
|
||||||
handleError("Failed to create baked OBJ output folder " + _bakedOutputDir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!QDir().mkpath(_originalOutputDir)) {
|
|
||||||
handleError("Failed to create original OBJ output folder " + _originalOutputDir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile bakedFile;
|
QFile bakedFile;
|
||||||
bakedFile.setFileName(_bakedModelFilePath);
|
bakedFile.setFileName(_bakedModelFilePath);
|
||||||
if (!bakedFile.open(QIODevice::WriteOnly)) {
|
if (!bakedFile.open(QIODevice::WriteOnly)) {
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "DomainBaker.h"
|
||||||
|
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
#include <QtCore/QEventLoop>
|
#include <QtCore/QEventLoop>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
|
@ -17,10 +19,9 @@
|
||||||
#include <QtCore/QJsonObject>
|
#include <QtCore/QJsonObject>
|
||||||
|
|
||||||
#include "Gzip.h"
|
#include "Gzip.h"
|
||||||
|
|
||||||
#include "Oven.h"
|
#include "Oven.h"
|
||||||
|
#include "FBXBaker.h"
|
||||||
#include "DomainBaker.h"
|
#include "OBJBaker.h"
|
||||||
|
|
||||||
DomainBaker::DomainBaker(const QUrl& localModelFileURL, const QString& domainName,
|
DomainBaker::DomainBaker(const QUrl& localModelFileURL, const QString& domainName,
|
||||||
const QString& baseOutputPath, const QUrl& destinationPath,
|
const QString& baseOutputPath, const QUrl& destinationPath,
|
||||||
|
@ -167,15 +168,18 @@ void DomainBaker::enumerateEntities() {
|
||||||
// check if the file pointed to by this URL is a bakeable model, by comparing extensions
|
// check if the file pointed to by this URL is a bakeable model, by comparing extensions
|
||||||
auto modelFileName = modelURL.fileName();
|
auto modelFileName = modelURL.fileName();
|
||||||
|
|
||||||
static const QString BAKEABLE_MODEL_EXTENSION { ".fbx" };
|
static const QString BAKEABLE_MODEL_FBX_EXTENSION { ".fbx" };
|
||||||
|
static const QString BAKEABLE_MODEL_OBJ_EXTENSION { ".obj" };
|
||||||
static const QString BAKED_MODEL_EXTENSION = ".baked.fbx";
|
static const QString BAKED_MODEL_EXTENSION = ".baked.fbx";
|
||||||
|
|
||||||
bool isBakedFBX = modelFileName.endsWith(BAKED_MODEL_EXTENSION, Qt::CaseInsensitive);
|
bool isBakedModel = modelFileName.endsWith(BAKED_MODEL_EXTENSION, Qt::CaseInsensitive);
|
||||||
bool isUnbakedFBX = modelFileName.endsWith(BAKEABLE_MODEL_EXTENSION, Qt::CaseInsensitive) && !isBakedFBX;
|
bool isBakeableFBX = modelFileName.endsWith(BAKEABLE_MODEL_FBX_EXTENSION, Qt::CaseInsensitive);
|
||||||
|
bool isBakeableOBJ = modelFileName.endsWith(BAKEABLE_MODEL_OBJ_EXTENSION, Qt::CaseInsensitive);
|
||||||
|
bool isBakeable = isBakeableFBX || isBakeableOBJ;
|
||||||
|
|
||||||
if (isUnbakedFBX || (_shouldRebakeOriginals && isBakedFBX)) {
|
if (isBakeable || (_shouldRebakeOriginals && isBakedModel)) {
|
||||||
|
|
||||||
if (isBakedFBX) {
|
if (isBakedModel) {
|
||||||
// grab a URL to the original, that we assume is stored a directory up, in the "original" folder
|
// grab a URL to the original, that we assume is stored a directory up, in the "original" folder
|
||||||
// with just the fbx extension
|
// with just the fbx extension
|
||||||
qDebug() << "Re-baking original for" << modelURL;
|
qDebug() << "Re-baking original for" << modelURL;
|
||||||
|
@ -190,7 +194,7 @@ void DomainBaker::enumerateEntities() {
|
||||||
modelURL = modelURL.adjusted(QUrl::RemoveQuery | QUrl::RemoveFragment);
|
modelURL = modelURL.adjusted(QUrl::RemoveQuery | QUrl::RemoveFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup an FBXBaker for this URL, as long as we don't already have one
|
// setup a ModelBaker for this URL, as long as we don't already have one
|
||||||
if (!_modelBakers.contains(modelURL)) {
|
if (!_modelBakers.contains(modelURL)) {
|
||||||
auto filename = modelURL.fileName();
|
auto filename = modelURL.fileName();
|
||||||
auto baseName = filename.left(filename.lastIndexOf('.'));
|
auto baseName = filename.left(filename.lastIndexOf('.'));
|
||||||
|
@ -199,12 +203,23 @@ void DomainBaker::enumerateEntities() {
|
||||||
while (QDir(_contentOutputPath + subDirName).exists()) {
|
while (QDir(_contentOutputPath + subDirName).exists()) {
|
||||||
subDirName = "/" + baseName + "-" + QString::number(i++);
|
subDirName = "/" + baseName + "-" + QString::number(i++);
|
||||||
}
|
}
|
||||||
QSharedPointer<FBXBaker> baker {
|
|
||||||
|
QSharedPointer<ModelBaker> baker;
|
||||||
|
if (isBakeableFBX) {
|
||||||
|
baker = {
|
||||||
new FBXBaker(modelURL, []() -> QThread* {
|
new FBXBaker(modelURL, []() -> QThread* {
|
||||||
return qApp->getNextWorkerThread();
|
return qApp->getNextWorkerThread();
|
||||||
}, _contentOutputPath + subDirName + "/baked", _contentOutputPath + subDirName + "/original"),
|
}, _contentOutputPath + subDirName + "/baked", _contentOutputPath + subDirName + "/original"),
|
||||||
&FBXBaker::deleteLater
|
&FBXBaker::deleteLater
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
baker = {
|
||||||
|
new OBJBaker(modelURL, []() -> QThread* {
|
||||||
|
return qApp->getNextWorkerThread();
|
||||||
|
}, _contentOutputPath + subDirName + "/baked", _contentOutputPath + subDirName + "/original"),
|
||||||
|
&FBXBaker::deleteLater
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// make sure our handler is called when the baker is done
|
// make sure our handler is called when the baker is done
|
||||||
connect(baker.data(), &Baker::finished, this, &DomainBaker::handleFinishedModelBaker);
|
connect(baker.data(), &Baker::finished, this, &DomainBaker::handleFinishedModelBaker);
|
||||||
|
|
|
@ -61,7 +61,7 @@ private:
|
||||||
|
|
||||||
QJsonArray _entities;
|
QJsonArray _entities;
|
||||||
|
|
||||||
QHash<QUrl, QSharedPointer<FBXBaker>> _modelBakers;
|
QHash<QUrl, QSharedPointer<ModelBaker>> _modelBakers;
|
||||||
QHash<QUrl, QSharedPointer<TextureBaker>> _skyboxBakers;
|
QHash<QUrl, QSharedPointer<TextureBaker>> _skyboxBakers;
|
||||||
|
|
||||||
QMultiHash<QUrl, QJsonValueRef> _entitiesNeedingRewrite;
|
QMultiHash<QUrl, QJsonValueRef> _entitiesNeedingRewrite;
|
||||||
|
|
Loading…
Reference in a new issue