fix: write textures to folder of PBRT file (#6099)
* fix: write textures to folder of PBRT file
This commit is contained in:
@@ -93,17 +93,22 @@ void ExportScenePbrt(const char *pFile, IOSystem *pIOSystem, const aiScene *pSce
|
||||
const ExportProperties *) {
|
||||
std::string path = DefaultIOSystem::absolutePath(std::string(pFile));
|
||||
std::string file = DefaultIOSystem::completeBaseName(std::string(pFile));
|
||||
std::string texturesPath = path;
|
||||
if (!texturesPath.empty()) {
|
||||
texturesPath+=pIOSystem->getOsSeparator();
|
||||
}
|
||||
texturesPath+="textures";
|
||||
|
||||
// initialize the exporter
|
||||
PbrtExporter exporter(pScene, pIOSystem, path, file);
|
||||
PbrtExporter exporter(pScene, pIOSystem, path, file, texturesPath);
|
||||
}
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
static void create_embedded_textures_folder(const aiScene *scene, IOSystem *pIOSystem) {
|
||||
static void create_embedded_textures_folder(const aiScene *scene, IOSystem *pIOSystem, const std::string &texturesPath) {
|
||||
if (scene->mNumTextures > 0) {
|
||||
if (!pIOSystem->Exists("textures")) {
|
||||
if (!pIOSystem->CreateDirectory("textures")) {
|
||||
if (!pIOSystem->Exists(texturesPath)) {
|
||||
if (!pIOSystem->CreateDirectory(texturesPath)) {
|
||||
throw DeadlyExportError("Could not create textures/ directory.");
|
||||
}
|
||||
}
|
||||
@@ -112,11 +117,12 @@ static void create_embedded_textures_folder(const aiScene *scene, IOSystem *pIOS
|
||||
|
||||
PbrtExporter::PbrtExporter(
|
||||
const aiScene *pScene, IOSystem *pIOSystem,
|
||||
const std::string &path, const std::string &file) :
|
||||
const std::string &path, const std::string &file, const std::string &texturesPath) :
|
||||
mScene(pScene),
|
||||
mIOSystem(pIOSystem),
|
||||
mPath(path),
|
||||
mFile(file),
|
||||
mTexturesPath(texturesPath),
|
||||
mRootTransform(
|
||||
// rotates the (already left-handed) CRS -90 degrees around the x axis in order to
|
||||
// make +Z 'up' and +Y 'towards viewer', as in default in pbrt
|
||||
@@ -134,7 +140,7 @@ PbrtExporter::PbrtExporter(
|
||||
) * mRootTransform;
|
||||
|
||||
// Export embedded textures.
|
||||
create_embedded_textures_folder(mScene, mIOSystem);
|
||||
create_embedded_textures_folder(mScene, mIOSystem, mTexturesPath);
|
||||
|
||||
for (unsigned int i = 0; i < mScene->mNumTextures; ++i) {
|
||||
aiTexture* tex = mScene->mTextures[i];
|
||||
@@ -684,7 +690,7 @@ std::string PbrtExporter::CleanTextureFilename(const aiString &f, bool rewriteEx
|
||||
}
|
||||
|
||||
// Expect all textures in textures
|
||||
fn = std::string("textures") + mIOSystem->getOsSeparator() + fn;
|
||||
fn = mTexturesPath + mIOSystem->getOsSeparator() + fn;
|
||||
|
||||
// Rewrite extension for unsupported file formats.
|
||||
if (rewriteExtension) {
|
||||
|
||||
@@ -74,7 +74,7 @@ class PbrtExporter {
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
PbrtExporter(const aiScene *pScene, IOSystem *pIOSystem,
|
||||
const std::string &path, const std::string &file);
|
||||
const std::string &path, const std::string &file, const std::string &texturesPath);
|
||||
|
||||
/// Destructor
|
||||
virtual ~PbrtExporter() = default;
|
||||
@@ -114,6 +114,9 @@ private:
|
||||
/// Name of the file (without extension) where the scene will be exported
|
||||
const std::string mFile;
|
||||
|
||||
/// Path of the textures directory (inlcuding seperator)
|
||||
const std::string mTexturesPath;
|
||||
|
||||
// A private set to keep track of which textures have been declared
|
||||
std::set<std::string> mTextureSet;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user