Add a test before generating the txture folder

pull/5401/head
Kim Kulling 2023-12-29 16:30:42 +01:00 committed by Kim Kulling
parent 5d5496f1ad
commit 263bebb5ba
3 changed files with 85 additions and 4 deletions

View File

@ -97,13 +97,23 @@ void ExportScenePbrt (
){ ){
std::string path = DefaultIOSystem::absolutePath(std::string(pFile)); std::string path = DefaultIOSystem::absolutePath(std::string(pFile));
std::string file = DefaultIOSystem::completeBaseName(std::string(pFile)); std::string file = DefaultIOSystem::completeBaseName(std::string(pFile));
path = path + file + ".brt";
// initialize the exporter // initialize the exporter
PbrtExporter exporter(pScene, pIOSystem, path, file); PbrtExporter exporter(pScene, pIOSystem, path, file);
} }
} // end of namespace Assimp } // end of namespace Assimp
static void create_embedded_textures_folder(const aiScene *scene, IOSystem *pIOSystem) {
if (scene->mNumTextures > 0) {
if (!pIOSystem->Exists("textures")) {
if (!pIOSystem->CreateDirectory("textures")) {
throw DeadlyExportError("Could not create textures/ directory.");
}
}
}
}
// Constructor // Constructor
PbrtExporter::PbrtExporter( PbrtExporter::PbrtExporter(
const aiScene *pScene, IOSystem *pIOSystem, const aiScene *pScene, IOSystem *pIOSystem,
@ -127,10 +137,10 @@ PbrtExporter::PbrtExporter(
0.f, 0.f, 1.f, 0.f, // 0.f, 0.f, 1.f, 0.f, //
0.f, 0.f, 0.f, 1.f // 0.f, 0.f, 0.f, 1.f //
) * mRootTransform; ) * mRootTransform;
// Export embedded textures. // Export embedded textures.
if (mScene->mNumTextures > 0) create_embedded_textures_folder(mScene, mIOSystem);
if (!mIOSystem->CreateDirectory("textures"))
throw DeadlyExportError("Could not create textures/ directory.");
for (unsigned int i = 0; i < mScene->mNumTextures; ++i) { for (unsigned int i = 0; i < mScene->mNumTextures; ++i) {
aiTexture* tex = mScene->mTextures[i]; aiTexture* tex = mScene->mTextures[i];
std::string fn = CleanTextureFilename(tex->mFilename, false); std::string fn = CleanTextureFilename(tex->mFilename, false);

View File

@ -165,6 +165,7 @@ SET( IMPORTERS
unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp
unit/ImportExport/RAW/utRAWImportExport.cpp unit/ImportExport/RAW/utRAWImportExport.cpp
unit/ImportExport/Terragen/utTerragenImportExport.cpp unit/ImportExport/Terragen/utTerragenImportExport.cpp
unit/ImportExport/Pbrt/utPbrtImportExport.cpp
) )
SET( MATERIAL SET( MATERIAL

View File

@ -0,0 +1,70 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#include "AbstractImportExportBase.h"
#include "UnitTestPCH.h"
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <assimp/Exporter.hpp>
using namespace Assimp;
class utPbrtImportExport : public AbstractImportExportBase {
public:
#ifndef ASSIMP_BUILD_NO_EXPORT
bool exporterTest() override {
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/spider.obj", aiProcess_ValidateDataStructure);
EXPECT_NE(scene, nullptr );
::Assimp::Exporter exporter;
return AI_SUCCESS == exporter.Export(scene, "pbrt", ASSIMP_TEST_MODELS_DIR "/OBJ/spider_out.pbrt");
}
#endif
};
#ifndef ASSIMP_BUILD_NO_EXPORT
TEST_F(utPbrtImportExport, exportTest_Success) {
EXPECT_TRUE(exporterTest());
}
#endif // ASSIMP_BUILD_NO_EXPORT