diff options
Diffstat (limited to 'src/3rdparty/assimp/code/PlyExporter.cpp')
-rw-r--r-- | src/3rdparty/assimp/code/PlyExporter.cpp | 73 |
1 files changed, 45 insertions, 28 deletions
diff --git a/src/3rdparty/assimp/code/PlyExporter.cpp b/src/3rdparty/assimp/code/PlyExporter.cpp index e69c5e386..b20c2b328 100644 --- a/src/3rdparty/assimp/code/PlyExporter.cpp +++ b/src/3rdparty/assimp/code/PlyExporter.cpp @@ -2,7 +2,8 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2016, assimp team +Copyright (c) 2006-2017, assimp team + All rights reserved. Redistribution and use of this software in source and binary forms, @@ -56,13 +57,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //using namespace Assimp; namespace Assimp { +// make sure type_of returns consistent output across different platforms +// also consider using: typeid(VAR).name() +template <typename T> const char* type_of(T&) { return "unknown"; } +template<> const char* type_of(float&) { return "float"; } +template<> const char* type_of(double&) { return "double"; } + // ------------------------------------------------------------------------------------------------ // Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp -void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties) +void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/) { // invoke the exporter PlyExporter exporter(pFile, pScene); + if (exporter.mOutput.fail()) { + throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile)); + } + // we're still here - export successfully completed. Write the file. std::unique_ptr<IOStream> outfile (pIOSystem->Open(pFile,"wt")); if(outfile == NULL) { @@ -72,7 +83,7 @@ void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1); } -void ExportScenePlyBinary(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties) +void ExportScenePlyBinary(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/) { // invoke the exporter PlyExporter exporter(pFile, pScene, true); @@ -136,15 +147,21 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina << aiGetVersionMajor() << '.' << aiGetVersionMinor() << '.' << aiGetVersionRevision() << ")" << endl; + // TODO: probably want to check here rather than just assume something + // definitely not good to always write float even if we might have double precision + + ai_real tmp = 0.0; + const char * typeName = type_of(tmp); + mOutput << "element vertex " << vertices << endl; - mOutput << "property float x" << endl; - mOutput << "property float y" << endl; - mOutput << "property float z" << endl; + mOutput << "property " << typeName << " x" << endl; + mOutput << "property " << typeName << " y" << endl; + mOutput << "property " << typeName << " z" << endl; if(components & PLY_EXPORT_HAS_NORMALS) { - mOutput << "property float nx" << endl; - mOutput << "property float ny" << endl; - mOutput << "property float nz" << endl; + mOutput << "property " << typeName << " nx" << endl; + mOutput << "property " << typeName << " ny" << endl; + mOutput << "property " << typeName << " nz" << endl; } // write texcoords first, just in case an importer does not support tangents @@ -154,37 +171,37 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina // and texture coordinates). for (unsigned int n = PLY_EXPORT_HAS_TEXCOORDS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_TEXTURECOORDS; n <<= 1, ++c) { if (!c) { - mOutput << "property float s" << endl; - mOutput << "property float t" << endl; + mOutput << "property " << typeName << " s" << endl; + mOutput << "property " << typeName << " t" << endl; } else { - mOutput << "property float s" << c << endl; - mOutput << "property float t" << c << endl; + mOutput << "property " << typeName << " s" << c << endl; + mOutput << "property " << typeName << " t" << c << endl; } } for (unsigned int n = PLY_EXPORT_HAS_COLORS, c = 0; (components & n) && c != AI_MAX_NUMBER_OF_COLOR_SETS; n <<= 1, ++c) { if (!c) { - mOutput << "property float r" << endl; - mOutput << "property float g" << endl; - mOutput << "property float b" << endl; - mOutput << "property float a" << endl; + mOutput << "property " << typeName << " r" << endl; + mOutput << "property " << typeName << " g" << endl; + mOutput << "property " << typeName << " b" << endl; + mOutput << "property " << typeName << " a" << endl; } else { - mOutput << "property float r" << c << endl; - mOutput << "property float g" << c << endl; - mOutput << "property float b" << c << endl; - mOutput << "property float a" << c << endl; + mOutput << "property " << typeName << " r" << c << endl; + mOutput << "property " << typeName << " g" << c << endl; + mOutput << "property " << typeName << " b" << c << endl; + mOutput << "property " << typeName << " a" << c << endl; } } if(components & PLY_EXPORT_HAS_TANGENTS_BITANGENTS) { - mOutput << "property float tx" << endl; - mOutput << "property float ty" << endl; - mOutput << "property float tz" << endl; - mOutput << "property float bx" << endl; - mOutput << "property float by" << endl; - mOutput << "property float bz" << endl; + mOutput << "property " << typeName << " tx" << endl; + mOutput << "property " << typeName << " ty" << endl; + mOutput << "property " << typeName << " tz" << endl; + mOutput << "property " << typeName << " bx" << endl; + mOutput << "property " << typeName << " by" << endl; + mOutput << "property " << typeName << " bz" << endl; } mOutput << "element face " << faces << endl; @@ -223,7 +240,7 @@ PlyExporter::~PlyExporter() { // ------------------------------------------------------------------------------------------------ void PlyExporter::WriteMeshVerts(const aiMesh* m, unsigned int components) { - static const float inf = std::numeric_limits<float>::infinity(); + static const ai_real inf = std::numeric_limits<ai_real>::infinity(); // If a component (for instance normal vectors) is present in at least one mesh in the scene, // then default values are written for meshes that do not contain this component. |