some refactorings.

pull/1935/head
Kim Kulling 2018-05-01 13:41:39 +02:00
parent 2c47717ca6
commit eced86b949
2 changed files with 30 additions and 22 deletions

View File

@ -100,6 +100,8 @@ void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene*
} // end of namespace Assimp
static const char *SolidToken = "solid";
static const char *EndSolidToken = "endsolid";
// ------------------------------------------------------------------------------------------------
STLExporter::STLExporter(const char* _filename, const aiScene* pScene, bool exportPointClouds, bool binary)
@ -132,38 +134,44 @@ STLExporter::STLExporter(const char* _filename, const aiScene* pScene, bool expo
WriteMeshBinary(pScene->mMeshes[i]);
}
} else {
const std::string& name = "AssimpScene";
// Exporting only point clouds
if (exportPointClouds) {
mOutput << "solid " << name << endl;
aiVector3D nor;
mOutput << " facet normal " << nor.x << " " << nor.y << " " << nor.z << endl;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
aiMesh *mesh = pScene->mMeshes[i];
if (nullptr == mesh) {
continue;
}
for (unsigned int a = 0; a < mesh->mNumVertices; ++a) {
const aiVector3D& v = mesh->mVertices[a];
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
}
}
mOutput << "endsolid " << name << endl;
WritePointCloud("Assimp_Pointcloud", pScene );
return;
}
mOutput << "solid " << name << endl;
// Export the assimp mesh
const std::string name = "AssimpScene";
mOutput << SolidToken << name << endl;
for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
WriteMesh(pScene->mMeshes[i]);
WriteMesh(pScene->mMeshes[ i ]);
}
mOutput << "endsolid " << name << endl;
mOutput << EndSolidToken << name << endl;
}
}
// ------------------------------------------------------------------------------------------------
void STLExporter::WritePointCloud(const std::string &name, const aiScene* pScene) {
mOutput << " " << SolidToken << " " << name << endl;
aiVector3D nor;
mOutput << " facet normal " << nor.x << " " << nor.y << " " << nor.z << endl;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
aiMesh *mesh = pScene->mMeshes[i];
if (nullptr == mesh) {
continue;
}
for (unsigned int a = 0; a < mesh->mNumVertices; ++a) {
const aiVector3D& v = mesh->mVertices[a];
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
}
}
mOutput << EndSolidToken << name << endl;
}
// ------------------------------------------------------------------------------------------------
void STLExporter::WriteMesh(const aiMesh* m)
{

View File

@ -67,7 +67,7 @@ public:
std::ostringstream mOutput;
private:
void WritePointCloud(const std::string &name, const aiScene* pScene);
void WriteMesh(const aiMesh* m);
void WriteMeshBinary(const aiMesh* m);