public LightingPalette Lerp(float t, bool presetA = true) { LightingPalette[] palette = presetA ? TimePresetA : TimePresetB; // Generate a new LightingPalette which is the interpolated values of things. t = WMath.Clamp(t, 0, 1); float scaledT = t * (palette.Length - 1); int lowerIndex = (int)scaledT; int upperIndex = (int)(scaledT + 1f); float newT = scaledT - (int)scaledT; //Console.WriteLine("t: {0} scaledT: {1} lIndex: {2} uIndex: {3} newT: {4}", t, scaledT, lowerIndex, upperIndex, newT); if (upperIndex == palette.Length) { upperIndex = lowerIndex; } LightingPalette interpPalette = new LightingPalette(); interpPalette.Shadow = WLinearColor.Lerp(palette[lowerIndex].Shadow, palette[upperIndex].Shadow, newT); interpPalette.ActorAmbient = WLinearColor.Lerp(palette[lowerIndex].ActorAmbient, palette[upperIndex].ActorAmbient, newT); interpPalette.RoomLight = WLinearColor.Lerp(palette[lowerIndex].RoomLight, palette[upperIndex].RoomLight, newT); interpPalette.RoomAmbient = WLinearColor.Lerp(palette[lowerIndex].RoomAmbient, palette[upperIndex].RoomAmbient, newT); interpPalette.WaveColor = WLinearColor.Lerp(palette[lowerIndex].WaveColor, palette[upperIndex].WaveColor, newT); interpPalette.OceanColor = WLinearColor.Lerp(palette[lowerIndex].OceanColor, palette[upperIndex].OceanColor, newT); interpPalette.UnknownWhite1 = WLinearColor.Lerp(palette[lowerIndex].UnknownWhite1, palette[upperIndex].UnknownWhite1, newT); interpPalette.UnknownWhite2 = WLinearColor.Lerp(palette[lowerIndex].UnknownWhite2, palette[upperIndex].UnknownWhite2, newT); interpPalette.Doorway = WLinearColor.Lerp(palette[lowerIndex].Doorway, palette[upperIndex].Doorway, newT); interpPalette.UnknownColor3 = WLinearColor.Lerp(palette[lowerIndex].UnknownColor3, palette[upperIndex].UnknownColor3, newT); interpPalette.Skybox = LightingSkyboxColors.Lerp(palette[lowerIndex].Skybox, palette[upperIndex].Skybox, newT); interpPalette.Fog = WLinearColor.Lerp(palette[lowerIndex].Fog, palette[upperIndex].Fog, newT); interpPalette.FogNearPlane = WMath.Lerp(palette[lowerIndex].FogNearPlane, palette[upperIndex].FogNearPlane, newT); interpPalette.FogFarPlane = WMath.Lerp(palette[lowerIndex].FogFarPlane, palette[upperIndex].FogFarPlane, newT); return(interpPalette); }
public List <EnvironmentLighting> GetLightingData() { // Bah... var loadedActors = new List <WActorNode>(); foreach (var chunk in m_chunkList) { m_reader.BaseStream.Position = chunk.ChunkOffset; MapActorDescriptor template = m_sActorDescriptors.Find(x => x.FourCC == chunk.FourCC); if (template == null) { Console.WriteLine("Unsupported FourCC: {0}", chunk.FourCC); continue; } switch (chunk.FourCC) { // We're only going to re-load the lighting-based actors... case "EnvR": case "Colo": case "Pale": case "Virt": for (int i = 0; i < chunk.ElementCount; i++) { var newActor = LoadActorFromChunk(chunk.FourCC, template); newActor.Layer = chunk.Layer; loadedActors.Add(newActor); } break; } } var dict = new Dictionary <string, List <WActorNode> >(); foreach (var actor in loadedActors) { if (!dict.ContainsKey(actor.FourCC)) { dict[actor.FourCC] = new List <WActorNode>(); } dict[actor.FourCC].Add(actor); } // Load Skybox Lighting Data var virtList = new List <LightingSkyboxColors>(); var paleList = new List <LightingPalette>(); var coloList = new List <LightingTimePreset>(); if (dict.ContainsKey("virt") && dict.ContainsKey("pale") && dict.ContainsKey("Colo")) { foreach (var virt in dict["Virt"]) { WLinearColor unknown1, unknown2, unknown3, unknown4, horizonCloud, centerCloud, sky, falseSea, horizon; virt.TryGetValue("Unknown 1", out unknown1); virt.TryGetValue("Unknown 2", out unknown2); virt.TryGetValue("Unknown 3", out unknown3); virt.TryGetValue("Unknown 4", out unknown4); virt.TryGetValue("Horizon Cloud Color", out horizonCloud); virt.TryGetValue("Center Cloud Color", out centerCloud); virt.TryGetValue("Sky Color", out sky); virt.TryGetValue("False Sea Color", out falseSea); virt.TryGetValue("Horizon Color", out horizon); LightingSkyboxColors virtEntry = new LightingSkyboxColors { Unknown1 = unknown1, Unknown2 = unknown2, Unknown3 = unknown3, Unknown4 = unknown4, HorizonCloud = horizonCloud, CenterCloud = centerCloud, Sky = sky, FalseSea = falseSea, Horizon = horizon }; virtList.Add(virtEntry); } foreach (var pale in dict["Pale"]) { WLinearColor shadow, actorAmbient, roomLight, roomAmbient, wave, ocean, unknown1, unknown2, doorway, unknown3, fog; byte virtIndex; float fogFarPlane, fogNearPlane; pale.TryGetValue("Shadow Color", out shadow); pale.TryGetValue("Actor Ambient Color", out actorAmbient); pale.TryGetValue("Room Light Color", out roomLight); pale.TryGetValue("Room Ambient Color", out roomAmbient); pale.TryGetValue("Wave Color", out wave); pale.TryGetValue("Ocean Color", out ocean); pale.TryGetValue("Unknown White 1", out unknown1); pale.TryGetValue("Unknown White 2", out unknown2); pale.TryGetValue("Door Backfill", out doorway); pale.TryGetValue("Unknown 3", out unknown3); pale.TryGetValue("Fog Color", out fog); pale.TryGetValue("Skybox Color Index", out virtIndex); pale.TryGetValue("Fog Far Plane", out fogFarPlane); pale.TryGetValue("Fog Near Plane", out fogNearPlane); LightingPalette lightPalette = new LightingPalette { Shadow = shadow, ActorAmbient = actorAmbient, RoomLight = roomLight, RoomAmbient = roomAmbient, WaveColor = wave, OceanColor = ocean, UnknownWhite1 = unknown1, UnknownWhite2 = unknown2, Doorway = doorway, UnknownColor3 = unknown3, Skybox = virtList[virtIndex], Fog = fog, FogNearPlane = fogNearPlane, FogFarPlane = fogFarPlane, }; paleList.Add(lightPalette); } foreach (var colo in dict["Colo"]) { byte[] setA = new byte[6]; byte[] setB = new byte[6]; colo.TryGetValue("Dawn A", out setA[0]); colo.TryGetValue("Morning A", out setA[1]); colo.TryGetValue("Noon A", out setA[2]); colo.TryGetValue("Afternoon A", out setA[3]); colo.TryGetValue("Dusk A", out setA[4]); colo.TryGetValue("Night A", out setA[5]); colo.TryGetValue("Dawn B", out setB[0]); colo.TryGetValue("Morning B", out setB[1]); colo.TryGetValue("Noon B", out setB[2]); colo.TryGetValue("Afternoon B", out setB[3]); colo.TryGetValue("Dusk B", out setB[4]); colo.TryGetValue("Night B", out setB[5]); LightingTimePreset timePreset = new LightingTimePreset(); for (int i = 0; i < 6; i++) { timePreset.TimePresetA[i] = paleList[setA[i]]; } //for (int i = 0; i < 6; i++) //timePreset.TimePresetB[i] = paleList[setB[i]]; coloList.Add(timePreset); } } var envrList = new List <EnvironmentLighting>(); if (paleList.Count > 0 && coloList.Count > 0) { foreach (var envr in dict["EnvR"]) { byte[] setA = new byte[4]; byte[] setB = new byte[4]; envr.TryGetValue("Clear Color A", out setA[0]); envr.TryGetValue("Raining Color A", out setA[1]); envr.TryGetValue("Snowing A", out setA[2]); envr.TryGetValue("Unknown A", out setA[3]); envr.TryGetValue("Clear Color B", out setB[0]); envr.TryGetValue("Raining Color B", out setB[1]); envr.TryGetValue("Snowing B", out setB[2]); envr.TryGetValue("Unknown B", out setB[3]); EnvironmentLighting envrPreset = new EnvironmentLighting(); for (int i = 0; i < 4; i++) { envrPreset.WeatherA[i] = coloList[setA[i]]; } for (int i = 0; i < 4; i++) { envrPreset.WeatherB[i] = coloList[setB[i]]; } envrList.Add(envrPreset); } } return(envrList); }
private List <EnvironmentLighting> GetLightingData() { List <EnvironmentLighting> lights = new List <EnvironmentLighting>(); List <LightingTimePreset> times = new List <LightingTimePreset>(); List <LightingPalette> palettes = new List <LightingPalette>(); List <LightingSkyboxColors> skyboxes = new List <LightingSkyboxColors>(); if (!m_fourCCGroups.ContainsKey(FourCC.EnvR) || !m_fourCCGroups.ContainsKey(FourCC.Colo) || !m_fourCCGroups.ContainsKey(FourCC.Virt) || !m_fourCCGroups.ContainsKey(FourCC.Pale)) { return(lights); } foreach (var virt in m_fourCCGroups[FourCC.Virt].Children) { EnvironmentLightingSkyboxColors skybox = (EnvironmentLightingSkyboxColors)virt; LightingSkyboxColors skycolors = new LightingSkyboxColors(skybox); skyboxes.Add(skycolors); } foreach (var pale in m_fourCCGroups[FourCC.Pale].Children) { EnvironmentLightingColors colors = (EnvironmentLightingColors)pale; LightingPalette palette = new LightingPalette(colors); if (colors.SkyboxColorIndex < skyboxes.Count) { palette.Skybox = skyboxes[colors.SkyboxColorIndex]; } else { palette.Skybox = new LightingSkyboxColors(); } palettes.Add(palette); } foreach (var colo in m_fourCCGroups[FourCC.Colo].Children) { EnvironmentLightingTimesOfDay daytimes = (EnvironmentLightingTimesOfDay)colo; LightingTimePreset preset = new LightingTimePreset(); preset.TimePresetA[0] = palettes[daytimes.DawnA]; preset.TimePresetA[1] = palettes[daytimes.MorningA]; preset.TimePresetA[2] = palettes[daytimes.NoonA]; preset.TimePresetA[3] = palettes[daytimes.AfternoonA]; preset.TimePresetA[4] = palettes[daytimes.DuskA]; preset.TimePresetA[5] = palettes[daytimes.NightA]; preset.TimePresetB[0] = palettes[0]; //daytimes.DawnB]; preset.TimePresetB[1] = palettes[0]; //palettes[daytimes.MorningB]; preset.TimePresetB[2] = palettes[0]; //palettes[daytimes.NoonB]; preset.TimePresetB[3] = palettes[0]; //palettes[daytimes.AfternoonB]; preset.TimePresetB[4] = palettes[0]; //palettes[daytimes.DuskB]; preset.TimePresetB[5] = palettes[0]; //palettes[daytimes.NightB]; times.Add(preset); } foreach (var envr in m_fourCCGroups[FourCC.EnvR].Children) { EnvironmentLightingConditions condition = (EnvironmentLightingConditions)envr; EnvironmentLighting env = new EnvironmentLighting(); env.WeatherA[0] = times[condition.ClearA]; env.WeatherA[1] = times[condition.RainingA < times.Count ? condition.RainingA : 0]; env.WeatherA[2] = times[condition.SnowingA]; env.WeatherA[3] = times[condition.UnknownA]; env.WeatherB[0] = times[condition.ClearB]; env.WeatherB[1] = times[condition.RainingB]; env.WeatherB[2] = times[condition.SnowingB]; env.WeatherB[3] = times[condition.UnknownB]; lights.Add(env); } return(lights); }