ReFix the stuff before

Fix XFileExporter Normal
Fix Collada (Triangle->Poly)
pull/298/head
Madrich 2014-06-11 00:41:18 +02:00
parent 272a59cd36
commit edc7a950c4
9 changed files with 49 additions and 91 deletions

View File

@ -58,7 +58,7 @@ namespace Assimp
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
void ExportSceneCollada(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
void ExportSceneCollada(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
{
std::string path = "";
std::string file = pFile;
@ -634,13 +634,11 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
// 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 )
{
if (mesh->mFaces[a].mNumIndices == 2) countLines++;
else if (mesh->mFaces[a].mNumIndices == 3) countTriangles++;
else if (mesh->mFaces[a].mNumIndices > 3) countPoly++;
else if (mesh->mFaces[a].mNumIndices >= 3) countPoly++;
}
// lines
@ -662,34 +660,7 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
mOutput << startstr << "</lines>" << endstr;
}
// triangles, note for collada, triangles are defined in a right hand system
if (countTriangles)
{
mOutput << startstr << "<triangles count=\"" << countTriangles << "\" material=\"defaultMaterial\">" << endstr;
PushTag();
mOutput << startstr << "<input offset=\"0\" semantic=\"VERTEX\" source=\"#" << idstr << "-vertices\" />" << endstr;
mOutput << startstr << "<input offset=\"1\" 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;
// write vertix indices
for( size_t b = 0; b < face.mNumIndices; ++b )
{
mOutput << face.mIndices[b] << " ";
}
// write normal indices
for( size_t b = 0; b < face.mNumIndices; ++b )
{
mOutput << face.mIndices[b] << " ";
}
}
mOutput << "</p>" << endstr;
PopTag();
mOutput << startstr << "</triangles>" << endstr;
}
// triangle - dont use it, because compatibility problems
// polygons
if (countPoly)
@ -701,7 +672,7 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
mOutput << startstr << "<vcount>";
for( size_t a = 0; a < mesh->mNumFaces; ++a )
{
if (mesh->mFaces[a].mNumIndices <= 3) continue;
if (mesh->mFaces[a].mNumIndices < 3) continue;
mOutput << mesh->mFaces[a].mNumIndices << " ";
}
mOutput << "</vcount>" << endstr;
@ -710,7 +681,7 @@ void ColladaExporter::WriteGeometry( size_t pIndex)
for( size_t a = 0; a < mesh->mNumFaces; ++a )
{
const aiFace& face = mesh->mFaces[a];
if (face.mNumIndices <= 3) continue;
if (face.mNumIndices < 3) continue;
for( size_t b = 0; b < face.mNumIndices; ++b )
mOutput << face.mIndices[b] << " ";
}

View File

@ -140,16 +140,6 @@ void MakeLeftHandedProcess::ProcessMesh( aiMesh* pMesh)
pMesh->mTangents[a].z *= -1.0f;
pMesh->mBitangents[a].z *= -1.0f;
}
// texture coords for all channels
for (unsigned int c = 0; c < pMesh->GetNumUVChannels(); c++)
{
if (pMesh->HasTextureCoords(c))
{
pMesh->mTextureCoords[c][a].y = 1.0f - pMesh->mTextureCoords[c][a].y;
}
}
}
// mirror offset matrices of all bones

View File

@ -72,13 +72,13 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out);
// ------------------------------------------------------------------------------------------------
// Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype
// do not use const, because some exporter need to convert the scene temporary
void ExportSceneCollada(const char*,IOSystem*, aiScene*);
void ExportSceneXFile(const char*,IOSystem*, aiScene*);
void ExportSceneObj(const char*,IOSystem*, aiScene*);
void ExportSceneSTL(const char*,IOSystem*, aiScene*);
void ExportSceneSTLBinary(const char*,IOSystem*, aiScene*);
void ExportScenePly(const char*,IOSystem*, aiScene*);
void ExportScene3DS(const char*, IOSystem*, aiScene*) {}
void ExportSceneCollada(const char*,IOSystem*, const aiScene*);
void ExportSceneXFile(const char*,IOSystem*, const aiScene*);
void ExportSceneObj(const char*,IOSystem*, const aiScene*);
void ExportSceneSTL(const char*,IOSystem*, const aiScene*);
void ExportSceneSTLBinary(const char*,IOSystem*, const aiScene*);
void ExportScenePly(const char*,IOSystem*, const aiScene*);
void ExportScene3DS(const char*, IOSystem*, const aiScene*) {}
// ------------------------------------------------------------------------------------------------
// global array of all export formats which Assimp supports in its current build
@ -89,7 +89,8 @@ Exporter::ExportFormatEntry gExporters[] =
#endif
#ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER
Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile),
Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile,
aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs),
#endif
#ifndef ASSIMP_BUILD_NO_OBJ_EXPORTER

View File

@ -51,7 +51,7 @@ namespace Assimp {
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to Wavefront OBJ. Prototyped and registered in Exporter.cpp
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
{
// invoke the exporter
ObjExporter exporter(pFile, pScene);

View File

@ -50,7 +50,7 @@ namespace Assimp {
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
{
// invoke the exporter
PlyExporter exporter(pFile, pScene);

View File

@ -50,7 +50,7 @@ namespace Assimp {
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
{
// invoke the exporter
STLExporter exporter(pFile, pScene);
@ -63,7 +63,7 @@ void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
}
void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
{
// invoke the exporter
STLExporter exporter(pFile, pScene, true);

View File

@ -59,7 +59,7 @@ namespace Assimp
// ------------------------------------------------------------------------------------------------
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
{
std::string path = "";
std::string file = pFile;
@ -96,7 +96,7 @@ void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
// ------------------------------------------------------------------------------------------------
// Constructor for a specific scene to export
XFileExporter::XFileExporter(aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file) : mIOSystem(pIOSystem), mPath(path), mFile(file)
XFileExporter::XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file) : mIOSystem(pIOSystem), mPath(path), mFile(file)
{
// make sure that all formatting happens using the standard, C locale and not the user's current locale
mOutput.imbue( std::locale("C") );
@ -128,13 +128,6 @@ void XFileExporter::WriteFile()
mOutput.setf(_IOSfixed);
mOutput.precision(6); // precission for float
// the scene is already in OpenGL, applying MakeLeftHandedProcess, makes it xFile left handed
MakeLeftHandedProcess convertProcess;
FlipWindingOrderProcess flipper;
convertProcess.Execute(mScene);
flipper.Execute(mScene);
// entry of writing the file
WriteHeader();
@ -149,9 +142,6 @@ void XFileExporter::WriteFile()
mOutput << startstr << "}" << endstr;
// and back to OpenGL right handed
convertProcess.Execute(mScene);
flipper.Execute(mScene);
}
// ------------------------------------------------------------------------------------------------
@ -300,10 +290,15 @@ void XFileExporter::WriteFrameTransform(aiMatrix4x4& m)
// ------------------------------------------------------------------------------------------------
// Recursively writes the given node
void XFileExporter::WriteNode( const aiNode* pNode)
void XFileExporter::WriteNode( aiNode* pNode)
{
mOutput << startstr << "Frame " << pNode->mName.C_Str() << " {" << " // " << pNode->mName.C_Str() << endstr;
if (pNode->mName.length==0)
{
std::stringstream ss;
ss << "Node_" << pNode;
pNode->mName.Set(ss.str());
}
mOutput << startstr << "Frame " << pNode->mName.C_Str() << " {" << endstr;
PushTag();
@ -377,11 +372,12 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
PushTag();
mOutput << startstr << "1;" << endstr; // number of materials
mOutput << startstr << mesh->mNumFaces << ";" << endstr; // number of faces
mOutput << startstr;
for( size_t a = 0; a < mesh->mNumFaces; ++a )
{
mOutput << startstr << a;
mOutput << "0"; // the material index
if (a < mesh->mNumFaces - 1)
mOutput << "," << endstr;
mOutput << ", ";
else
mOutput << ";" << endstr;
}
@ -403,15 +399,15 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
}
// write normals (every vertex has one)
mOutput << endstr;
if (mesh->HasNormals())
{
mOutput << startstr << "MeshNormals {" << endstr;
mOutput << endstr << startstr << "MeshNormals {" << endstr;
mOutput << startstr << mesh->mNumVertices << ";" << endstr;
for (size_t a = 0; a < mesh->mNumVertices; a++)
{
aiVector3D &v = mesh->mNormals[a];
mOutput << startstr << v[0] << ";"<< v[1] << ";" << v[2] << ";";
// because we have a LHS and also changed wth winding, we need to invert the normals again
mOutput << startstr << -v[0] << ";"<< -v[1] << ";" << -v[2] << ";";
if (a < mesh->mNumVertices - 1)
mOutput << "," << endstr;
else
@ -446,7 +442,7 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
// write texture UVs if available
if (mesh->HasTextureCoords(0))
{
mOutput << startstr << "MeshTextureCoords {" << endstr;
mOutput << endstr << startstr << "MeshTextureCoords {" << endstr;
mOutput << startstr << mesh->mNumVertices << ";" << endstr;
for (size_t a = 0; a < mesh->mNumVertices; a++)
//for (int a = (int)mesh->mNumVertices-1; a >=0 ; a--)
@ -465,7 +461,7 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
// write color channel if available
if (mesh->HasVertexColors(0))
{
mOutput << startstr << "MeshVertexColors {" << endstr;
mOutput << endstr << startstr << "MeshVertexColors {" << endstr;
mOutput << startstr << mesh->mNumVertices << ";" << endstr;
for (size_t a = 0; a < mesh->mNumVertices; a++)
{
@ -478,15 +474,15 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
}
mOutput << startstr << "}" << endstr;
}
// test ...
/*
else
{
mOutput << startstr << "MeshVertexColors {" << endstr;
mOutput << endstr << startstr << "MeshVertexColors {" << endstr;
mOutput << startstr << mesh->mNumVertices << ";" << endstr;
for (size_t a = 0; a < mesh->mNumVertices; a++)
{
aiColor4D* mColors = mesh->mColors[a];
mOutput << startstr << a << ";0.500000;0.000000;0.000000;0.000000;;";
mOutput << startstr << a << ";0.500000;0.000000;0.000000;0.500000;;";
if (a < mesh->mNumVertices-1)
mOutput << "," << endstr;
else
@ -494,7 +490,7 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
}
mOutput << startstr << "}" << endstr;
}
*/
PopTag();
mOutput << startstr << "}" << endstr << endstr;

View File

@ -61,7 +61,7 @@ class XFileExporter
{
public:
/// Constructor for a specific scene to export
XFileExporter(aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file);
XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file);
/// Destructor
virtual ~XFileExporter();
@ -77,7 +77,7 @@ protected:
void WriteFrameTransform(aiMatrix4x4& m);
/// Recursively writes the given node
void WriteNode( const aiNode* pNode);
void WriteNode( aiNode* pNode );
/// write a mesh entry of the scene
void WriteMesh(const aiMesh* mesh);
@ -107,7 +107,7 @@ protected:
const std::string mFile;
/// The scene to be written
aiScene* mScene;
const aiScene* mScene;
bool mSceneOwned;
/// current line start string, contains the current indentation for simple stream insertion

View File

@ -81,7 +81,7 @@ class ASSIMP_API Exporter
public:
/** Function pointer type of a Export worker function */
typedef void (*fpExportFunc)(const char*,IOSystem*, aiScene*);
typedef void (*fpExportFunc)(const char*,IOSystem*, const aiScene*);
/** Internal description of an Assimp export format option */
struct ExportFormatEntry