Split out Light gathering a bit

This commit is contained in:
Jarrod Doyle 2024-10-27 10:23:15 +00:00
parent a9d2d2e193
commit c8e13a7f7b
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 167 additions and 149 deletions

View File

@ -25,6 +25,19 @@ class Program
public int objId;
public int lightTableIndex;
public bool anim;
public WorldRep.LightTable.LightData ToLightData(float lightScale)
{
return new WorldRep.LightTable.LightData
{
Location = position,
Direction = spotlightDir,
Color = color / lightScale,
InnerAngle = spotlightInnerAngle,
OuterAngle = spotlightOuterAngle,
Radius = radius == float.MaxValue ? 0 : radius,
};
}
}
static void Main(string[] args)
@ -153,10 +166,30 @@ class Program
foreach (var brush in brList.Brushes)
{
if (brush.media == BrList.Brush.Media.Light)
switch (brush.media)
{
case BrList.Brush.Media.Light:
ProcessBrushLight(lights, worldRep.LightingTable, brush);
break;
case BrList.Brush.Media.Object:
ProcessObjectLight(
lights,
hierarchy,
campaign,
worldRep.LightingTable,
brush);
break;
}
}
return lights;
}
// TODO: Check if this works (brush is a record type)
private static void ProcessBrushLight(List<Light> lights, WorldRep.LightTable lightTable, BrList.Brush brush)
{
// For some reason the light table index on brush lights is 1 indexed
brush.brushInfo = (uint)worldRep.LightingTable.LightCount + 1;
brush.brushInfo = (uint)lightTable.LightCount + 1;
var sz = brush.size;
var light = new Light
@ -165,11 +198,11 @@ class Program
color = Utils.HsbToRgb(sz.Y, sz.Z, Math.Min(sz.X, 255.0f)),
radius = float.MaxValue,
r2 = float.MaxValue,
lightTableIndex = worldRep.LightingTable.LightCount,
lightTableIndex = lightTable.LightCount,
};
lights.Add(light);
worldRep.LightingTable.AddLight(new WorldRep.LightTable.LightData
lightTable.AddLight(new WorldRep.LightTable.LightData
{
Location = light.position,
Direction = light.spotlightDir,
@ -178,7 +211,13 @@ class Program
Radius = 0,
});
}
else if (brush.media == BrList.Brush.Media.Object)
private static void ProcessObjectLight(
List<Light> lights,
ObjectHierarchy hierarchy,
ResourcePathManager.CampaignResources campaign,
WorldRep.LightTable lightTable,
BrList.Brush brush)
{
// TODO: Handle PropSpotlightAndAmbient
var id = (int)brush.brushInfo;
@ -186,7 +225,7 @@ class Program
var propLight = hierarchy.GetProperty<PropLight>(id, "P$Light", false);
var propLightColor = hierarchy.GetProperty<PropLightColor>(id, "P$LightColo");
var propSpotlight = hierarchy.GetProperty<PropSpotlight>(id, "P$Spotlight");
var propModelname = hierarchy.GetProperty<PropLabel>(id, "P$ModelName");
var propModelName = hierarchy.GetProperty<PropLabel>(id, "P$ModelName");
propLightColor ??= new PropLightColor { Hue = 0, Saturation = 0 };
@ -197,9 +236,9 @@ class Program
spotlightInnerAngle = -1.0f,
};
if (propModelname != null)
if (propModelName != null)
{
var resName = $"{propModelname.value.ToLower()}.bin";
var resName = $"{propModelName.value.ToLower()}.bin";
var modelPath = campaign.GetResourcePath(ResourceType.Object, resName);
if (modelPath != null)
{
@ -243,9 +282,8 @@ class Program
spotlightDir = baseLight.spotlightDir,
spotlightInnerAngle = baseLight.spotlightInnerAngle,
spotlightOuterAngle = baseLight.spotlightOuterAngle,
lightTableIndex = worldRep.LightingTable.LightCount,
lightTableIndex = lightTable.LightCount,
};
if (propLight.Radius == 0)
{
light.radius = float.MaxValue;
@ -253,20 +291,12 @@ class Program
}
lights.Add(light);
worldRep.LightingTable.AddLight(new WorldRep.LightTable.LightData
{
Location = light.position,
Direction = light.spotlightDir,
Color = light.color / 32.0f, // TODO: This is based on light_scale config var
InnerAngle = light.spotlightInnerAngle,
OuterAngle = light.spotlightOuterAngle,
Radius = propLight.Radius,
});
lightTable.AddLight(light.ToLightData(32.0f));
}
if (propAnimLight != null)
{
var lightIndex = worldRep.LightingTable.LightCount;
var lightIndex = lightTable.LightCount;
propAnimLight.LightTableLightIndex = (ushort)lightIndex;
var light = new Light
@ -291,21 +321,9 @@ class Program
}
lights.Add(light);
worldRep.LightingTable.AddLight(new WorldRep.LightTable.LightData
{
Location = light.position,
Direction = light.spotlightDir,
Color = light.color / 32.0f, // TODO: This is based on light_scale config var
InnerAngle = light.spotlightInnerAngle,
OuterAngle = light.spotlightOuterAngle,
Radius = propAnimLight.Radius,
});
lightTable.AddLight(light.ToLightData(32.0f));
}
}
}
return lights;
}
private static ObjectHierarchy BuildHierarchy(string misPath, DbFile misFile)
{