Example #1
0
        private void LoadDriverModel()
        {
            if (_driver != null)
            {
                return;
            }

            var driverDescription = _carData.GetDriverDescription();

            if (driverDescription == null || !File.Exists(_driverModelFilename))
            {
                return;
            }

            var driver = new Kn5RenderableDriver(Kn5.FromFile(_driverModelFilename), Matrix.Translation(driverDescription.Offset),
                                                 _currentSkin == null ? null : Path.Combine(_skinsDirectory, _currentSkin),
                                                 AsyncTexturesLoading, _asyncOverrideTexturesLoading, _converter)
            {
                LiveReload     = LiveReload,
                MagickOverride = MagickOverride
            };

            _driver = driver;

            if (File.Exists(_driverHierarchyFilename))
            {
                driver.AlignNodes(Knh.FromFile(_driverHierarchyFilename));
            }

            _driverSteerAnimator = Lazier.Create(() => {
                var animator = CreateAnimator(RootDirectory, driverDescription.SteerAnimation,
                                              clampEnabled: false, skipFixed: false);
                if (animator == null)
                {
                    return(null);
                }

                animator.Reset += OnSteerAnimatorReset;
                return(animator);
            });
            _driverSteerLock = driverDescription.SteerAnimationLock;

            driver.LocalMatrix = RootObject.LocalMatrix;
            Add(driver);
            ObjectsChanged?.Invoke(this, EventArgs.Empty);

            if (_steerDeg != 0 || OptionFixKnh)
            {
                UpdateDriverSteerAnimation(GetSteerOffset());
            }

            if (DebugMode)
            {
                driver.DebugMode = true;
            }
        }
Example #2
0
        private void InitializeDriver()
        {
            if (_driverSet)
            {
                return;
            }
            _driverSet = true;

            if (_driverHierarchyFilename == null)
            {
                _driverHierarchyFilename = Path.Combine(RootDirectory, "driver_base_pos.knh");
                _driverHierarchyWatcher  = SimpleDirectoryWatcher.WatchFile(_driverHierarchyFilename, () => {
                    _driver?.AlignNodes(Knh.FromFile(_driverHierarchyFilename));
                });
            }

            var driver = _carData.GetDriverDescription();

            if (driver == null)
            {
                return;
            }

            var contentDirectory = Path.GetDirectoryName(Path.GetDirectoryName(RootDirectory));

            if (contentDirectory == null)
            {
                return;
            }

            var driversDirectory = Path.Combine(contentDirectory, "driver");

            _driverModelFilename = Path.Combine(driversDirectory, driver.Name + ".kn5");
            _driverModelWatcher  = SimpleDirectoryWatcher.WatchFile(_driverModelFilename, ReloadDriverModel);
            LoadDriverModel();

            ObjectsChanged?.Invoke(this, EventArgs.Empty);
        }