Extend Collada Exporter using lines and triangles
parent
84eb1930ea
commit
9ddd459fe8
|
@ -420,12 +420,12 @@ void ColladaExporter::WriteMaterials()
|
||||||
|
|
||||||
aiString name;
|
aiString name;
|
||||||
if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS )
|
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();
|
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 ) {
|
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
|
// 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.
|
// 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 = '_';
|
*it = '_';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -630,26 +630,83 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</vertices>" << endstr;
|
mOutput << startstr << "</vertices>" << endstr;
|
||||||
|
|
||||||
// write face setup
|
// count the number of lines, triangles and polygon meshes
|
||||||
mOutput << startstr << "<polylist count=\"" << mesh->mNumFaces << "\" material=\"theresonlyone\">" << endstr;
|
int countLines = 0;
|
||||||
PushTag();
|
int countTriangles = 0;
|
||||||
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstr << "-vertices\" />" << endstr;
|
int countPoly = 0;
|
||||||
|
|
||||||
mOutput << startstr << "<vcount>";
|
|
||||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
|
||||||
mOutput << mesh->mFaces[a].mNumIndices << " ";
|
|
||||||
mOutput << "</vcount>" << endstr;
|
|
||||||
|
|
||||||
mOutput << startstr << "<p>";
|
|
||||||
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
||||||
{
|
{
|
||||||
const aiFace& face = mesh->mFaces[a];
|
if (mesh->mFaces[a].mNumIndices == 2) countLines++;
|
||||||
for( size_t b = 0; b < face.mNumIndices; ++b )
|
else if (mesh->mFaces[a].mNumIndices == 3) countTriangles++;
|
||||||
mOutput << face.mIndices[b] << " ";
|
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
|
// closing tags
|
||||||
PopTag();
|
PopTag();
|
||||||
|
|
Loading…
Reference in New Issue