Example #1
0
        public void SaveMovement(string steerKsAnimFilename)
        {
            if (RootNode == null)
            {
                throw new Exception("The root “DRIVER:DRIVER” node not found in model");
            }

            if (!_originalPosition.HasValue)
            {
                return;
            }

            LocalMatrix       = _originalPosition.Value;
            _originalPosition = null;

            RootNode.LocalMatrix = _summaryMovement * RootNode.LocalMatrix;
            _summaryMovement     = Matrix.Identity;
            _pivot.Reset();

            var anim = KsAnim.FromFile(steerKsAnimFilename);
            var root = anim.Entries.GetValueOrDefault("DRIVER:DRIVER");

            if (root == null)
            {
                throw new Exception("Animation do not have the root “DRIVER:DRIVER” node");
            }

            if (root.GetMatrices().Length > 1)
            {
                throw new Exception("The root “DRIVER:DRIVER” node is animated");
            }

            root.SetMatrices(new[] { RootNode.LocalMatrix }, root.Size);
            anim.SaveRecyclingOriginal(anim.OriginalFilename);
        }
Example #2
0
        private void Reload()
        {
            _original = File.Exists(_filename) ? KsAnim.FromFile(_filename) : KsAnim.CreateEmpty();

            if (_wrappers != null)
            {
                for (var i = 0; i < _wrappers.Length; i++)
                {
                    _wrappers[i].Set(null);
                }

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

            if (_parent != null)
            {
                Initialize(_parent);
                Set(_currentPosition);
            }

            if (_holder != null && _holder.TryGetTarget(out var holder))
            {
                holder.RaiseSceneUpdated();
            }
        }
Example #3
0
 public KsAnimAnimator(string filename, float duration, bool skipFixed)
 {
     _duration  = duration;
     _skipFixed = skipFixed;
     _filename  = filename;
     _original  = File.Exists(_filename) ? KsAnim.FromFile(_filename) : KsAnim.CreateEmpty();
     _watcher   = DirectoryWatcher.WatchFile(filename, Reload);
 }
Example #4
0
 public KsAnimAnimator(string filename, float duration)
 {
     _duration = duration;
     _original = KsAnim.FromFile(filename);
 }
Example #5
0
        private ITestEntry ResolveQuery([NotNull] string query)
        {
            var s0     = query.IndexOf('/', 2);
            var s1     = query.LastIndexOf('/');
            var piece0 = s0 == -1 ? query.Substring(2) : query.Substring(2, s0 - 2);
            var piece1 = s1 == s0 ? s0 == 0 ? string.Empty : query.Substring(s0 + 1) : query.Substring(s0 + 1, s1 - s0 - 1);
            var piece2 = s1 == s0 ? string.Empty : query.Substring(s1 + 1);

            if (piece0.EndsWith(".ini"))
            {
                return(new ListTestEntry(LoadIni().NonNull().ToList()));
            }
            if (piece0.EndsWith(".ksanim"))
            {
                return(new ListTestEntry(LoadAnimation().NonNull().ToList()));
            }
            if (piece0 == "userDefined")
            {
                var value = _userDefined.GetValueOrDefault(piece1);
                if (value == null)
                {
                    return(new ConstTestEntry(false));
                }
                return(new DefinitionTestEntry(Filter.Create(this, value, _filterParams)));
            }

            return(null);

            IEnumerable <string> LoadIni()
            {
                var s2 = piece1.IndexOf('[');
                IFilter <IniFileSection> sectionContentFilter = null;

                if (s2 != -1 && piece1.EndsWith("]"))
                {
                    sectionContentFilter = SectionFilterFactory.Create(piece1.Substring(s2 + 1, piece1.Length - s2 - 2));
                    piece1 = piece1.Substring(0, s2);
                }
                var sectionNameFilter = Filter.Create(StringTester.Instance, piece1, true);
                var valueNameFilter   = Filter.Create(StringTester.Instance, piece2, true);

                return(_carData.GetIniFile(piece0)
                       .Where(section => sectionNameFilter.Test(section.Key) && sectionContentFilter?.Test(section.Value) != false)
                       .SelectMany(section => section.Value)
                       .Where(pair => valueNameFilter.Test(pair.Key))
                       .Select(pair => pair.Value));
            }

            IEnumerable <string> LoadAnimation()
            {
                var animation = Path.Combine(_carDirectory, "animations", piece0);

                if (File.Exists(animation))
                {
                    foreach (var entry in KsAnim.FromFile(animation)
                             .Entries.Where(x => !x.Value.IsStatic()))
                    {
                        yield return(entry.Key);
                    }
                }
            }
        }