Remove some redundancy involving model texture URL resolution

This commit is contained in:
sabrina-shanman 2019-03-15 15:32:39 -07:00
parent 60ed9e12a4
commit 53429f459e
3 changed files with 7 additions and 11 deletions

View file

@ -43,7 +43,6 @@ private:
void replaceMeshNodeWithDraco(FBXNode& meshNode, const QByteArray& dracoMeshBytes, const std::vector<hifi::ByteArray>& dracoMaterialList); void replaceMeshNodeWithDraco(FBXNode& meshNode, const QByteArray& dracoMeshBytes, const std::vector<hifi::ByteArray>& dracoMaterialList);
hfm::Model::Pointer _hfmModel; hfm::Model::Pointer _hfmModel;
QHash<QUrl, QString> _remappedTexturePaths;
bool _pendingErrorEmission { false }; bool _pendingErrorEmission { false };
}; };

View file

@ -408,7 +408,7 @@ QString ModelBaker::compressTexture(QString modelTextureFileName, image::Texture
if (!modelTextureFileInfo.filePath().isEmpty()) { if (!modelTextureFileInfo.filePath().isEmpty()) {
textureContent = _textureContentMap.value(modelTextureFileName.toLocal8Bit()); textureContent = _textureContentMap.value(modelTextureFileName.toLocal8Bit());
} }
auto urlToTexture = getTextureURL(modelTextureFileInfo, modelTextureFileName, !textureContent.isNull()); auto urlToTexture = getTextureURL(modelTextureFileInfo, !textureContent.isNull());
QString baseTextureFileName; QString baseTextureFileName;
if (_remappedTexturePaths.contains(urlToTexture)) { if (_remappedTexturePaths.contains(urlToTexture)) {
@ -559,14 +559,11 @@ void ModelBaker::handleAbortedTexture() {
checkIfTexturesFinished(); checkIfTexturesFinished();
} }
QUrl ModelBaker::getTextureURL(const QFileInfo& textureFileInfo, QString relativeFileName, bool isEmbedded) { QUrl ModelBaker::getTextureURL(const QFileInfo& textureFileInfo, bool isEmbedded) {
QUrl urlToTexture; QUrl urlToTexture;
// use QFileInfo to easily split up the existing texture filename into its components
auto apparentRelativePath = QFileInfo(relativeFileName.replace("\\", "/"));
if (isEmbedded) { if (isEmbedded) {
urlToTexture = _modelURL.toString() + "/" + apparentRelativePath.filePath(); urlToTexture = _modelURL.toString() + "/" + textureFileInfo.filePath();
} else { } else {
if (textureFileInfo.exists() && textureFileInfo.isFile()) { if (textureFileInfo.exists() && textureFileInfo.isFile()) {
// set the texture URL to the local texture that we have confirmed exists // set the texture URL to the local texture that we have confirmed exists
@ -576,14 +573,14 @@ QUrl ModelBaker::getTextureURL(const QFileInfo& textureFileInfo, QString relativ
// this is a relative file path which will require different handling // this is a relative file path which will require different handling
// depending on the location of the original model // depending on the location of the original model
if (_modelURL.isLocalFile() && apparentRelativePath.exists() && apparentRelativePath.isFile()) { if (_modelURL.isLocalFile() && textureFileInfo.exists() && textureFileInfo.isFile()) {
// the absolute path we ran into for the texture in the model exists on this machine // the absolute path we ran into for the texture in the model exists on this machine
// so use that file // so use that file
urlToTexture = QUrl::fromLocalFile(apparentRelativePath.absoluteFilePath()); urlToTexture = QUrl::fromLocalFile(textureFileInfo.absoluteFilePath());
} else { } else {
// we didn't find the texture on this machine at the absolute path // we didn't find the texture on this machine at the absolute path
// so assume that it is right beside the model to match the behaviour of interface // so assume that it is right beside the model to match the behaviour of interface
urlToTexture = _modelURL.resolved(apparentRelativePath.fileName()); urlToTexture = _modelURL.resolved(textureFileInfo.fileName());
} }
} }
} }

View file

@ -98,7 +98,7 @@ private slots:
void handleAbortedTexture(); void handleAbortedTexture();
private: private:
QUrl getTextureURL(const QFileInfo& textureFileInfo, QString relativeFileName, bool isEmbedded = false); QUrl getTextureURL(const QFileInfo& textureFileInfo, bool isEmbedded = false);
void bakeTexture(const QUrl & textureURL, image::TextureUsage::Type textureType, const QDir & outputDir, void bakeTexture(const QUrl & textureURL, image::TextureUsage::Type textureType, const QDir & outputDir,
const QString & bakedFilename, const QByteArray & textureContent); const QString & bakedFilename, const QByteArray & textureContent);
QString texturePathRelativeToModel(QUrl modelURL, QUrl textureURL); QString texturePathRelativeToModel(QUrl modelURL, QUrl textureURL);