OBJ model exporter: fixed a problem where texture UV values were NaN when a texture was not fully loaded prior to exporting. Fixes #1015

This commit is contained in:
biwa 2024-02-03 14:19:04 +01:00
parent a83b92fbdd
commit 29643d98b4

View file

@ -15,6 +15,7 @@ using CodeImp.DoomBuilder.VisualModes;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.BuilderModes.Interface;
using System.Windows.Forms;
using System.Linq;
#endregion
@ -388,7 +389,50 @@ namespace CodeImp.DoomBuilder.BuilderModes.IO
if (addvs)
{
BaseVisualSector bvs = mode.CreateBaseVisualSector(s);
if (bvs != null) visualSectors.Add(bvs);
if (bvs != null)
{
// When the visual sector is created yet unseen wall textures are not fully loaded in time, which can result in the
// texture coordinates (UV) ending up as NaN. This can happen if the export is started before the textures are loaded
// (for example by opening the texture browser or going into visual mode. So make sure the textures are loaded immediately.
// After that the visual sector has to be rebuilt. This only seems to affect wall textures, not floors/ceilings
// See https://github.com/UltimateDoomBuilder/UltimateDoomBuilder/issues/1015
foreach (VisualSidedefParts vsp in bvs.Sides.Values)
{
if (vsp.upper?.Texture != null && vsp.upper.Texture.ImageState != ImageLoadState.Ready)
vsp.upper.Texture.LocalGetBitmap(true);
if (vsp.middlesingle?.Texture != null && vsp.middlesingle.Texture.ImageState != ImageLoadState.Ready)
vsp.middlesingle.Texture.LocalGetBitmap(true);
if (vsp.middledouble?.Texture != null && vsp.middledouble.Texture.ImageState != ImageLoadState.Ready)
vsp.middledouble.Texture.LocalGetBitmap(true);
if (vsp.lower?.Texture != null && vsp.lower.Texture.ImageState != ImageLoadState.Ready)
vsp.lower.Texture.LocalGetBitmap(true);
if (vsp.middle3d != null)
{
foreach (VisualMiddle3D vm in vsp.middle3d.Where(o => o.Texture != null && o.Texture.ImageState != ImageLoadState.Ready))
{
vm.Texture.LocalGetBitmap(true);
}
}
if (vsp.middleback != null)
{
foreach (VisualMiddleBack vm in vsp.middleback.Where(o => o.Texture != null && o.Texture.ImageState != ImageLoadState.Ready))
{
vm.Texture.LocalGetBitmap(true);
}
}
}
// Rebuild the visual sector so that the texture coordinates are guaranteed to be correct
bvs.Rebuild();
visualSectors.Add(bvs);
}
}
}