From 8ef85aa5c08245967ed9ddc404a6a31c0f73e8d8 Mon Sep 17 00:00:00 2001 From: Unreal Karaulov Date: Sun, 17 Mar 2024 14:11:30 +0300 Subject: [PATCH] test fix bad surface extents --- src/bsp/Bsp.cpp | 44 +++++--------------------------------------- src/editor/Gui.cpp | 3 ++- src/qtools/rad.cpp | 5 ++--- src/qtools/rad.h | 3 ++- 4 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index b9966b0d..eac40ae0 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -4346,14 +4346,15 @@ bool Bsp::validate() int bmaxs[2]; if (isValid) isValid = GetFaceExtents(i, bmins, bmaxs); + else + print_log(PRINT_RED | PRINT_INTENSITY, "Bad face {} extents\n", i); if (isValid) { isValid = !is_face_duplicate_edges(i); if (!isValid && g_settings.verboseLogs) { - print_log("Warn: Face {} has duplicate verts! Fixed!\n", i); - face_fix_duplicate_edges(i); + print_log("Warn: Face {} has duplicate verts!\n", i); } isValid = true; } @@ -11937,56 +11938,21 @@ bool Bsp::CalcFaceExtents(lightinfo_t* l) bool Bsp::GetFaceExtents(int facenum, int mins_out[2], int maxs_out[2]) { - float mins[2], maxs[2], val; - + bool findpos = CanFindFacePosition(this, facenum, mins_out, maxs_out); bool retval = true; - mins[0] = mins[1] = 999999.0f; - maxs[0] = maxs[1] = -999999.0f; - BSPFACE32& face = faces[facenum]; - BSPTEXTUREINFO tex = texinfos[face.iTextureInfo]; - for (int i = 0; i < face.nEdges; i++) - { - vec3 v = vec3(); - int e = surfedges[face.iFirstEdge + i]; - if (e >= 0) - { - v = verts[edges[e].iVertex[0]]; - } - else - { - v = verts[edges[-e].iVertex[1]]; - } - for (int j = 0; j < 2; j++) - { - float* axis = j == 0 ? (float*)&tex.vS : (float*)&tex.vT; - val = CalculatePointVecsProduct((float*)&v, axis); - - if (val < mins[j]) - { - mins[j] = val; - } - if (val > maxs[j]) - { - maxs[j] = val; - } - } - } - for (int i = 0; i < 2; i++) { int tmpTextureStep = CalcFaceTextureStep(facenum); - mins_out[i] = (int)floor(mins[i] / tmpTextureStep); - maxs_out[i] = (int)ceil(maxs[i] / tmpTextureStep); - if (!(tex.nFlags & TEX_SPECIAL) && (maxs_out[i] - mins_out[i]) * tmpTextureStep > (MAX_SURFACE_EXTENT * MAX_SURFACE_EXTENT)) { retval = false; print_log(get_localized_string("BAD_SURFACE_EXT"), facenum, (int)((maxs_out[i] - mins_out[i]) * tmpTextureStep), (MAX_SURFACE_EXTENT * MAX_SURFACE_EXTENT)); + print_log("TRACE: Mins {} maxs {}\n", mins_out[i], maxs_out[i]); mins_out[i] = 1; maxs_out[i] = 1; } diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index 48a21c9b..090a3960 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -4725,6 +4725,7 @@ void Gui::drawMenuBar() ImGui::EndTooltip(); } + //face_fix_duplicate_edges(i); ImGui::BeginDisabled(); if (ImGui::MenuItem("Fix light entities[+TEXTURE]")) { @@ -12550,7 +12551,7 @@ void Gui::checkFaceErrors() map->GetFaceLightmapSize((int)app->pickInfo.selectedFaces[i], size); if ((size[0] > MAX_SURFACE_EXTENT) || (size[1] > MAX_SURFACE_EXTENT) || size[0] < 0 || size[1] < 0) { - //print_log(get_localized_string(LANG_0426),size[0],size[1]); + print_log(get_localized_string(LANG_0426),size[0],size[1]); size[0] = std::min(size[0], MAX_SURFACE_EXTENT); size[1] = std::min(size[1], MAX_SURFACE_EXTENT); badSurfaceExtents = true; diff --git a/src/qtools/rad.cpp b/src/qtools/rad.cpp index f3177ca7..648ce831 100644 --- a/src/qtools/rad.cpp +++ b/src/qtools/rad.cpp @@ -99,10 +99,9 @@ void TranslateWorldToTex(Bsp* bsp, int facenum, matrix_t& m) m.v[3][2] = -fp.fDist; } -bool CanFindFacePosition(Bsp* bsp, int facenum) +bool CanFindFacePosition(Bsp* bsp, int facenum, int imins[2], int imaxs[2]) { float texmins[2]{}, texmaxs[2]{}; - int imins[2]{}, imaxs[2]{}; matrix_t worldtotex; matrix_t textoworld; @@ -112,6 +111,7 @@ bool CanFindFacePosition(Bsp* bsp, int facenum) { return false; } + BSPTEXTUREINFO& tex = bsp->texinfos[f->iTextureInfo]; TranslateWorldToTex(bsp, facenum, worldtotex); @@ -147,7 +147,6 @@ bool CanFindFacePosition(Bsp* bsp, int facenum) unsigned int tmpTextureStep = bsp->CalcFaceTextureStep(facenum); - for (int k = 0; k < 2; k++) { imins[k] = (int)floor(texmins[k] / tmpTextureStep + 0.5 - ON_EPSILON); diff --git a/src/qtools/rad.h b/src/qtools/rad.h index 946feb00..d561f803 100644 --- a/src/qtools/rad.h +++ b/src/qtools/rad.h @@ -123,4 +123,5 @@ struct LIGHTMAP }; -float CalculatePointVecsProduct(const volatile float* point, const volatile float* vecs); \ No newline at end of file +float CalculatePointVecsProduct(const volatile float* point, const volatile float* vecs); +bool CanFindFacePosition(Bsp* bsp, int facenum, int imins[2], int imaxs[2]); \ No newline at end of file