public void SelectSkin(string skinId) { if (CarNode == null) { _selectSkinLater = true; _selectSkin = skinId; } else { CarNode?.SelectSkin(DeviceContextHolder, skinId); } }
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; } } }