private void UpdateLights() { if (Entity == null || !Entity.InScene || Definition == null) { return; } foreach (var feature in Definition.Features.Values) { if (!_lights.TryGetValue(feature.Id, out var light)) { _lights.Add(feature.Id, light = MyRenderProxy.CreateRenderLight($"{Entity}/{DebugName}/{feature.Id}")); } var turnedOn = _stateComponent == null || feature.States.Count == 0 || feature.States.Contains(_stateComponent.CurrentState); var pos = ComputeFeaturePosition(feature); var msg = new UpdateRenderLightData { ID = light, Position = pos.Translation, // Point light PointLightOn = turnedOn && feature.PointLight.HasValue, PointLight = feature.PointLight ?? default, // Spot light SpotLightOn = turnedOn && feature.SpotLight.HasValue, SpotLight = feature.SpotLight ?? default, ShadowDistance = feature.SpotLight?.ShadowsRange ?? 0, CastShadows = feature.SpotLightCastsShadows, ReflectorTexture = feature.SpotLightMask, // Glares Glare = feature.Flare, // Not optimal, but not really a big deal. PositionChanged = true, AabbChanged = true, }; msg.Glare.Enabled &= turnedOn; msg.SpotLight.Direction = (Vector3)pos.Forward; msg.SpotLight.Up = (Vector3)pos.Up; MyRenderProxy.UpdateRenderLight(ref msg); } }