From 9ddd459fe88d67cff7b57c30dde4921306c091b3 Mon Sep 17 00:00:00 2001 From: Madrich Date: Sat, 31 May 2014 12:50:07 +0200 Subject: [PATCH] Extend Collada Exporter using lines and triangles --- code/ColladaExporter.cpp | 95 ++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index cb392acf0..6cfef2246 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -420,12 +420,12 @@ void ColladaExporter::WriteMaterials() aiString name; if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS ) - name = "mat"; + name = "mat"; materials[a].name = std::string( "m") + boost::lexical_cast (a) + name.C_Str(); for( std::string::iterator it = materials[a].name.begin(); it != materials[a].name.end(); ++it ) { // isalnum on MSVC asserts for code points in [0,255]. Thus prevent unwanted promotion // of char to signed int and take the unsigned char value. - if( !isalnum( static_cast(*it) ) ) { + if( !isalnum( static_cast(*it) ) ) { *it = '_'; } } @@ -630,26 +630,83 @@ void ColladaExporter::WriteGeometry( size_t pIndex) PopTag(); mOutput << startstr << "" << endstr; - // write face setup - mOutput << startstr << "mNumFaces << "\" material=\"theresonlyone\">" << endstr; - PushTag(); - mOutput << startstr << "" << endstr; - - mOutput << startstr << ""; - for( size_t a = 0; a < mesh->mNumFaces; ++a ) - mOutput << mesh->mFaces[a].mNumIndices << " "; - mOutput << "" << endstr; - - mOutput << startstr << "

"; + // count the number of lines, triangles and polygon meshes + int countLines = 0; + int countTriangles = 0; + int countPoly = 0; for( size_t a = 0; a < mesh->mNumFaces; ++a ) { - const aiFace& face = mesh->mFaces[a]; - for( size_t b = 0; b < face.mNumIndices; ++b ) - mOutput << face.mIndices[b] << " "; + if (mesh->mFaces[a].mNumIndices == 2) countLines++; + else if (mesh->mFaces[a].mNumIndices == 3) countTriangles++; + else if (mesh->mFaces[a].mNumIndices > 3) countPoly++; + } + + // lines + if (countLines) + { + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" << endstr; + mOutput << startstr << "

"; + for( size_t a = 0; a < mesh->mNumFaces; ++a ) + { + const aiFace& face = mesh->mFaces[a]; + if (face.mNumIndices != 2) continue; + for( size_t b = 0; b < face.mNumIndices; ++b ) + mOutput << face.mIndices[b] << " "; + } + mOutput << "

" << endstr; + PopTag(); + mOutput << startstr << "" << endstr; + } + + // triangles + if (countTriangles) + { + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" << endstr; + mOutput << startstr << "" << endstr; + mOutput << startstr << "

"; + for( size_t a = 0; a < mesh->mNumFaces; ++a ) + { + const aiFace& face = mesh->mFaces[a]; + if (face.mNumIndices != 3) continue; + for( size_t b = 0; b < face.mNumIndices; ++b ) + mOutput << face.mIndices[b] << " "; + } + mOutput << "

" << endstr; + PopTag(); + mOutput << startstr << "
" << endstr; + } + + // polygons + if (countPoly) + { + mOutput << startstr << "" << endstr; + PushTag(); + mOutput << startstr << "" << endstr; + + mOutput << startstr << ""; + for( size_t a = 0; a < mesh->mNumFaces; ++a ) + { + if (mesh->mFaces[a].mNumIndices <= 3) continue; + mOutput << mesh->mFaces[a].mNumIndices << " "; + } + mOutput << "" << endstr; + + mOutput << startstr << "

"; + for( size_t a = 0; a < mesh->mNumFaces; ++a ) + { + const aiFace& face = mesh->mFaces[a]; + if (face.mNumIndices <= 3) continue; + for( size_t b = 0; b < face.mNumIndices; ++b ) + mOutput << face.mIndices[b] << " "; + } + mOutput << "

" << endstr; + PopTag(); + mOutput << startstr << "
" << endstr; } - mOutput << "

" << endstr; - PopTag(); - mOutput << startstr << "
" << endstr; // closing tags PopTag();