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 } // 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) STLExporter::STLExporter(const char* _filename, const aiScene* pScene, bool exportPointClouds, bool binary)
@ -132,11 +134,26 @@ STLExporter::STLExporter(const char* _filename, const aiScene* pScene, bool expo
WriteMeshBinary(pScene->mMeshes[i]); WriteMeshBinary(pScene->mMeshes[i]);
} }
} else { } else {
const std::string& name = "AssimpScene";
// Exporting only point clouds // Exporting only point clouds
if (exportPointClouds) { if (exportPointClouds) {
mOutput << "solid " << name << endl; WritePointCloud("Assimp_Pointcloud", pScene );
return;
}
// 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 ]);
}
mOutput << EndSolidToken << name << endl;
}
}
// ------------------------------------------------------------------------------------------------
void STLExporter::WritePointCloud(const std::string &name, const aiScene* pScene) {
mOutput << " " << SolidToken << " " << name << endl;
aiVector3D nor; aiVector3D nor;
mOutput << " facet normal " << nor.x << " " << nor.y << " " << nor.z << endl; mOutput << " facet normal " << nor.x << " " << nor.y << " " << nor.z << endl;
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) { for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
@ -152,16 +169,7 @@ STLExporter::STLExporter(const char* _filename, const aiScene* pScene, bool expo
mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl; mOutput << " vertex " << v.x << " " << v.y << " " << v.z << endl;
} }
} }
mOutput << "endsolid " << name << endl; mOutput << EndSolidToken << name << endl;
return;
}
mOutput << "solid " << name << endl;
for(unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
WriteMesh(pScene->mMeshes[i]);
}
mOutput << "endsolid " << name << endl;
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

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