parent
c4021fbaaf
commit
272a59cd36
|
@ -58,7 +58,7 @@ namespace Assimp
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
|
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
|
||||||
void ExportSceneCollada(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
void ExportSceneCollada(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
|
||||||
{
|
{
|
||||||
std::string path = "";
|
std::string path = "";
|
||||||
std::string file = pFile;
|
std::string file = pFile;
|
||||||
|
|
|
@ -134,12 +134,22 @@ void MakeLeftHandedProcess::ProcessMesh( aiMesh* pMesh)
|
||||||
{
|
{
|
||||||
pMesh->mVertices[a].z *= -1.0f;
|
pMesh->mVertices[a].z *= -1.0f;
|
||||||
if( pMesh->HasNormals())
|
if( pMesh->HasNormals())
|
||||||
pMesh->mNormals[a].z *= -1.0f;
|
pMesh->mNormals[a].z *= -1.0f;
|
||||||
if( pMesh->HasTangentsAndBitangents())
|
if( pMesh->HasTangentsAndBitangents())
|
||||||
{
|
{
|
||||||
pMesh->mTangents[a].z *= -1.0f;
|
pMesh->mTangents[a].z *= -1.0f;
|
||||||
pMesh->mBitangents[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
|
// mirror offset matrices of all bones
|
||||||
|
|
|
@ -71,13 +71,14 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype
|
// Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype
|
||||||
void ExportSceneCollada(const char*,IOSystem*, const aiScene*);
|
// do not use const, because some exporter need to convert the scene temporary
|
||||||
void ExportSceneXFile(const char*,IOSystem*, const aiScene*);
|
void ExportSceneCollada(const char*,IOSystem*, aiScene*);
|
||||||
void ExportSceneObj(const char*,IOSystem*, const aiScene*);
|
void ExportSceneXFile(const char*,IOSystem*, aiScene*);
|
||||||
void ExportSceneSTL(const char*,IOSystem*, const aiScene*);
|
void ExportSceneObj(const char*,IOSystem*, aiScene*);
|
||||||
void ExportSceneSTLBinary(const char*,IOSystem*, const aiScene*);
|
void ExportSceneSTL(const char*,IOSystem*, aiScene*);
|
||||||
void ExportScenePly(const char*,IOSystem*, const aiScene*);
|
void ExportSceneSTLBinary(const char*,IOSystem*, aiScene*);
|
||||||
void ExportScene3DS(const char*, IOSystem*, const aiScene*) {}
|
void ExportScenePly(const char*,IOSystem*, aiScene*);
|
||||||
|
void ExportScene3DS(const char*, IOSystem*, aiScene*) {}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// global array of all export formats which Assimp supports in its current build
|
// global array of all export formats which Assimp supports in its current build
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace Assimp {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Worker function for exporting a scene to Wavefront OBJ. Prototyped and registered in Exporter.cpp
|
// Worker function for exporting a scene to Wavefront OBJ. Prototyped and registered in Exporter.cpp
|
||||||
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
|
||||||
{
|
{
|
||||||
// invoke the exporter
|
// invoke the exporter
|
||||||
ObjExporter exporter(pFile, pScene);
|
ObjExporter exporter(pFile, pScene);
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace Assimp {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp
|
// Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp
|
||||||
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
|
||||||
{
|
{
|
||||||
// invoke the exporter
|
// invoke the exporter
|
||||||
PlyExporter exporter(pFile, pScene);
|
PlyExporter exporter(pFile, pScene);
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace Assimp {
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp
|
// Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp
|
||||||
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
|
||||||
{
|
{
|
||||||
// invoke the exporter
|
// invoke the exporter
|
||||||
STLExporter exporter(pFile, pScene);
|
STLExporter exporter(pFile, pScene);
|
||||||
|
@ -63,7 +63,7 @@ void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene
|
||||||
|
|
||||||
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
|
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
|
||||||
}
|
}
|
||||||
void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
|
||||||
{
|
{
|
||||||
// invoke the exporter
|
// invoke the exporter
|
||||||
STLExporter exporter(pFile, pScene, true);
|
STLExporter exporter(pFile, pScene, true);
|
||||||
|
|
|
@ -44,7 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||||
#ifndef ASSIMP_BUILD_NO_XFILE_EXPORTER
|
#ifndef ASSIMP_BUILD_NO_XFILE_EXPORTER
|
||||||
#include "XFileExporter.h"
|
#include "XFileExporter.h"
|
||||||
|
#include "ConvertToLHProcess.h"
|
||||||
#include "Bitmap.h"
|
#include "Bitmap.h"
|
||||||
#include "fast_atof.h"
|
#include "fast_atof.h"
|
||||||
#include "SceneCombiner.h"
|
#include "SceneCombiner.h"
|
||||||
|
@ -59,7 +59,7 @@ namespace Assimp
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
|
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
|
||||||
void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, aiScene* pScene)
|
||||||
{
|
{
|
||||||
std::string path = "";
|
std::string path = "";
|
||||||
std::string file = pFile;
|
std::string file = pFile;
|
||||||
|
@ -96,7 +96,7 @@ void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pSce
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructor for a specific scene to export
|
// Constructor for a specific scene to export
|
||||||
XFileExporter::XFileExporter( const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file) : mIOSystem(pIOSystem), mPath(path), mFile(file)
|
XFileExporter::XFileExporter(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
|
// make sure that all formatting happens using the standard, C locale and not the user's current locale
|
||||||
mOutput.imbue( std::locale("C") );
|
mOutput.imbue( std::locale("C") );
|
||||||
|
@ -128,6 +128,13 @@ void XFileExporter::WriteFile()
|
||||||
mOutput.setf(_IOSfixed);
|
mOutput.setf(_IOSfixed);
|
||||||
mOutput.precision(6); // precission for float
|
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
|
// entry of writing the file
|
||||||
WriteHeader();
|
WriteHeader();
|
||||||
|
|
||||||
|
@ -141,6 +148,10 @@ void XFileExporter::WriteFile()
|
||||||
PopTag();
|
PopTag();
|
||||||
|
|
||||||
mOutput << startstr << "}" << endstr;
|
mOutput << startstr << "}" << endstr;
|
||||||
|
|
||||||
|
// and back to OpenGL right handed
|
||||||
|
convertProcess.Execute(mScene);
|
||||||
|
flipper.Execute(mScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -277,11 +288,11 @@ void XFileExporter::WriteHeader()
|
||||||
void XFileExporter::WriteFrameTransform(aiMatrix4x4& m)
|
void XFileExporter::WriteFrameTransform(aiMatrix4x4& m)
|
||||||
{
|
{
|
||||||
mOutput << startstr << "FrameTransformMatrix {" << endstr << " ";
|
mOutput << startstr << "FrameTransformMatrix {" << endstr << " ";
|
||||||
PushTag();
|
PushTag();
|
||||||
mOutput << startstr << m.a1 << "," << m.a2 << "," << m.a3 << "," << m.a4 << ","
|
mOutput << startstr << m.a1 << "," << m.b1 << "," << m.c1 << "," << m.d1 << "," << endstr;
|
||||||
<< m.b1 << "," << m.b2 << "," << m.b3 << "," << m.b4 << ","
|
mOutput << startstr << m.a2 << "," << m.b2 << "," << m.c2 << "," << m.d2 << "," << endstr;
|
||||||
<< m.c1 << "," << m.c2 << "," << m.c3 << "," << m.c4 << ","
|
mOutput << startstr << m.a3 << "," << m.b3 << "," << m.c3 << "," << m.d3 << "," << endstr;
|
||||||
<< m.d1 << "," << m.d2 << "," << m.d3 << "," << m.d4 << ";;" << endstr;
|
mOutput << startstr << m.a4 << "," << m.b4 << "," << m.c4 << "," << m.d4 << ";;" << endstr;
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "}" << endstr << endstr;
|
mOutput << startstr << "}" << endstr << endstr;
|
||||||
}
|
}
|
||||||
|
@ -291,11 +302,12 @@ void XFileExporter::WriteFrameTransform(aiMatrix4x4& m)
|
||||||
// Recursively writes the given node
|
// Recursively writes the given node
|
||||||
void XFileExporter::WriteNode( const aiNode* pNode)
|
void XFileExporter::WriteNode( const aiNode* pNode)
|
||||||
{
|
{
|
||||||
mOutput << startstr << "Frame " << pNode->mName.C_Str() << " {" << endstr;
|
|
||||||
|
mOutput << startstr << "Frame " << pNode->mName.C_Str() << " {" << " // " << pNode->mName.C_Str() << endstr;
|
||||||
|
|
||||||
PushTag();
|
PushTag();
|
||||||
|
|
||||||
aiMatrix4x4 m;// = pNode->mTransformation;
|
aiMatrix4x4 m = pNode->mTransformation;
|
||||||
|
|
||||||
WriteFrameTransform(m);
|
WriteFrameTransform(m);
|
||||||
|
|
||||||
|
@ -353,6 +365,43 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
|
||||||
mOutput << ";" << endstr;
|
mOutput << ";" << endstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mOutput << endstr;
|
||||||
|
|
||||||
|
if (mesh->HasTextureCoords(0))
|
||||||
|
{
|
||||||
|
const aiMaterial* mat = mScene->mMaterials[mesh->mMaterialIndex];
|
||||||
|
aiString relpath;
|
||||||
|
mat->Get(_AI_MATKEY_TEXTURE_BASE, aiTextureType_DIFFUSE, 0, relpath);
|
||||||
|
|
||||||
|
mOutput << startstr << "MeshMaterialList {" << endstr;
|
||||||
|
PushTag();
|
||||||
|
mOutput << startstr << "1;" << endstr; // number of materials
|
||||||
|
mOutput << startstr << mesh->mNumFaces << ";" << endstr; // number of faces
|
||||||
|
for( size_t a = 0; a < mesh->mNumFaces; ++a )
|
||||||
|
{
|
||||||
|
mOutput << startstr << a;
|
||||||
|
if (a < mesh->mNumFaces - 1)
|
||||||
|
mOutput << "," << endstr;
|
||||||
|
else
|
||||||
|
mOutput << ";" << endstr;
|
||||||
|
}
|
||||||
|
mOutput << startstr << "Material {" << endstr;
|
||||||
|
PushTag();
|
||||||
|
mOutput << startstr << "1.0; 1.0; 1.0; 1.000000;;" << endstr;
|
||||||
|
mOutput << startstr << "1.000000;" << endstr; // power
|
||||||
|
mOutput << startstr << "0.000000; 0.000000; 0.000000;;" << endstr; // specularity
|
||||||
|
mOutput << startstr << "0.000000; 0.000000; 0.000000;;" << endstr; // emission
|
||||||
|
mOutput << startstr << "TextureFilename { \"";
|
||||||
|
|
||||||
|
writePath(relpath);
|
||||||
|
|
||||||
|
mOutput << "\"; }" << endstr;
|
||||||
|
PopTag();
|
||||||
|
mOutput << startstr << "}" << endstr;
|
||||||
|
PopTag();
|
||||||
|
mOutput << startstr << "}" << endstr;
|
||||||
|
}
|
||||||
|
|
||||||
// write normals (every vertex has one)
|
// write normals (every vertex has one)
|
||||||
mOutput << endstr;
|
mOutput << endstr;
|
||||||
if (mesh->HasNormals())
|
if (mesh->HasNormals())
|
||||||
|
@ -400,10 +449,12 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
|
||||||
mOutput << startstr << "MeshTextureCoords {" << endstr;
|
mOutput << startstr << "MeshTextureCoords {" << endstr;
|
||||||
mOutput << startstr << mesh->mNumVertices << ";" << endstr;
|
mOutput << startstr << mesh->mNumVertices << ";" << endstr;
|
||||||
for (size_t a = 0; a < mesh->mNumVertices; a++)
|
for (size_t a = 0; a < mesh->mNumVertices; a++)
|
||||||
|
//for (int a = (int)mesh->mNumVertices-1; a >=0 ; a--)
|
||||||
{
|
{
|
||||||
aiVector3D& uv = mesh->mTextureCoords[0][a]; // uv of first uv layer for the vertex
|
aiVector3D& uv = mesh->mTextureCoords[0][a]; // uv of first uv layer for the vertex
|
||||||
mOutput << uv.x << ";" << uv.y;
|
mOutput << startstr << uv.x << ";" << uv.y;
|
||||||
if (a < mesh->mNumVertices-1)
|
if (a < mesh->mNumVertices-1)
|
||||||
|
//if (a >0 )
|
||||||
mOutput << ";," << endstr;
|
mOutput << ";," << endstr;
|
||||||
else
|
else
|
||||||
mOutput << ";;" << endstr;
|
mOutput << ";;" << endstr;
|
||||||
|
@ -449,6 +500,22 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XFileExporter::writePath(aiString path)
|
||||||
|
{
|
||||||
|
std::string str = std::string(path.C_Str());
|
||||||
|
BaseImporter::ConvertUTF8toISO8859_1(str);
|
||||||
|
|
||||||
|
while( str.find( "\\\\") != std::string::npos)
|
||||||
|
str.replace( str.find( "\\\\"), 2, "\\");
|
||||||
|
|
||||||
|
while( str.find( "\\") != std::string::npos)
|
||||||
|
str.replace( str.find( "\\"), 1, "/");
|
||||||
|
|
||||||
|
mOutput << str;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -55,13 +55,13 @@ struct aiNode;
|
||||||
namespace Assimp
|
namespace Assimp
|
||||||
{
|
{
|
||||||
|
|
||||||
/// Helper class to export a given scene to a Collada file. Just for my personal
|
/// Helper class to export a given scene to a X-file.
|
||||||
/// comfort when implementing it.
|
/// Note: an xFile uses a left hand system. Assimp used a right hand system (OpenGL), therefore we have to transform everything
|
||||||
class XFileExporter
|
class XFileExporter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Constructor for a specific scene to export
|
/// Constructor for a specific scene to export
|
||||||
XFileExporter( const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file);
|
XFileExporter(aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~XFileExporter();
|
virtual ~XFileExporter();
|
||||||
|
@ -93,6 +93,10 @@ public:
|
||||||
std::stringstream mOutput;
|
std::stringstream mOutput;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/// write a path
|
||||||
|
void writePath(aiString path);
|
||||||
|
|
||||||
/// The IOSystem for output
|
/// The IOSystem for output
|
||||||
IOSystem* mIOSystem;
|
IOSystem* mIOSystem;
|
||||||
|
|
||||||
|
@ -103,11 +107,12 @@ protected:
|
||||||
const std::string mFile;
|
const std::string mFile;
|
||||||
|
|
||||||
/// The scene to be written
|
/// The scene to be written
|
||||||
const aiScene* mScene;
|
aiScene* mScene;
|
||||||
bool mSceneOwned;
|
bool mSceneOwned;
|
||||||
|
|
||||||
/// current line start string, contains the current indentation for simple stream insertion
|
/// current line start string, contains the current indentation for simple stream insertion
|
||||||
std::string startstr;
|
std::string startstr;
|
||||||
|
|
||||||
/// current line end string for simple stream insertion
|
/// current line end string for simple stream insertion
|
||||||
std::string endstr;
|
std::string endstr;
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ class ASSIMP_API Exporter
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Function pointer type of a Export worker function */
|
/** Function pointer type of a Export worker function */
|
||||||
typedef void (*fpExportFunc)(const char*,IOSystem*,const aiScene*);
|
typedef void (*fpExportFunc)(const char*,IOSystem*, aiScene*);
|
||||||
|
|
||||||
/** Internal description of an Assimp export format option */
|
/** Internal description of an Assimp export format option */
|
||||||
struct ExportFormatEntry
|
struct ExportFormatEntry
|
||||||
|
|
Loading…
Reference in New Issue