Skip to content

Commit

Permalink
test fix bad surface extents
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Mar 17, 2024
1 parent d5fa465 commit 8ef85aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 44 deletions.
44 changes: 5 additions & 39 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4725,6 +4725,7 @@ void Gui::drawMenuBar()
ImGui::EndTooltip();
}

//face_fix_duplicate_edges(i);
ImGui::BeginDisabled();
if (ImGui::MenuItem("Fix light entities[+TEXTURE]"))
{
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions src/qtools/rad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -112,6 +111,7 @@ bool CanFindFacePosition(Bsp* bsp, int facenum)
{
return false;
}

BSPTEXTUREINFO& tex = bsp->texinfos[f->iTextureInfo];

TranslateWorldToTex(bsp, facenum, worldtotex);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/qtools/rad.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ struct LIGHTMAP
};


float CalculatePointVecsProduct(const volatile float* point, const volatile float* vecs);
float CalculatePointVecsProduct(const volatile float* point, const volatile float* vecs);
bool CanFindFacePosition(Bsp* bsp, int facenum, int imins[2], int imaxs[2]);

0 comments on commit 8ef85aa

Please sign in to comment.