From fb9e4d126673adf722dc00924dd1dd51487fadc3 Mon Sep 17 00:00:00 2001 From: Andreas Henne Date: Thu, 6 Aug 2015 13:30:49 +0200 Subject: [PATCH] Ply export now uses uchar as type for the number of vertices per polygon and int as vertex index type. --- code/PlyExporter.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/code/PlyExporter.cpp b/code/PlyExporter.cpp index 9268794f0..f8ff34fc2 100644 --- a/code/PlyExporter.cpp +++ b/code/PlyExporter.cpp @@ -189,7 +189,12 @@ PlyExporter::PlyExporter(const char* _filename, const aiScene* pScene, bool bina } mOutput << "element face " << faces << endl; - mOutput << "property list uint uint vertex_index" << endl; + + // uchar seems to be the most common type for the number of indices per polygon and int seems to be most common for the vertex indices. + // For instance, MeshLab fails to load meshes in which both types are uint. Houdini seems to have problems as well. + // Obviously, using unchar will not work for meshes with polygons with more than 255 indices, but how realistic is this case? + mOutput << "property list uchar int vertex_index" << endl; + mOutput << "end_header" << endl; for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) { @@ -342,16 +347,24 @@ void PlyExporter::WriteMeshIndices(const aiMesh* m, unsigned int offset) } } -void PlyExporter::WriteMeshIndicesBinary(const aiMesh* m, unsigned int offset) +// Generic method in case we want to use different data types for the indices or make this configurable. +template +void WriteMeshIndicesBinary_Generic(const aiMesh* m, unsigned int offset, std::ostringstream& output) { for (unsigned int i = 0; i < m->mNumFaces; ++i) { const aiFace& f = m->mFaces[i]; - mOutput.write(reinterpret_cast(&f.mNumIndices), 4); + NumIndicesType numIndices = static_cast(f.mNumIndices); + output.write(reinterpret_cast(&numIndices), sizeof(NumIndicesType)); for (unsigned int c = 0; c < f.mNumIndices; ++c) { - unsigned int index = f.mIndices[c] + offset; - mOutput.write(reinterpret_cast(&index), 4); + IndexType index = f.mIndices[c] + offset; + output.write(reinterpret_cast(&index), sizeof(IndexType)); } } } +void PlyExporter::WriteMeshIndicesBinary(const aiMesh* m, unsigned int offset) +{ + WriteMeshIndicesBinary_Generic(m, offset, mOutput); +} + #endif