Pārlūkot izejas kodu

some refactorings.

Kim Kulling 7 gadi atpakaļ
vecāks
revīzija
eced86b949
2 mainītis faili ar 30 papildinājumiem un 22 dzēšanām
  1. 29 21
      code/STLExporter.cpp
  2. 1 1
      code/STLExporter.h

+ 29 - 21
code/STLExporter.cpp

@@ -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,36 +134,42 @@ 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 << 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 << "endsolid " << name << endl;
     }
+    mOutput << EndSolidToken << name << endl;
 }
 
 // ------------------------------------------------------------------------------------------------

+ 1 - 1
code/STLExporter.h

@@ -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);