Add map clearing, handle cells without visible polys, add lighting
This commit is contained in:
		
							parent
							
								
									2e841276f3
								
							
						
					
					
						commit
						1ba0c6ac27
					
				| 
						 | 
				
			
			@ -144,7 +144,7 @@ public class WorldRep : IChunk
 | 
			
		|||
        public int LightIndexCount { get; set; }
 | 
			
		||||
        public ushort[] LightIndices { get; set; }
 | 
			
		||||
 | 
			
		||||
        public Cell(BinaryReader reader)
 | 
			
		||||
        public Cell(BinaryReader reader, int bpp)
 | 
			
		||||
        {
 | 
			
		||||
            VertexCount = reader.ReadByte();
 | 
			
		||||
            PolyCount = reader.ReadByte();
 | 
			
		||||
| 
						 | 
				
			
			@ -199,7 +199,6 @@ public class WorldRep : IChunk
 | 
			
		|||
            for (var i = 0; i < RenderPolyCount; i++)
 | 
			
		||||
            {
 | 
			
		||||
                var info = LightList[i];
 | 
			
		||||
                var bpp = 4; // TODO: WREXT only!
 | 
			
		||||
                Lightmaps[i] = new Lightmap(reader, info.Width, info.Height, info.AnimLightBitmask, bpp);
 | 
			
		||||
            }
 | 
			
		||||
            LightIndexCount = reader.ReadInt32();
 | 
			
		||||
| 
						 | 
				
			
			@ -218,10 +217,12 @@ public class WorldRep : IChunk
 | 
			
		|||
    public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
 | 
			
		||||
    {
 | 
			
		||||
        DataHeader = new(reader);
 | 
			
		||||
        var bpp = (DataHeader.LightmapFormat == 0) ? 2 : 4;
 | 
			
		||||
 | 
			
		||||
        Cells = new Cell[DataHeader.CellCount];
 | 
			
		||||
        for (var i = 0; i < DataHeader.CellCount; i++)
 | 
			
		||||
        {
 | 
			
		||||
            Cells[i] = new Cell(reader);
 | 
			
		||||
            Cells[i] = new Cell(reader, bpp);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // TODO: All the other info lol
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -96,8 +96,8 @@ public class DbFile
 | 
			
		|||
    {
 | 
			
		||||
        return entryName switch
 | 
			
		||||
        {
 | 
			
		||||
            "AI_ROOM_DB" => new AiRoomDb(),
 | 
			
		||||
            "AICONVERSE" => new AiConverseChunk(),
 | 
			
		||||
            // "AI_ROOM_DB" => new AiRoomDb(),
 | 
			
		||||
            // "AICONVERSE" => new AiConverseChunk(),
 | 
			
		||||
            "WREXT" => new WorldRep(),
 | 
			
		||||
            _ => new GenericChunk(),
 | 
			
		||||
        };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,6 +15,8 @@ public partial class Mission : Node3D
 | 
			
		|||
	public string FileName { get; set; }
 | 
			
		||||
	[Export]
 | 
			
		||||
	public bool Build = false;
 | 
			
		||||
	[Export]
 | 
			
		||||
	public bool Clear = false;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	DbFile _file;
 | 
			
		||||
| 
						 | 
				
			
			@ -31,6 +33,11 @@ public partial class Mission : Node3D
 | 
			
		|||
			RebuildMap();
 | 
			
		||||
			Build = false;
 | 
			
		||||
		}
 | 
			
		||||
		if (Clear)
 | 
			
		||||
		{
 | 
			
		||||
			ClearMap();
 | 
			
		||||
			Clear = false;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public override void _Input(InputEvent @event)
 | 
			
		||||
| 
						 | 
				
			
			@ -44,12 +51,17 @@ public partial class Mission : Node3D
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void RebuildMap()
 | 
			
		||||
	public void ClearMap()
 | 
			
		||||
	{
 | 
			
		||||
		foreach (var node in GetChildren())
 | 
			
		||||
		{
 | 
			
		||||
			node.QueueFree();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void RebuildMap()
 | 
			
		||||
	{
 | 
			
		||||
		ClearMap();
 | 
			
		||||
 | 
			
		||||
		_file = new(FileName);
 | 
			
		||||
		var wr = (WorldRep)_file.Chunks["WREXT"];
 | 
			
		||||
| 
						 | 
				
			
			@ -66,6 +78,11 @@ public partial class Mission : Node3D
 | 
			
		|||
		var numRenderPolys = cell.RenderPolyCount;
 | 
			
		||||
		var numPortalPolys = cell.PortalPolyCount;
 | 
			
		||||
 | 
			
		||||
		if (numRenderPolys == 0 || numPortalPolys >= numPolys)
 | 
			
		||||
		{
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var vertices = new List<Vector3>();
 | 
			
		||||
		var normals = new List<Vector3>();
 | 
			
		||||
		var idxOffset = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -86,13 +103,10 @@ public partial class Mission : Node3D
 | 
			
		|||
			for (int j = 1; j < numPolyVertices - 1; j++)
 | 
			
		||||
			{
 | 
			
		||||
				foreach (var offset in new int[] { 0, j, j + 1 })
 | 
			
		||||
				// foreach (var offset in new int[] { j + 1, j, 0 })
 | 
			
		||||
				{
 | 
			
		||||
					var vertex = cell.Vertices[cell.Indices[idxOffset + offset]];
 | 
			
		||||
					vertices.Add(vertex.ToGodotVec3(4.0f));
 | 
			
		||||
					normals.Add(normal.ToGodotVec3(4.0f));
 | 
			
		||||
					// vertices.Add(new Vector3(vertex.Y, vertex.Z, vertex.X));
 | 
			
		||||
					// normals.Add(new Vector3(normal.Y, normal.Z, normal.X));
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +125,17 @@ public partial class Mission : Node3D
 | 
			
		|||
			Mesh = arrMesh,
 | 
			
		||||
			CastShadow = GeometryInstance3D.ShadowCastingSetting.On
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		AddChild(meshInstance);
 | 
			
		||||
 | 
			
		||||
		var r = new Random();
 | 
			
		||||
		if (r.NextSingle() > 0.9 && cell.SphereRadius > 5.0)
 | 
			
		||||
		{
 | 
			
		||||
			var light = new OmniLight3D
 | 
			
		||||
			{
 | 
			
		||||
				Position = cell.SphereCenter.ToGodotVec3(4.0f),
 | 
			
		||||
				OmniRange = cell.SphereRadius * (r.NextSingle() + 1.0f) * 0.5f,
 | 
			
		||||
			};
 | 
			
		||||
			AddChild(light);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -9,17 +9,10 @@
 | 
			
		|||
 | 
			
		||||
[node name="Mission" type="Node3D" parent="."]
 | 
			
		||||
script = ExtResource("1_xhqt7")
 | 
			
		||||
FileName = "/home/jarrod/Dev/thief/de-specs/test_data/wr-test.cow"
 | 
			
		||||
FileName = "/home/jarrod/Dev/thief/de-specs/test_data/rose-garden.mis"
 | 
			
		||||
 | 
			
		||||
[node name="Camera3D" type="Camera3D" parent="."]
 | 
			
		||||
script = ExtResource("2_w5otl")
 | 
			
		||||
 | 
			
		||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 | 
			
		||||
environment = SubResource("Environment_oxkvl")
 | 
			
		||||
 | 
			
		||||
[node name="OmniLight3D" type="OmniLight3D" parent="."]
 | 
			
		||||
shadow_enabled = true
 | 
			
		||||
 | 
			
		||||
[node name="OmniLight3D3" type="OmniLight3D" parent="."]
 | 
			
		||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.509499, 0.98353, 1.1662)
 | 
			
		||||
shadow_enabled = true
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue