diff --git a/include/light/phong.hh b/include/light/phong.hh index a7befb92..b5ee833d 100644 --- a/include/light/phong.hh +++ b/include/light/phong.hh @@ -35,7 +35,19 @@ #include -std::vector FacesOverlappingEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const dmodel_t *model); +class neighbour_t { +public: + const bsp2_dface_t *face; + qvec3f p0, p1; + + neighbour_t(const bsp2_dface_t *f, const qvec3f p0in, const qvec3f p1in) + : face(f), + p0(p0in), + p1(p1in) { + } +}; + +std::vector FacesOverlappingEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const dmodel_t *model); void CalcualateVertexNormals(const mbsp_t *bsp); const qvec3f GetSurfaceVertexNormal(const mbsp_t *bsp, const bsp2_dface_t *f, const int vertindex); diff --git a/light/ltface.cc b/light/ltface.cc index 660092b2..46e471d3 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -409,7 +409,6 @@ PositionSamplePointOnFace(const mbsp_t *bsp, const qvec3f &point, const qvec3f &modelOffset); - std::vector NeighbouringFaces_old(const mbsp_t *bsp, const bsp2_dface_t *face) { std::vector result; @@ -423,26 +422,25 @@ std::vector NeighbouringFaces_old(const mbsp_t *bsp, const return result; } -std::vector NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face) +std::vector NeighbouringFaces_new(const mbsp_t *bsp, const bsp2_dface_t *face) { - std::set resultset; + std::vector result; + std::set used_faces; + for (int i=0; inumedges; i++) { vec3_t p0, p1; Face_PointAtIndex(bsp, face, i, p0); Face_PointAtIndex(bsp, face, (i + 1) % face->numedges, p1); - const std::vector tmp = FacesOverlappingEdge(p0, p1, bsp, &bsp->dmodels[0]); - for (const bsp2_dface_t *f : tmp) { - if (f != face) { - resultset.insert(f); + const std::vector tmp = FacesOverlappingEdge(p0, p1, bsp, &bsp->dmodels[0]); + for (const auto &neighbour : tmp) { + if (neighbour.face != face && used_faces.find(neighbour.face) == used_faces.end()) { + used_faces.insert(neighbour.face); + result.push_back(neighbour); } } } - std::vector result; - for (const bsp2_dface_t *f : resultset) { - result.push_back(f); - } return result; } @@ -2062,10 +2060,10 @@ LightFace_DebugNeighbours(lightsurf_t *lightsurf, lightmapdict_t *lightmaps) const int fnum = Face_GetNum(lightsurf->bsp, lightsurf->face); - std::vector neighbours = NeighbouringFaces_new(lightsurf->bsp, BSP_GetFace(lightsurf->bsp, dump_facenum)); + std::vector neighbours = NeighbouringFaces_new(lightsurf->bsp, BSP_GetFace(lightsurf->bsp, dump_facenum)); bool found = false; for (auto &f : neighbours) { - if (f == lightsurf->face) + if (f.face == lightsurf->face) found = true; } diff --git a/light/phong.cc b/light/phong.cc index 1a64ebde..831bd1a3 100644 --- a/light/phong.cc +++ b/light/phong.cc @@ -42,7 +42,7 @@ using namespace std; -static bool +static neighbour_t FaceOverlapsEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const bsp2_dface_t *f) { for (int edgeindex = 0; edgeindex < f->numedges; edgeindex++) { @@ -52,14 +52,14 @@ FaceOverlapsEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const bsp2 const qvec3f v0point = Vertex_GetPos_E(bsp, v0); const qvec3f v1point = Vertex_GetPos_E(bsp, v1); if (LinesOverlap(vec3_t_to_glm(p0), vec3_t_to_glm(p1), v0point, v1point)) { - return true; + return neighbour_t{f, v0point, v1point}; } } - return false; + return neighbour_t{nullptr, qvec3f{}, qvec3f{}}; } static void -FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int nodenum, vector *result) +FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int nodenum, vector *result) { if (nodenum < 0) { // we don't do anything for leafs. @@ -67,7 +67,6 @@ FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int return; } - const bsp2_dnode_t *node = BSP_GetNode(bsp, nodenum); const dplane_t *plane = BSP_GetPlane(bsp, node->planenum); const vec_t p0dist = Plane_Dist(p0, plane); @@ -77,8 +76,9 @@ FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int // check all faces on this node. for (int i=0; inumfaces; i++) { const bsp2_dface_t *face = BSP_GetFace(bsp, node->firstface + i); - if (FaceOverlapsEdge(p0, p1, bsp, face)) { - result->push_back(face); + const auto neighbour = FaceOverlapsEdge(p0, p1, bsp, face); + if (neighbour.face != nullptr) { + result->push_back(neighbour); } } } @@ -101,10 +101,10 @@ FacesOverlappingEdge_r(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, int * Returns faces which have an edge that overlaps the given p0-p1 edge. * Uses hull 0. */ -vector +vector FacesOverlappingEdge(const vec3_t p0, const vec3_t p1, const mbsp_t *bsp, const dmodel_t *model) { - vector result; + vector result; FacesOverlappingEdge_r(p0, p1, bsp, model->headnode[0], &result); return result; }