public AnimatedModel(Engine engine, Skeleton skeleton, ModelVariantIdentifier variant, ModelDefinition definition, ModelQuality quality)
            : base(engine, variant, definition, quality)
        {
            Skeleton = skeleton;
            _AnimationPlayer = new AnimationPlayer();

            var nameMap = new Dictionary<string, int>();
            for (var i = 0; i < Skeleton.BoneNames.Length; ++i)
                nameMap.Add(Skeleton.BoneNames[i], i);
            _BoneMap = Definition.BoneNames.Select(n => nameMap[n]).ToArray();
            _InvertedReferencePose = Skeleton.ReferencePose.Select(_ => Matrix.Invert(_)).ToArray();
        }
        public AnimationContainer(Skeleton skeleton, PapFile file)
        {
            Skeleton = skeleton;
            File = file;

            _AnimationNameMap = file.Animations.ToDictionary(_ => _.Name, _ => _.Index);
            _UnmanagedPtr = HavokInterop.Execute(() => Interop.loadAnimationContainer(skeleton._UnmanagedPtr, file.HavokData, file.HavokData.Length));

            var numAnim = HavokInterop.Execute(() => Interop.getNumAnimations(_UnmanagedPtr));
            if (AnimationCount != numAnim)
                throw new System.IO.InvalidDataException();
        }
 public AnimatedModel(Engine engine, Skeleton skeleton, ModelVariantIdentifier variant, ModelDefinition definition)
     : this(engine, skeleton, variant, definition, ModelQuality.High)
 {
 }
 public AnimatedModel(Engine engine, Skeleton skeleton, ModelVariantIdentifier variant, ModelFile file, ModelQuality quality)
     : this(engine, skeleton, variant, file.GetModelDefinition(), quality)
 {
 }
        private bool TryGetModel(out Skeleton skeleton, out ModelDefinition model, out ImcVariant variant, out int m, out int b)
        {
            model = null;
            skeleton = null;
            variant = ImcVariant.Default;
            m = 0;
            b = 0;

            var asVariant = SelectedEntry as Models.ModelCharaVariant;
            if (asVariant == null)
                return false;

            int v = asVariant.Value;
            b = asVariant.Parent.Value;
            m = asVariant.Parent.Parent.Value;

            var imcPath = string.Format(ImcPathFormat, m, b);
            var mdlPath = string.Format(ModelPathFormat, m, b);
            var sklPath = string.Format(SkeletonPathFormat, m, 1);// b);

            SaintCoinach.IO.File imcFileBase;
            SaintCoinach.IO.File mdlFileBase;
            if (!Parent.Realm.Packs.TryGetFile(imcPath, out imcFileBase) || !Parent.Realm.Packs.TryGetFile(mdlPath, out mdlFileBase) || !(mdlFileBase is ModelFile)) {
                System.Windows.MessageBox.Show(string.Format("Unable to find files for {0}.", asVariant), "File not found", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return false;
            }

            SaintCoinach.IO.File sklFileBase;
            if(!Parent.Realm.Packs.TryGetFile(sklPath, out sklFileBase)) {
                System.Windows.MessageBox.Show(string.Format("Unable to find skeleton for {0}.", asVariant), "File not found", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return false;
            }

            skeleton = new Skeleton(new SklbFile(sklFileBase));

            try {
                var imcFile = new ImcFile(imcFileBase);
                model = ((ModelFile)mdlFileBase).GetModelDefinition();
                variant = imcFile.GetVariant(v);

                return true;
            } catch (Exception e) {
                System.Windows.MessageBox.Show(string.Format("Unable to load model for {0}:{1}{2}", asVariant, Environment.NewLine, e), "Failure to load", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return false;
            }
        }
        private IComponent CreateModel(Engine engine, Skeleton skeleton, ModelDefinition model, ImcVariant variant, int m, int b)
        {
            const string PapPathFormat = "chara/monster/m{0:D4}/animation/a0001/bt_common/resident/monster.pap";

            var component = new AnimatedModel(engine, skeleton, variant, model, ModelQuality.High) {

            };

            var papPath = string.Format(PapPathFormat, m, b);

            SaintCoinach.IO.File papFileBase;
            if (Parent.Realm.Packs.TryGetFile(papPath, out papFileBase)) {
                var anim = new AnimationContainer(skeleton, new PapFile(papFileBase));

                var hasAnim = false;
                for(var i = 0; i < DefaultAnimationNames.Length && !hasAnim; ++i) {
                    var n = DefaultAnimationNames[i];
                    if (anim.AnimationNames.Contains(n)) {
                        component.AnimationPlayer.Animation = anim.Get(n);
                        hasAnim = true;
                    }
                }

                if (!hasAnim)
                    component.AnimationPlayer.Animation = anim.Get(0);
            }
            return component;
        }
示例#7
0
 public AnimatedModel(Engine engine, Skeleton skeleton, ModelVariantIdentifier variant, ModelDefinition definition) : this(engine, skeleton, variant, definition, ModelQuality.High)
 {
 }
示例#8
0
 public AnimatedModel(Engine engine, Skeleton skeleton, ModelVariantIdentifier variant, ModelFile file, ModelQuality quality) : this(engine, skeleton, variant, file.GetModelDefinition(), quality)
 {
 }