]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/bvh/BVHStaticGeometryBuilder.hxx
Remove using std:: from the metar header, remove HTTP support, add very basic unit...
[simgear.git] / simgear / scene / bvh / BVHStaticGeometryBuilder.hxx
index 88bfd8e49ee934ce4552b7c9eb511baa59e7d6b7..98968162e7bebbf872fbfae878c71efb69e1b969 100644 (file)
 #ifndef BVHStaticGeometryBuilder_hxx
 #define BVHStaticGeometryBuilder_hxx
 
+#include <algorithm>
+#include <map>
+#include <set>
+
 #include <simgear/structure/SGReferenced.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 
@@ -71,6 +75,9 @@ public:
     typedef std::map<SGVec3f, unsigned> VertexMap;
     VertexMap _vertexMap;
 
+    typedef std::set<SGVec3<unsigned> > TriangleSet;
+    TriangleSet _triangleSet;
+
     void setCurrentMaterial(const SGMaterial* material)
     {
         _currentMaterial = material;
@@ -98,6 +105,11 @@ public:
     void addTriangle(const SGVec3f& v1, const SGVec3f& v2, const SGVec3f& v3)
     {
         unsigned indices[3] = { addVertex(v1), addVertex(v2), addVertex(v3) };
+        std::sort(indices, indices + 3);
+        SGVec3<unsigned> indexKey(indices);
+        if (_triangleSet.find(indexKey) != _triangleSet.end())
+            return;
+        _triangleSet.insert(indexKey);
         BVHStaticTriangle* staticTriangle;
         staticTriangle = new BVHStaticTriangle(_currentMaterialIndex, indices);
         _leafRefList.push_back(LeafRef(staticTriangle, *_staticData));
@@ -117,6 +129,7 @@ public:
         const BVHStaticNode* tree = buildTreeRecursive(_leafRefList);
         if (!tree)
             return 0;
+        _staticData->trim();
         return new BVHStaticGeometry(tree, _staticData);
     }