Extend Collada Exporter using lines and triangles
parent
84eb1930ea
commit
9ddd459fe8
|
@ -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<std::string> (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<uint8_t>(*it) ) ) {
|
||||
if( !isalnum( static_cast<uint8_t>(*it) ) ) {
|
||||
*it = '_';
|
||||
}
|
||||
}
|
||||
|
@ -630,26 +630,83 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
|||
PopTag();
|
||||
mOutput << startstr << "</vertices>" << endstr;
|
||||
|
||||
// write face setup
|
||||
mOutput << startstr << "<polylist count=\"" << mesh->mNumFaces << "\" material=\"theresonlyone\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstr << "-vertices\" />" << endstr;
|
||||
|
||||
mOutput << startstr << "<vcount>";
|
||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
||||
mOutput << mesh->mFaces[a].mNumIndices << " ";
|
||||
mOutput << "</vcount>" << endstr;
|
||||
|
||||
mOutput << startstr << "<p>";
|
||||
// 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 << "<lines count=\"" << countLines << "\" material=\"theresonlyone\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstr << "-vertices\" />" << endstr;
|
||||
mOutput << startstr << "<p>";
|
||||
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 << "</p>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</lines>" << endstr;
|
||||
}
|
||||
|
||||
// triangles
|
||||
if (countTriangles)
|
||||
{
|
||||
mOutput << startstr << "<triangles count=\"" << countTriangles << "\" material=\"theresonlyone\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstr << "-vertices\" />" << endstr;
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"NORMAL\" source=\"#" << idstr << "-normals\" />" << endstr;
|
||||
mOutput << startstr << "<p>";
|
||||
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 << "</p>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</triangles>" << endstr;
|
||||
}
|
||||
|
||||
// polygons
|
||||
if (countPoly)
|
||||
{
|
||||
mOutput << startstr << "<polylist count=\"" << countPoly << "\" material=\"theresonlyone\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstr << "-vertices\" />" << endstr;
|
||||
|
||||
mOutput << startstr << "<vcount>";
|
||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
||||
{
|
||||
if (mesh->mFaces[a].mNumIndices <= 3) continue;
|
||||
mOutput << mesh->mFaces[a].mNumIndices << " ";
|
||||
}
|
||||
mOutput << "</vcount>" << endstr;
|
||||
|
||||
mOutput << startstr << "<p>";
|
||||
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 << "</p>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</polylist>" << endstr;
|
||||
}
|
||||
mOutput << "</p>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</polylist>" << endstr;
|
||||
|
||||
// closing tags
|
||||
PopTag();
|
||||
|
|
Loading…
Reference in New Issue