mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 05:33:55 +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
libraries/baking/src
tools/oven/src
|
@ -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
|
||||
TextureBaker* bakedTexture = qobject_cast<TextureBaker*>(sender());
|
||||
|
||||
qDebug() << "Texture aborted: " << bakedTexture->getTextureURL();
|
||||
|
||||
if (bakedTexture) {
|
||||
_bakingTextures.remove(bakedTexture->getTextureURL());
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
ModelBaker(const QUrl& inputModelURL, TextureBakerThreadGetter inputTextureThreadGetter,
|
||||
const QString& bakedOutputDirectory, const QString& originalOutputDirectory = "");
|
||||
virtual ~ModelBaker();
|
||||
|
||||
bool compressMesh(FBXMesh& mesh, bool hasDeformers, FBXNode& dracoMeshNode, GetMaterialIDCallback materialIDCallback = nullptr);
|
||||
QString compressTexture(QString textureFileName, image::TextureUsage::Type = image::TextureUsage::Type::DEFAULT_TEXTURE);
|
||||
virtual void setWasAborted(bool wasAborted) override;
|
||||
|
|
|
@ -45,6 +45,16 @@ void OBJBaker::bake() {
|
|||
}
|
||||
|
||||
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
|
||||
if (_modelURL.isLocalFile()) {
|
||||
// loading the local OBJ
|
||||
|
@ -150,16 +160,6 @@ void OBJBaker::bakeOBJ() {
|
|||
|
||||
_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;
|
||||
bakedFile.setFileName(_bakedModelFilePath);
|
||||
if (!bakedFile.open(QIODevice::WriteOnly)) {
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "DomainBaker.h"
|
||||
|
||||
#include <QtConcurrent>
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QtCore/QFile>
|
||||
|
@ -17,10 +19,9 @@
|
|||
#include <QtCore/QJsonObject>
|
||||
|
||||
#include "Gzip.h"
|
||||
|
||||
#include "Oven.h"
|
||||
|
||||
#include "DomainBaker.h"
|
||||
#include "FBXBaker.h"
|
||||
#include "OBJBaker.h"
|
||||
|
||||
DomainBaker::DomainBaker(const QUrl& localModelFileURL, const QString& domainName,
|
||||
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
|
||||
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";
|
||||
|
||||
bool isBakedFBX = modelFileName.endsWith(BAKED_MODEL_EXTENSION, Qt::CaseInsensitive);
|
||||
bool isUnbakedFBX = modelFileName.endsWith(BAKEABLE_MODEL_EXTENSION, Qt::CaseInsensitive) && !isBakedFBX;
|
||||
bool isBakedModel = modelFileName.endsWith(BAKED_MODEL_EXTENSION, Qt::CaseInsensitive);
|
||||
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
|
||||
// with just the fbx extension
|
||||
qDebug() << "Re-baking original for" << modelURL;
|
||||
|
@ -190,7 +194,7 @@ void DomainBaker::enumerateEntities() {
|
|||
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)) {
|
||||
auto filename = modelURL.fileName();
|
||||
auto baseName = filename.left(filename.lastIndexOf('.'));
|
||||
|
@ -199,12 +203,23 @@ void DomainBaker::enumerateEntities() {
|
|||
while (QDir(_contentOutputPath + subDirName).exists()) {
|
||||
subDirName = "/" + baseName + "-" + QString::number(i++);
|
||||
}
|
||||
QSharedPointer<FBXBaker> baker {
|
||||
new FBXBaker(modelURL, []() -> QThread* {
|
||||
return qApp->getNextWorkerThread();
|
||||
}, _contentOutputPath + subDirName + "/baked", _contentOutputPath + subDirName + "/original"),
|
||||
&FBXBaker::deleteLater
|
||||
};
|
||||
|
||||
QSharedPointer<ModelBaker> baker;
|
||||
if (isBakeableFBX) {
|
||||
baker = {
|
||||
new FBXBaker(modelURL, []() -> QThread* {
|
||||
return qApp->getNextWorkerThread();
|
||||
}, _contentOutputPath + subDirName + "/baked", _contentOutputPath + subDirName + "/original"),
|
||||
&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
|
||||
connect(baker.data(), &Baker::finished, this, &DomainBaker::handleFinishedModelBaker);
|
||||
|
|
|
@ -61,7 +61,7 @@ private:
|
|||
|
||||
QJsonArray _entities;
|
||||
|
||||
QHash<QUrl, QSharedPointer<FBXBaker>> _modelBakers;
|
||||
QHash<QUrl, QSharedPointer<ModelBaker>> _modelBakers;
|
||||
QHash<QUrl, QSharedPointer<TextureBaker>> _skyboxBakers;
|
||||
|
||||
QMultiHash<QUrl, QJsonValueRef> _entitiesNeedingRewrite;
|
||||
|
|
Loading…
Reference in a new issue