From 3ad53ab630802be9f0ee2cbcdfd54acaa1b826e0 Mon Sep 17 00:00:00 2001 From: Trevor David Black Date: Wed, 8 Apr 2020 13:29:03 -0700 Subject: [PATCH] Printing file metadata --- code/Pbrt/PbrtExporter.cpp | 91 +++++++++++++++++++++++++++++++++++--- code/Pbrt/PbrtExporter.h | 16 ++++++- 2 files changed, 101 insertions(+), 6 deletions(-) diff --git a/code/Pbrt/PbrtExporter.cpp b/code/Pbrt/PbrtExporter.cpp index f89874571..1ce73e07e 100644 --- a/code/Pbrt/PbrtExporter.cpp +++ b/code/Pbrt/PbrtExporter.cpp @@ -100,7 +100,7 @@ PbrtExporter::PbrtExporter ( { std::unique_ptr outfile; - // open the indicated file for writing + // Open the indicated file for writing outfile.reset(mIOSystem->Open(mPath,"wt")); if (!outfile) { throw DeadlyExportError( @@ -108,10 +108,21 @@ PbrtExporter::PbrtExporter ( ); } - outfile->Write("Writing to pbrt file\n", 21 , 1); - outfile->Write(mPath.c_str(), mPath.size() , 1); - outfile->Write("\n", 1, 1); - outfile->Write(mFile.c_str(), mFile.size() , 1); + // Write Header + WriteHeader(); + + // Write metadata to file + WriteMetaData(); + + // Write preamble + WritePreamble(); + + // Write World Description + WriteWorldDefinition(); + + // Write out to file + outfile->Write(mOutput.str().c_str(), + mOutput.str().length(), 1); // explicitly release file pointer, // so we don't have to rely on class destruction. @@ -123,5 +134,75 @@ PbrtExporter::~PbrtExporter() { // Empty } +void PbrtExporter::WriteHeader() { + +} + +void PbrtExporter::WriteMetaData() { + mOutput << "# Writing out scene metadata:" << std::endl; + aiMetadata* pMetaData = mScene->mMetaData; + for (int i = 0; i < pMetaData->mNumProperties; i++) { + mOutput << "# - "; + mOutput << pMetaData->mKeys[i].C_Str() << " :"; + switch(pMetaData->mValues[i].mType) { + case AI_BOOL : { + mOutput << " "; + if (*static_cast(pMetaData->mValues[i].mData)) + mOutput << "TRUE" << std::endl; + else + mOutput << "FALSE" << std::endl; + break; + } + case AI_INT32 : { + mOutput << " " << + *static_cast(pMetaData->mValues[i].mData) << + std::endl; + break; + } + case AI_UINT64 : + mOutput << " " << + *static_cast(pMetaData->mValues[i].mData) << + std::endl; + break; + case AI_FLOAT : + mOutput << " " << + *static_cast(pMetaData->mValues[i].mData) << + std::endl; + break; + case AI_DOUBLE : + mOutput << " " << + *static_cast(pMetaData->mValues[i].mData) << + std::endl; + break; + case AI_AISTRING : { + aiString* value = + static_cast(pMetaData->mValues[i].mData); + std::string svalue = value->C_Str(); + std::size_t found = svalue.find_first_of("\n"); + mOutput << std::endl; + while (found != std::string::npos) { + mOutput << "# " << svalue.substr(0, found) << std::endl; + svalue = svalue.substr(found + 1); + found = svalue.find_first_of("\n"); + } + mOutput << "# " << svalue << std::endl; + break; + } + case AI_AIVECTOR3D : + + break; + } + mOutput << std::endl; + } +} + +void PbrtExporter::WritePreamble() { + +} + +void PbrtExporter::WriteWorldDefinition() { + +} + #endif // ASSIMP_BUILD_NO_PBRT_EXPORTER #endif // ASSIMP_BUILD_NO_EXPORT diff --git a/code/Pbrt/PbrtExporter.h b/code/Pbrt/PbrtExporter.h index 5df9221ca..a8b8a9ba8 100644 --- a/code/Pbrt/PbrtExporter.h +++ b/code/Pbrt/PbrtExporter.h @@ -83,7 +83,8 @@ public: virtual ~PbrtExporter(); private: - const aiScene* mScene; // the scene to export + // the scene to export + const aiScene* mScene; /// Stringstream to write all output into std::stringstream mOutput; @@ -96,6 +97,19 @@ private: /// Name of the file (without extension) where the scene will be exported const std::string mFile; + +private: + // Writing the comment header + void WriteHeader(); + + // Writing the metadata into a comment + void WriteMetaData(); + + // Writing the pbrt file preamble + void WritePreamble(); + + // Writing the pbrt world defintion + void WriteWorldDefinition(); }; } // namespace Assimp