Merge pull request #13221 from huffman/feat/oven-cli-texture-options

Add more texture options to Oven CLI
This commit is contained in:
Stephen Birarda 2018-06-11 12:01:56 -07:00 committed by GitHub
commit b41c80f31e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 18 deletions

View file

@ -157,18 +157,19 @@ void TextureBaker::processTexture() {
return;
}
const char* name = khronos::gl::texture::toString(memKTX->_header.getGLInternaFormat());
if (name == nullptr) {
handleError("Could not determine internal format for compressed KTX: " + _textureURL.toString());
return;
}
// attempt to write the baked texture to the destination file path
{
if (memKTX->_header.isCompressed()) {
const char* name = khronos::gl::texture::toString(memKTX->_header.getGLInternaFormat());
if (name == nullptr) {
handleError("Could not determine internal format for compressed KTX: " + _textureURL.toString());
return;
}
const char* data = reinterpret_cast<const char*>(memKTX->_storage->data());
const size_t length = memKTX->_storage->size();
auto fileName = _baseFilename + BAKED_TEXTURE_BCN_SUFFIX;
auto fileName = _baseFilename + "_" + name + ".ktx";
auto filePath = _outputDirectory.absoluteFilePath(fileName);
QFile bakedTextureFile { filePath };
if (!bakedTextureFile.open(QIODevice::WriteOnly) || bakedTextureFile.write(data, length) == -1) {
@ -177,6 +178,18 @@ void TextureBaker::processTexture() {
}
_outputFiles.push_back(filePath);
meta.availableTextureTypes[memKTX->_header.getGLInternaFormat()] = _metaTexturePathPrefix + fileName;
} else {
const char* data = reinterpret_cast<const char*>(memKTX->_storage->data());
const size_t length = memKTX->_storage->size();
auto fileName = _baseFilename + ".ktx";
auto filePath = _outputDirectory.absoluteFilePath(fileName);
QFile ktxTextureFile { filePath };
if (!ktxTextureFile.open(QIODevice::WriteOnly) || ktxTextureFile.write(data, length) == -1) {
handleError("Could not write ktx texture for " + _textureURL.toString());
return;
}
_outputFiles.push_back(filePath);
}

View file

@ -38,6 +38,11 @@ ResourceManager::ResourceManager(bool atpSupportEnabled) : _atpSupportEnabled(at
_thread.start();
}
ResourceManager::~ResourceManager() {
_thread.terminate();
_thread.wait();
}
void ResourceManager::setUrlPrefixOverride(const QString& prefix, const QString& replacement) {
QMutexLocker locker(&_prefixMapLock);
if (replacement.isEmpty()) {

View file

@ -28,6 +28,7 @@ class ResourceManager: public QObject, public Dependency {
public:
ResourceManager(bool atpSupportEnabled = true);
~ResourceManager();
void setUrlPrefixOverride(const QString& prefix, const QString& replacement);
QString normalizeURL(const QString& urlString);

View file

@ -16,6 +16,8 @@
#include <QtCore/QDebug>
#include <QFile>
#include <unordered_map>
#include "OvenCLIApplication.h"
#include "ModelBakingLoggingCategory.h"
#include "FBXBaker.h"
@ -38,17 +40,15 @@ void BakerCLI::bakeFile(QUrl inputUrl, const QString& outputPath, const QString&
static const QString MODEL_EXTENSION { "fbx" };
static const QString SCRIPT_EXTENSION { "js" };
QString extension = type;
if (extension.isNull()) {
auto url = inputUrl.toDisplayString();
extension = url.mid(url.lastIndexOf('.'));
}
// check what kind of baker we should be creating
bool isFBX = extension == MODEL_EXTENSION;
bool isScript = extension == SCRIPT_EXTENSION;
bool isFBX = type == MODEL_EXTENSION;
bool isScript = type == SCRIPT_EXTENSION;
// If the type doesn't match the above, we assume we have a texture, and the type specified is the
// texture usage type (albedo, cubemap, normals, etc.)
auto url = inputUrl.toDisplayString();
auto idx = url.lastIndexOf('.');
auto extension = idx >= 0 ? url.mid(idx + 1).toLower() : "";
bool isSupportedImage = QImageReader::supportedImageFormats().contains(extension.toLatin1());
_outputPath = outputPath;
@ -65,7 +65,29 @@ void BakerCLI::bakeFile(QUrl inputUrl, const QString& outputPath, const QString&
_baker = std::unique_ptr<Baker> { new JSBaker(inputUrl, outputPath) };
_baker->moveToThread(Oven::instance().getNextWorkerThread());
} else if (isSupportedImage) {
_baker = std::unique_ptr<Baker> { new TextureBaker(inputUrl, image::TextureUsage::CUBE_TEXTURE, outputPath) };
static const std::unordered_map<QString, image::TextureUsage::Type> STRING_TO_TEXTURE_USAGE_TYPE_MAP {
{ "default", image::TextureUsage::DEFAULT_TEXTURE },
{ "strict", image::TextureUsage::STRICT_TEXTURE },
{ "albedo", image::TextureUsage::ALBEDO_TEXTURE },
{ "normal", image::TextureUsage::NORMAL_TEXTURE },
{ "bump", image::TextureUsage::BUMP_TEXTURE },
{ "specular", image::TextureUsage::SPECULAR_TEXTURE },
{ "metallic", image::TextureUsage::METALLIC_TEXTURE },
{ "roughness", image::TextureUsage::ROUGHNESS_TEXTURE },
{ "gloss", image::TextureUsage::GLOSS_TEXTURE },
{ "emissive", image::TextureUsage::EMISSIVE_TEXTURE },
{ "cube", image::TextureUsage::CUBE_TEXTURE },
{ "occlusion", image::TextureUsage::OCCLUSION_TEXTURE },
{ "scattering", image::TextureUsage::SCATTERING_TEXTURE },
{ "lightmap", image::TextureUsage::LIGHTMAP_TEXTURE },
};
auto it = STRING_TO_TEXTURE_USAGE_TYPE_MAP.find(type);
if (it == STRING_TO_TEXTURE_USAGE_TYPE_MAP.end()) {
qCDebug(model_baking) << "Unknown texture usage type:" << type;
QCoreApplication::exit(OVEN_STATUS_CODE_FAIL);
}
_baker = std::unique_ptr<Baker> { new TextureBaker(inputUrl, it->second, outputPath) };
_baker->moveToThread(Oven::instance().getNextWorkerThread());
} else {
qCDebug(model_baking) << "Failed to determine baker type for file" << inputUrl;

View file

@ -14,11 +14,14 @@
#include <QtCore/QCommandLineParser>
#include <QtCore/QUrl>
#include <image/Image.h>
#include "BakerCLI.h"
static const QString CLI_INPUT_PARAMETER = "i";
static const QString CLI_OUTPUT_PARAMETER = "o";
static const QString CLI_TYPE_PARAMETER = "t";
static const QString CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER = "disable-texture-compression";
OvenCLIApplication::OvenCLIApplication(int argc, char* argv[]) :
QCoreApplication(argc, argv)
@ -29,7 +32,8 @@ OvenCLIApplication::OvenCLIApplication(int argc, char* argv[]) :
parser.addOptions({
{ CLI_INPUT_PARAMETER, "Path to file that you would like to bake.", "input" },
{ CLI_OUTPUT_PARAMETER, "Path to folder that will be used as output.", "output" },
{ CLI_TYPE_PARAMETER, "Type of asset.", "type" }
{ CLI_TYPE_PARAMETER, "Type of asset.", "type" },
{ CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER, "Disable texture compression." }
});
parser.addHelpOption();
@ -40,6 +44,15 @@ OvenCLIApplication::OvenCLIApplication(int argc, char* argv[]) :
QUrl inputUrl(QDir::fromNativeSeparators(parser.value(CLI_INPUT_PARAMETER)));
QUrl outputUrl(QDir::fromNativeSeparators(parser.value(CLI_OUTPUT_PARAMETER)));
QString type = parser.isSet(CLI_TYPE_PARAMETER) ? parser.value(CLI_TYPE_PARAMETER) : QString::null;
if (parser.isSet(CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER)) {
qDebug() << "Disabling texture compression";
image::setColorTexturesCompressionEnabled(false);
image::setGrayscaleTexturesCompressionEnabled(false);
image::setNormalTexturesCompressionEnabled(false);
image::setCubeTexturesCompressionEnabled(false);
}
QMetaObject::invokeMethod(cli, "bakeFile", Qt::QueuedConnection, Q_ARG(QUrl, inputUrl),
Q_ARG(QString, outputUrl.toString()), Q_ARG(QString, type));
} else {