Refactorings: come code cleanups

pull/5401/head
Kim Kulling 2023-12-29 16:47:21 +01:00 committed by Kim Kulling
parent 263bebb5ba
commit 636fbd65b3
3 changed files with 26 additions and 50 deletions

View File

@ -89,15 +89,11 @@ using namespace Assimp;
namespace Assimp { namespace Assimp {
void ExportScenePbrt ( void ExportScenePbrt(const char *pFile, IOSystem *pIOSystem, const aiScene *pScene,
const char* pFile, const ExportProperties *) {
IOSystem* pIOSystem,
const aiScene* pScene,
const ExportProperties* /*pProperties*/
){
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"; path = path + file + ".pbrt";
// initialize the exporter // initialize the exporter
PbrtExporter exporter(pScene, pIOSystem, path, file); PbrtExporter exporter(pScene, pIOSystem, path, file);
} }
@ -114,7 +110,6 @@ static void create_embedded_textures_folder(const aiScene *scene, IOSystem *pIOS
} }
} }
// Constructor
PbrtExporter::PbrtExporter( PbrtExporter::PbrtExporter(
const aiScene *pScene, IOSystem *pIOSystem, const aiScene *pScene, IOSystem *pIOSystem,
const std::string &path, const std::string &file) : const std::string &path, const std::string &file) :
@ -186,9 +181,6 @@ PbrtExporter::PbrtExporter(
outfile->Write(mOutput.str().c_str(), mOutput.str().length(), 1); outfile->Write(mOutput.str().c_str(), mOutput.str().length(), 1);
} }
// Destructor
PbrtExporter::~PbrtExporter() = default;
void PbrtExporter::WriteMetaData() { void PbrtExporter::WriteMetaData() {
mOutput << "#############################\n"; mOutput << "#############################\n";
mOutput << "# Scene metadata:\n"; mOutput << "# Scene metadata:\n";

View File

@ -70,15 +70,33 @@ class ExportProperties;
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** Helper class to export a given scene to a Pbrt file. */ /** Helper class to export a given scene to a Pbrt file. */
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
class PbrtExporter class PbrtExporter {
{
public: public:
/// Constructor for a specific scene to export /// Constructor for a specific scene to export
PbrtExporter(const aiScene *pScene, IOSystem *pIOSystem, PbrtExporter(const aiScene *pScene, IOSystem *pIOSystem,
const std::string &path, const std::string &file); const std::string &path, const std::string &file);
/// Destructor /// Destructor
virtual ~PbrtExporter(); virtual ~PbrtExporter() = default;
private:
aiMatrix4x4 GetNodeTransform(const aiString &name) const;
static std::string TransformAsString(const aiMatrix4x4 &m);
static std::string RemoveSuffix(std::string filename);
std::string CleanTextureFilename(const aiString &f, bool rewriteExtension = true) const;
void WriteMetaData();
void WriteWorldDefinition();
void WriteCameras();
void WriteCamera(int i);
void WriteLights();
void WriteTextures();
static bool TextureHasAlphaMask(const std::string &filename);
void WriteMaterials();
void WriteMaterial(int i);
void WriteMesh(aiMesh *mesh);
void WriteInstanceDefinition(int i);
void WriteGeometricObjects(aiNode *node, aiMatrix4x4 parentTransform,
std::map<int, int> &meshUses);
private: private:
// the scene to export // the scene to export
@ -96,39 +114,11 @@ private:
/// Name of the file (without extension) where the scene will be exported /// Name of the file (without extension) where the scene will be exported
const std::string mFile; const std::string mFile;
private:
// A private set to keep track of which textures have been declared // A private set to keep track of which textures have been declared
std::set<std::string> mTextureSet; std::set<std::string> mTextureSet;
// Transform to apply to the root node and all root objects such as cameras, lights, etc. // Transform to apply to the root node and all root objects such as cameras, lights, etc.
aiMatrix4x4 mRootTransform; aiMatrix4x4 mRootTransform;
aiMatrix4x4 GetNodeTransform(const aiString& name) const;
static std::string TransformAsString(const aiMatrix4x4& m);
static std::string RemoveSuffix(std::string filename);
std::string CleanTextureFilename(const aiString &f, bool rewriteExtension = true) const;
void WriteMetaData();
void WriteWorldDefinition();
void WriteCameras();
void WriteCamera(int i);
void WriteLights();
void WriteTextures();
static bool TextureHasAlphaMask(const std::string &filename);
void WriteMaterials();
void WriteMaterial(int i);
void WriteMesh(aiMesh* mesh);
void WriteInstanceDefinition(int i);
void WriteGeometricObjects(aiNode* node, aiMatrix4x4 parentTransform,
std::map<int, int> &meshUses);
}; };
} // namespace Assimp } // namespace Assimp

View File

@ -97,7 +97,7 @@ public:
* Create an instance of your derived class and assign it to an * Create an instance of your derived class and assign it to an
* #Assimp::Importer instance by calling Importer::SetIOHandler(). * #Assimp::Importer instance by calling Importer::SetIOHandler().
*/ */
IOSystem() AI_NO_EXCEPT; IOSystem() AI_NO_EXCEPT = default;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** @brief Virtual destructor. /** @brief Virtual destructor.
@ -105,7 +105,7 @@ public:
* It is safe to be called from within DLL Assimp, we're constructed * It is safe to be called from within DLL Assimp, we're constructed
* on Assimp's heap. * on Assimp's heap.
*/ */
virtual ~IOSystem(); virtual ~IOSystem() = default;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** @brief For backward compatibility /** @brief For backward compatibility
@ -236,12 +236,6 @@ private:
std::vector<std::string> m_pathStack; std::vector<std::string> m_pathStack;
}; };
// ----------------------------------------------------------------------------
AI_FORCE_INLINE IOSystem::IOSystem() AI_NO_EXCEPT = default;
// ----------------------------------------------------------------------------
AI_FORCE_INLINE IOSystem::~IOSystem() = default;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// For compatibility, the interface of some functions taking a std::string was // For compatibility, the interface of some functions taking a std::string was
// changed to const char* to avoid crashes between binary incompatible STL // changed to const char* to avoid crashes between binary incompatible STL