From 2564432e71612971e25f1c533e35b4c12cd32dd2 Mon Sep 17 00:00:00 2001 From: frohlich Date: Tue, 3 Mar 2009 08:25:19 +0000 Subject: [PATCH] Avoid duplicate triangles. Modified Files: simgear/scene/bvh/BVHStaticGeometryBuilder.hxx --- simgear/scene/bvh/BVHStaticGeometryBuilder.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/simgear/scene/bvh/BVHStaticGeometryBuilder.hxx b/simgear/scene/bvh/BVHStaticGeometryBuilder.hxx index f754c542..98968162 100644 --- a/simgear/scene/bvh/BVHStaticGeometryBuilder.hxx +++ b/simgear/scene/bvh/BVHStaticGeometryBuilder.hxx @@ -18,6 +18,10 @@ #ifndef BVHStaticGeometryBuilder_hxx #define BVHStaticGeometryBuilder_hxx +#include +#include +#include + #include #include @@ -71,6 +75,9 @@ public: typedef std::map VertexMap; VertexMap _vertexMap; + typedef std::set > 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 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)); -- 2.39.5