From 3474fdc002ec14ac862470cd9496e656e64e09c9 Mon Sep 17 00:00:00 2001 From: havoc Date: Tue, 26 Nov 2002 20:38:41 +0000 Subject: [PATCH] BuildTriangleNeighbors now detects edges shared by three triangles, fixes weird shadow bugs in a few places git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2651 d7cf8633-e32d-0410-b094-e92efae38249 --- model_shared.c | 35 +++++++++++++++++++++++------------ model_shared.h | 2 +- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/model_shared.c b/model_shared.c index 591d8ac1..323931dc 100644 --- a/model_shared.c +++ b/model_shared.c @@ -384,19 +384,30 @@ static void Mod_Print (void) Con_Printf ("%4iK %s\n", mod->mempool ? (mod->mempool->totalsize + 1023) / 1024 : 0, mod->name); } -int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end) +int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore) { - int i; + int i, match, count; + count = 0; + match = -1; for (i = 0;i < numtriangles;i++, elements += 3) { - if (elements[0] == start && elements[1] == end) - return i; - if (elements[1] == start && elements[2] == end) - return i; - if (elements[2] == start && elements[0] == end) - return i; + if ((elements[0] == start && elements[1] == end) + || (elements[1] == start && elements[2] == end) + || (elements[2] == start && elements[0] == end)) + { + if (i != ignore) + match = i; + count++; + } + else if ((elements[1] == start && elements[0] == end) + || (elements[2] == start && elements[1] == end) + || (elements[0] == start && elements[2] == end)) + count++; } - return -1; + // detect edges shared by three triangles and make them seams + if (count > 2) + match = -1; + return match; } void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles) @@ -405,9 +416,9 @@ void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtria const int *e; for (i = 0, e = elements, n = neighbors;i < numtriangles;i++, e += 3, n += 3) { - n[0] = Mod_FindTriangleWithEdge(elements, numtriangles, e[1], e[0]); - n[1] = Mod_FindTriangleWithEdge(elements, numtriangles, e[2], e[1]); - n[2] = Mod_FindTriangleWithEdge(elements, numtriangles, e[0], e[2]); + n[0] = Mod_FindTriangleWithEdge(elements, numtriangles, e[1], e[0], i); + n[1] = Mod_FindTriangleWithEdge(elements, numtriangles, e[2], e[1], i); + n[2] = Mod_FindTriangleWithEdge(elements, numtriangles, e[0], e[2], i); } } diff --git a/model_shared.h b/model_shared.h index 8f504282..cfebccbe 100644 --- a/model_shared.h +++ b/model_shared.h @@ -308,7 +308,7 @@ void Mod_LoadModels(void); extern model_t *loadmodel; extern char loadname[32]; // for hunk tags -int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end); +int Mod_FindTriangleWithEdge(const int *elements, int numtriangles, int start, int end, int ignore); void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles); void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline); void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals); -- 2.39.2