private void UpdateMeshDebug([CanBeNull] Kn5RenderableCar carNode) { if (carNode != null) { carNode.DebugMode = _meshDebug; } }
protected override void CopyValues(Kn5RenderableCar newCar, Kn5RenderableCar oldCar) { base.CopyValues(newCar, oldCar); if (_magickOverideLater.HasValue) { newCar.MagickOverride = _magickOverideLater.Value; _magickOverideLater = null; } }
protected override void InitializeInner() { base.InitializeInner(); DeviceContextHolder.Set(GetMaterialsFactory()); if (_showroomKn5Filename != null) { ShowroomNode = LoadShowroom(_showroomKn5Filename); Scene.Insert(0, ShowroomNode); } _carWrapper = new RenderableList(); Scene.Add(_carWrapper); if (_car != null) { var carNode = new Kn5RenderableCar(_car, Matrix.Identity, _selectSkinLater ? _selectSkin : Kn5RenderableCar.DefaultSkin, asyncTexturesLoading: AsyncTexturesLoading, asyncOverrideTexturesLoading: AsyncOverridesLoading, allowSkinnedObjects: AllowSkinnedObjects); CarNode = carNode; CopyValues(carNode, null); _selectSkinLater = false; _carWrapper.Add(carNode); _carBoundingBox = null; ExtendCar(CarNode, _carWrapper); } // Scene.Add(new Kn5RenderableFile(Kn5.FromFile(_carKn5), Matrix.Identity)); Scene.UpdateBoundingBox(); _reflectionCubemap?.Initialize(DeviceContextHolder); if (EnableShadows) { _shadows = CreateShadows(); _shadows?.Initialize(DeviceContextHolder); } if (Camera == null) { Camera = CreateCamera(CarNode); _resetCamera = (CameraOrbit)Camera.Clone(); PrepareCamera(Camera); } DeviceContextHolder.SceneUpdated += OnSceneUpdated; DeviceContextHolder.TexturesUpdated += OnTexturesUpdated; }
private void CopyValues([NotNull] Kn5RenderableCar newCar, [CanBeNull] Kn5RenderableCar oldCar) { newCar.HeadlightsEnabled = oldCar?.HeadlightsEnabled ?? CarLightsEnabled; newCar.BrakeLightsEnabled = oldCar?.BrakeLightsEnabled ?? CarBrakeLightsEnabled; newCar.LeftDoorOpen = oldCar?.LeftDoorOpen ?? false; newCar.RightDoorOpen = oldCar?.RightDoorOpen ?? false; newCar.SteerDeg = oldCar?.SteerDeg ?? 0f; if (oldCar != null) { oldCar.CamerasChanged -= OnCamerasChanged; oldCar.ExtraCamerasChanged -= OnExtraCamerasChanged; } newCar.CamerasChanged += OnCamerasChanged; newCar.ExtraCamerasChanged += OnExtraCamerasChanged; }
protected override void InitializeInner() { base.InitializeInner(); DeviceContextHolder.Set <IMaterialsFactory>(new MaterialsProviderSimple()); if (_showroom != null) { var kn5 = Kn5.FromFile(_showroom.Kn5Filename); Scene.Insert(0, new Kn5RenderableFile(kn5, Matrix.Identity)); } _carWrapper = new RenderableList(); Scene.Add(_carWrapper); if (_car != null) { var kn5 = Kn5.FromFile(FileUtils.GetMainCarFilename(_car.Location)); CarNode = new Kn5RenderableCar(kn5, _car.Location, Matrix.Identity, _selectSkinLater ? _selectSkin : Kn5RenderableCar.DefaultSkin); _selectSkinLater = false; _carWrapper.Add(CarNode); var reflection = new FlatMirror(CarNode, new Plane(Vector3.Zero, Vector3.UnitY)); _carWrapper.Add(reflection); } Scene.UpdateBoundingBox(); if (CubemapReflection) { _reflectionCubemap = new ReflectionCubemap(1024); _reflectionCubemap.Initialize(DeviceContextHolder); } if (EffectDarkMaterial.EnableShadows) { _shadows = new ShadowsDirectional(2048, new[] { 5f }); _shadows.Initialize(DeviceContextHolder); } if (Camera == null) { Camera = CreateCamera(CarNode); _resetCamera = (CameraOrbit)Camera.Clone(); } }
public void Initialize() { if (_car != null) { var carNode = new Kn5RenderableCar(_car, Matrix.Identity, _renderer.SoundFactory, _selectSkinLater ? _selectSkin : Kn5RenderableCar.DefaultSkin, asyncTexturesLoading: _renderer.AsyncTexturesLoading, asyncOverrideTexturesLoading: _renderer.AsyncOverridesLoading, allowSkinnedObjects: _renderer.AllowSkinnedObjects); CarNode = carNode; _renderer.CopyValues(carNode, null); _selectSkinLater = false; CarWrapper.Add(carNode); _carBoundingBox = null; _renderer.ExtendCar(this, CarNode, CarWrapper); } }
protected override void InitializeInner() { base.InitializeInner(); DeviceContextHolder.Set <IMaterialsFactory>(new MaterialsProviderDeferred()); Scene.Add(SkyObject.Create(500f)); foreach (var showroom in _kn5.Skip(1)) { Scene.Add(new Kn5RenderableFile(showroom, Matrix.Identity)); } if (_kn5.Length > 1) { _car = new DeferredRenderableCar(CarDescription.FromKn5(_kn5[0]), Matrix.Identity, shadowsHeight: 0.001f, lights: Lights) { IsReflectable = false }; Scene.Add(_car); } Scene.UpdateBoundingBox(); Camera = new CameraOrbit(32) { Alpha = 0.9f, Beta = 0.1f, Radius = _car?.BoundingBox?.GetSize().Length() * 1.2f ?? 4.8f, Target = (_car?.BoundingBox?.GetCenter() ?? Vector3.Zero) - new Vector3(0f, 0.05f, 0f) }; _resetCamera = (CameraOrbit)Camera.Clone(); Sun = new DirectionalLight { Color = FixLight(new Vector3(1.2f, 1.0f, 0.9f)) * 5f, Direction = Vector3.Normalize(new Vector3(-1.2f, -3.4f, -2.2f)) }; _effect = DeviceContextHolder.GetEffect <EffectDeferredGObject>(); }
protected override void ExtendCar(Kn5RenderableCar car, RenderableList carWrapper) { if (_car != null) { _car.ObjectsChanged -= OnCarObjectsChanged; } base.ExtendCar(car, carWrapper); _car = car; if (_car != null) { _car.ObjectsChanged += OnCarObjectsChanged; } _carWrapper = carWrapper; _mirrorDirty = true; if (_meshDebug) { UpdateMeshDebug(car); } }
private void ApplyCarState() { var carData = CarData; if (carData == null) { return; } if (_dataWheels) { Kn5RenderableFile.UpdateModelMatrixInverted(CarNode); Kn5RenderableCar.SetWheelsByData(CarNode, carData.GetWheels(_suspensionModifiers), Matrix.Invert(carData.GetGraphicMatrix())); } Kn5RenderableCar.AdjustPosition(CarNode); if (_leftDoorOpen) { Kn5RenderableCar.CreateAnimator(carData.CarDirectory, carData.GetLeftDoorAnimation())?.SetImmediate(CarNode, 1f, null); } if (_rightDoorOpen) { Kn5RenderableCar.CreateAnimator(carData.CarDirectory, carData.GetRightDoorAnimation())?.SetImmediate(CarNode, 1f, null); } if (_headlightsEnabled) { foreach (var animation in carData.GetLightsAnimations()) { Kn5RenderableCar.CreateAnimator(carData.CarDirectory, animation)?.SetImmediate(CarNode, 1f, null); } } Kn5RenderableCar.SetCockpitLrActive(CarNode, _cockpitLrActive); Kn5RenderableCar.SetSeatbeltActive(CarNode, _seatbeltOnActive); Kn5RenderableCar.SetBlurredObjects(CarNode, carData.GetBlurredObjects().ToArray(), _blurredNodesActive ? 100f : 0f); if (_wingsStates != null) { var i = 0; foreach (var animation in carData.GetWingsAnimations()) { if (_wingsStates[i++]) { Kn5RenderableCar.CreateAnimator(carData.CarDirectory, animation)?.SetImmediate(CarNode, 1f, null); } } } if (_extraAnimationsStates != null) { var i = 0; foreach (var animation in carData.GetExtraAnimations()) { if (_extraAnimationsStates[i++]) { Kn5RenderableCar.CreateAnimator(carData.CarDirectory, animation)?.SetImmediate(CarNode, 1f, null); } } } }
protected virtual void ExtendCar(Kn5RenderableCar car, RenderableList carWrapper) { }
public async Task SetCarAsync(CarDescription car, string skinId = Kn5RenderableCar.DefaultSkin, CancellationToken cancellationToken = default(CancellationToken)) { ClearBeforeChangingCar(); GC.Collect(); GC.WaitForPendingFinalizers(); try { _loadingCar = car; if (_carWrapper == null) { _car = car; return; } if (car == null) { ClearExisting(); CarNode = null; _carBoundingBox = null; _car = null; Scene.UpdateBoundingBox(); return; } Kn5RenderableCar loaded = null; var previous = _previousCars.FirstOrDefault(x => x.Id == car.MainKn5File); if (previous != null) { _previousCars.Remove(previous); ClearExisting(); _carWrapper.AddRange(previous.Objects); _car = car; loaded = previous.Objects.OfType <Kn5RenderableCar>().First(); CopyValues(loaded, CarNode); CarNode = loaded; _carBoundingBox = null; if (_selectSkinLater) { CarNode.SelectSkin(DeviceContextHolder, _selectSkin); _selectSkinLater = false; } else { CarNode.SelectSkin(DeviceContextHolder, skinId); } Scene.UpdateBoundingBox(); return; } await car.LoadAsync(); if (cancellationToken.IsCancellationRequested) { return; } await Task.Run(() => { loaded = new Kn5RenderableCar(car, Matrix.Identity, _selectSkinLater ? _selectSkin : skinId, asyncTexturesLoading: AsyncTexturesLoading, asyncOverrideTexturesLoading: AsyncOverridesLoading, allowSkinnedObjects: AllowSkinnedObjects); _selectSkinLater = false; if (cancellationToken.IsCancellationRequested) { return; } CopyValues(loaded, CarNode); if (cancellationToken.IsCancellationRequested) { return; } loaded.Draw(DeviceContextHolder, null, SpecialRenderMode.InitializeOnly); }); if (cancellationToken.IsCancellationRequested || _loadingCar != car) { loaded?.Dispose(); return; } ClearExisting(); _carWrapper.Add(loaded); ExtendCar(loaded, _carWrapper); _car = car; _selectSkin = null; CarNode = loaded; _carBoundingBox = null; IsDirty = true; Scene.UpdateBoundingBox(); } catch (Exception e) { MessageBox.Show(e.ToString()); throw; } finally { if (ReferenceEquals(_loadingCar, car)) { _loadingCar = null; } } }
public void SetCar(CarDescription car, string skinId = Kn5RenderableCar.DefaultSkin) { ClearBeforeChangingCar(); try { _loadingCar = car; if (_carWrapper == null) { _car = car; return; } if (car == null) { ClearExisting(); CarNode = null; _carBoundingBox = null; _car = null; Scene.UpdateBoundingBox(); return; } Kn5RenderableCar loaded; var previous = _previousCars.FirstOrDefault(x => x.Id == car.MainKn5File); if (previous != null) { _previousCars.Remove(previous); ClearExisting(); _carWrapper.AddRange(previous.Objects); _car = car; loaded = previous.Objects.OfType <Kn5RenderableCar>().First(); CopyValues(loaded, CarNode); CarNode = loaded; _carBoundingBox = null; if (_selectSkinLater) { CarNode.SelectSkin(DeviceContextHolder, _selectSkin); _selectSkinLater = false; } else { CarNode.SelectSkin(DeviceContextHolder, skinId); } Scene.UpdateBoundingBox(); return; } loaded = new Kn5RenderableCar(car, Matrix.Identity, _selectSkinLater ? _selectSkin : skinId, asyncTexturesLoading: AsyncTexturesLoading, asyncOverrideTexturesLoading: AsyncOverridesLoading, allowSkinnedObjects: AllowSkinnedObjects); _selectSkinLater = false; CopyValues(loaded, CarNode); ClearExisting(); _carWrapper.Add(loaded); ExtendCar(loaded, _carWrapper); _car = car; _selectSkin = null; CarNode = loaded; _carBoundingBox = null; IsDirty = true; Scene.UpdateBoundingBox(); } catch (Exception e) { MessageBox.Show(e.ToString()); throw; } finally { if (ReferenceEquals(_loadingCar, car)) { _loadingCar = null; } } }
public async Task SetCarAsync(CarObject car, string skinId = Kn5RenderableCar.DefaultSkin, CancellationToken cancellationToken = default(CancellationToken)) { LicensePlateSelected = false; try { _loadingCar = car; if (_carWrapper == null) { _car = car; return; } if (car == null) { ClearExisting(); _car = null; CarNode = null; Scene.UpdateBoundingBox(); return; } Kn5RenderableCar loaded = null; FlatMirror reflection = null; var previous = _previousCars.FirstOrDefault(x => x.Id == car.Id); if (previous != null) { _previousCars.Remove(previous); ClearExisting(); _carWrapper.AddRange(previous.Objects); _car = car; loaded = previous.Objects.OfType <Kn5RenderableCar>().First(); loaded.LightsEnabled = CarNode?.LightsEnabled == true; CarNode = loaded; if (_selectSkinLater) { CarNode.SelectSkin(DeviceContextHolder, _selectSkin); _selectSkinLater = false; } else { CarNode.SelectSkin(DeviceContextHolder, skinId); } Scene.UpdateBoundingBox(); return; } await Task.Run(() => { var carKn5 = Kn5.FromFile(FileUtils.GetMainCarFilename(car.Location)); if (cancellationToken.IsCancellationRequested) { return; } loaded = new Kn5RenderableCar(carKn5, car.Location, Matrix.Identity, _selectSkinLater ? _selectSkin : skinId); _selectSkinLater = false; if (cancellationToken.IsCancellationRequested) { return; } loaded.LightsEnabled = CarNode?.LightsEnabled == true; if (cancellationToken.IsCancellationRequested) { return; } loaded.Draw(DeviceContextHolder, null, SpecialRenderMode.InitializeOnly); if (cancellationToken.IsCancellationRequested) { return; } reflection = new FlatMirror(loaded, new Plane(Vector3.Zero, Vector3.UnitY)); reflection.Draw(DeviceContextHolder, null, SpecialRenderMode.InitializeOnly); }); if (cancellationToken.IsCancellationRequested || _loadingCar != car) { loaded?.Dispose(); return; } ClearExisting(); _carWrapper.Add(loaded); _carWrapper.Add(reflection); _car = car; CarNode = loaded; _selectSkin = null; Scene.UpdateBoundingBox(); } catch (Exception e) { MessageBox.Show(e.ToString()); throw; } finally { if (ReferenceEquals(_loadingCar, car)) { _loadingCar = null; } } }