diff --git a/KeepersCompound.Lightmapper/LightMapper.cs b/KeepersCompound.Lightmapper/LightMapper.cs index 5592293..e22ebe1 100644 --- a/KeepersCompound.Lightmapper/LightMapper.cs +++ b/KeepersCompound.Lightmapper/LightMapper.cs @@ -129,6 +129,7 @@ public class LightMapper private void BuildLightList() { + // TODO: Doors aren't blocking lights, seems to be lighttable related _lights.Clear(); // Get the chunks we need diff --git a/KeepersCompound.Lightmapper/MeshBuilder.cs b/KeepersCompound.Lightmapper/MeshBuilder.cs index 782c1b6..fa5472f 100644 --- a/KeepersCompound.Lightmapper/MeshBuilder.cs +++ b/KeepersCompound.Lightmapper/MeshBuilder.cs @@ -5,11 +5,13 @@ using KeepersCompound.LGS.Database.Chunks; namespace KeepersCompound.Lightmapper; +// TODO: Rename to CastSurfaceType? public enum SurfaceType { Solid, Sky, Water, + Air, } public class Mesh(int triangleCount, List vertices, List indices, List triangleSurfaceMap) @@ -35,17 +37,36 @@ public class MeshBuilder var numPolys = cell.PolyCount; var numRenderPolys = cell.RenderPolyCount; var numPortalPolys = cell.PortalPolyCount; - - // There's nothing to render - if (numRenderPolys == 0 || numPortalPolys >= numPolys) - { - continue; - } - var solidPolys = numPolys - numPortalPolys; + var cellIdxOffset = 0; - for (var polyIdx = 0; polyIdx < numRenderPolys; polyIdx++) + for (var polyIdx = 0; polyIdx < numPolys; polyIdx++) { + // There's 3 types of poly that we need to include in the mesh: + // - Terrain + // - Water surfaces + // - Door vision blockers + // + // Door vision blockers are the interesting one. They're not RenderPolys at all, and we only include + // them in the mesh if the cell only has two of them (otherwise the door is in the middle of the air) + SurfaceType primType; + if (polyIdx < solidPolys) + { + primType = cell.RenderPolys[polyIdx].TextureId == 249 ? SurfaceType.Sky : SurfaceType.Solid; + } + else if (polyIdx < numRenderPolys) + { + primType = SurfaceType.Water; + } + else if (cell is { Flags: 24, PortalPolyCount: 2 }) // TODO: Work out what these flags are!! + { + primType = SurfaceType.Solid; + } + else + { + continue; + } + var poly = cell.Polys[polyIdx]; polyVertices.Clear(); polyVertices.EnsureCapacity(poly.VertexCount); @@ -53,18 +74,6 @@ public class MeshBuilder { polyVertices.Add(cell.Vertices[cell.Indices[cellIdxOffset + i]]); } - - // We need to know what type of surface this poly is so we can map Embree primitive IDs to surface - // types - var renderPoly = cell.RenderPolys[polyIdx]; - var primType = SurfaceType.Solid; - if (renderPoly.TextureId == 249) - { - primType = SurfaceType.Sky; - } else if (polyIdx >= solidPolys) - { - primType = SurfaceType.Water; - } AddPolygon(polyVertices, primType); cellIdxOffset += poly.VertexCount;