コード例 #1
0
 private static void WriteAnimation(string path, Animation an)
 {
     using (Stream s = File.OpenWrite(path))
     {
         AnimationFile.Write(an, s);
     }
 }
コード例 #2
0
        public static string ExportFile(FullModelData data, string path)
        {
            AnimationFile animationFile = new AnimationFile();

            foreach (Object3D object3D in data.SectionsOfType <Object3D>())
            {
                if (object3D.Animations.Count > 0)
                {
                    AnimationFileObject animationFileObject = new AnimationFileObject(object3D.HashName.String);

                    foreach (IAnimationController animationController in object3D.Animations)
                    {
                        if (animationController is LinearVector3Controller)
                        {
                            LinearVector3Controller linearVector3Controller = (LinearVector3Controller)animationController;
                            animationFileObject.PositionKeyframes = new List <Keyframe <Vector3> >(linearVector3Controller.Keyframes);
                        }
                        else if (animationController is QuatLinearRotationController)
                        {
                            QuatLinearRotationController quatLinearRotationController = (QuatLinearRotationController)animationController;
                            animationFileObject.RotationKeyframes = new List <Keyframe <Quaternion> >(quatLinearRotationController.Keyframes);
                        }
                    }

                    animationFile.Objects.Add(animationFileObject);
                }
            }

            animationFile.Write(path);

            return(path);
        }
コード例 #3
0
        AnimationClip LoadAnimation(string path)
        {
            var file      = _pfs.FindFile(path);
            var animation = AnimationFile.Create(file);

            return(new AnimationClip(animation));
        }
コード例 #4
0
        private static void CreateBoneTable(GameSkeleton skeleton, int[] bones, ref AnimationFile animFile)
        {
            // Add the bones
            for (int i = 0; i < bones.Length; i++)
            {
                var originalBoneIndex = bones[i];
                animFile.Bones[i] = new AnimationFile.BoneInfo()
                {
                    Id = i, Name = skeleton.BoneNames[originalBoneIndex], ParentId = skeleton.GetParentBone(originalBoneIndex)
                };
            }

            for (int i = 0; i < bones.Length; i++)
            {
                if (animFile.Bones[i].ParentId == -1)
                {
                    continue;
                }

                var parentName = skeleton.BoneNames[animFile.Bones[i].ParentId];
                var indexOf    = animFile.Bones.Select((value, index) => new { value.Name, index })
                                 .Where(pair => pair.Name == parentName)
                                 .Select(pair => pair.index + 1)
                                 .FirstOrDefault() - 1;
                animFile.Bones[i].ParentId = indexOf;
            }
        }
コード例 #5
0
        public GameSkeleton(AnimationFile skeletonFile, AnimationPlayer animationPlayer)
        {
            BoneCount       = skeletonFile.Bones.Count();
            Translation     = new Vector3[BoneCount];
            Rotation        = new Quaternion[BoneCount];
            _worldTransform = new Matrix[BoneCount];
            ParentBoneId    = new int[BoneCount];
            BoneNames       = new string[BoneCount];
            SkeletonName    = skeletonFile.Header.SkeletonName;
            AnimationPlayer = animationPlayer;

            int skeletonWeirdIndex = 0;

            for (int i = 0; i < BoneCount; i++)
            {
                ParentBoneId[i] = skeletonFile.Bones[i].ParentId;
                BoneNames[i]    = skeletonFile.Bones[i].Name;
                Rotation[i]     = new Quaternion(
                    skeletonFile.DynamicFrames[skeletonWeirdIndex].Quaternion[i].X,
                    skeletonFile.DynamicFrames[skeletonWeirdIndex].Quaternion[i].Y,
                    skeletonFile.DynamicFrames[skeletonWeirdIndex].Quaternion[i].Z,
                    skeletonFile.DynamicFrames[skeletonWeirdIndex].Quaternion[i].W);



                Translation[i] = new Vector3(
                    skeletonFile.DynamicFrames[skeletonWeirdIndex].Transforms[i].X * 1,
                    skeletonFile.DynamicFrames[skeletonWeirdIndex].Transforms[i].Y,
                    skeletonFile.DynamicFrames[skeletonWeirdIndex].Transforms[i].Z);
            }

            RebuildSkeletonMatrix();
        }
コード例 #6
0
        public void EncodeAnimation(AnimationFile animation, Stream stream)
        {
            StreamWriter file = new StreamWriter(stream);

            WriteAnimation(animation, file);
            file.Close();
        }
コード例 #7
0
        public static ObservableCollection <AnimatedBone> CreateFromSkeleton(AnimationFile file, List <int> boneIndexUsedByModel = null)
        {
            var output = new ObservableCollection <AnimatedBone>();

            foreach (var boneInfo in file.Bones)
            {
                var parent  = FindBoneInList(boneInfo.ParentId, output);
                var newNode = new AnimatedBone()
                {
                    BoneIndex = boneInfo.Id, Name = boneInfo.Name
                };
                if (boneIndexUsedByModel == null)
                {
                    newNode.IsUsedByCurrentModel = true;
                }
                else
                {
                    newNode.IsUsedByCurrentModel = boneIndexUsedByModel.Contains((byte)boneInfo.Id);
                }

                if (parent == null)
                {
                    output.Add(newNode);
                }
                else
                {
                    parent.Children.Add(newNode);
                }
            }
            return(output);
        }
コード例 #8
0
        public static void Import(FullModelData fmd, string path)
        {
            AnimationFile animationFile = new AnimationFile();

            animationFile.Read(path);

            foreach (AnimationFileObject animationObject in animationFile.Objects)
            {
                Object3D object3D = fmd.GetObject3DByHash(new HashName(animationObject.Name));

                Log.Default.Info("Trying to add animation to " + animationObject.Name);
                if (object3D != null)
                {
                    Log.Default.Info("Found " + animationObject.Name);

                    object3D.Animations.Clear(); // Kill the old anims.

                    if (animationObject.RotationKeyframes.Count > 0)
                    {
                        QuatLinearRotationController quatLinearRotationController = AddRotations(object3D, animationObject.RotationKeyframes);
                        fmd.AddSection(quatLinearRotationController);
                    }

                    if (animationObject.PositionKeyframes.Count > 0)
                    {
                        LinearVector3Controller linearVector3Controller = AddPositions(object3D, animationObject.PositionKeyframes);
                        fmd.AddSection(linearVector3Controller);
                    }
                }
                else
                {
                    Log.Default.Info("Not Found " + animationObject.Name);
                }
            }
        }
コード例 #9
0
ファイル: DebugStuff.cs プロジェクト: xWhitey/openvice
        /// <summary>
        /// Initialize debug data<para/>
        /// Инициализация отладочной иноформации
        /// </summary>
        public static void Init()
        {
            //Entities.Camera.Position = new OpenTK.Vector3(375.604f, 58.78056f, -585.3889f);

            rend         = new Graphics.Renderers.DebugRenderer();
            box          = new Graphics.Renderers.DebugRenderer.Box();
            box.LineSize = 2f;
            box.Size     = Vector3.One * 0.5f;
            //rend.Primitives.Add(box);


            AnimationFile fg = new AnimationFile(PathManager.GetAbsolute("anim/ped.ifp"));

            animation = fg["WALK_player"];


            man    = new Model(new ModelFile(ArchiveManager.Get("HFYST.dff"), true), true, true);
            manTex = new TextureDictionary(new TextureFile(ArchiveManager.Get("HFYST.txd"), true), true, true);



            ApplyAnimationFrame(man.Children, animation, 2);

            re    = new Graphics.Renderers.SkinnedRenderer();
            lines = new List <Graphics.Renderers.DebugRenderer.Line>();
        }
コード例 #10
0
 private void selectAnimation()
 {
     if (dSelectAnimation.ShowDialog() == DialogResult.OK)
     {
         string     basefile = Path.GetDirectoryName(dSelectAnimation.FileName);
         string     filename = Path.GetFileName(dSelectAnimation.FileName);
         FileSystem fs       = new FileSystem();
         fs.addRoot(basefile);
         addAnimation(Path.GetFileNameWithoutExtension(filename), AnimationFile.Load(fs, filename));
     }
 }
 public AnimationFile GetSkeletonFileFromName(PackFileService pfs, string skeletonName)
 {
     foreach (var name in SkeletonFileNames)
     {
         if (name.Contains(skeletonName))
         {
             var file = pfs.FindFile(name);
             if (file != null)
             {
                 return(AnimationFile.Create(file as PackFile));
             }
         }
     }
     return(null);
 }
コード例 #12
0
        public AnimationClip(AnimationFile file)
        {
            RotationMappings    = file.RotationMappings.ToList();
            TranslationMappings = file.TranslationMappings.ToList();
            PlayTimeInSec       = file.Header.AnimationTotalPlayTimeInSec;

            if (file.StaticFrame != null)
            {
                StaticFrame = CreateKeyFrame(file.StaticFrame);
            }

            foreach (var frame in file.DynamicFrames)
            {
                DynamicFrames.Add(CreateKeyFrame(frame));
            }
        }
コード例 #13
0
        void CreateAnimation(string riderSlot, string mountSlot, ErrorListViewModel.ErrorList resultInfo)
        {
            // Does the rider have this?
            var riderHasAnimation = _riderFragment.Fragments.FirstOrDefault(x => x.Slot.Value == riderSlot) != null;

            if (riderHasAnimation)
            {
                // Create a copy of the animation fragment entry
                var riderFragment    = _riderFragment.Fragments.First(x => x.Slot.Value == riderSlot);
                var newRiderFragment = riderFragment.Clone();
                var newAnimationName = GenerateNewAnimationName(newRiderFragment.AnimationFile, _animationPrefix);
                newRiderFragment.AnimationFile = newAnimationName;
                _riderOutputFragment.Fragments.Add(newRiderFragment);

                var mountFragment = _mountFragment.Fragments.First(x => x.Slot.Value == mountSlot);

                // Generate new animation
                var riderAnim = LoadAnimation(riderFragment.AnimationFile);
                var mountAnim = LoadAnimation(mountFragment.AnimationFile);


                var newAnimation = _animationGenerator.GenerateMountAnimation(mountAnim, riderAnim);

                // Save the new animation
                var animFile = newAnimation.ConvertToFileFormat(_animationGenerator.GetRiderSkeleton());
                var bytes    = AnimationFile.GetBytes(animFile);
                SaveHelper.Save(_pfs, newAnimationName, null, bytes);

                resultInfo.Ok(mountSlot, "Matching animation found in rider (" + riderSlot + "). New animation created");
            }
            else
            {
                // Add an empty fragment entry
                _riderOutputFragment.Fragments.Add(new AnimationFragmentEntry()
                {
                    Slot     = AnimationSlotTypeHelper.GetfromValue(riderSlot),
                    Skeleton = _riderFragment.Skeletons.Values.First()
                });

                resultInfo.Error(mountSlot, "Expected slot missing in  rider (" + riderSlot + "), this need to be resolved!");
            }
        }
コード例 #14
0
        public static AnimationFile ExtractPartOfSkeleton(GameSkeleton skeleton, string skeletonName, int[] bones)
        {
            // Header
            var animFile = new AnimationFile();

            animFile.Header.SkeletonName = skeletonName;
            animFile.Header.AnimationTotalPlayTimeInSec = 0.1f;
            animFile.Bones = new AnimationFile.BoneInfo[bones.Length];

            CreateBoneTable(skeleton, bones, ref animFile);

            // Create the keyframe
            animFile.DynamicFrames = new List <AnimationFile.Frame>();
            var frame = new AnimationFile.Frame();

            animFile.DynamicFrames.Add(frame);

            // Populate the keyframe
            for (int i = 0; i < bones.Length; i++)
            {
                var originalBoneIndex = bones[i];

                if (i == 0)
                {
                    var worldTrans = skeleton.GetWorldTransform(originalBoneIndex);
                    var res        = worldTrans.Decompose(out Vector3 scale, out var rot, out var trans);
                    frame.Transforms.Add(new RmvVector3(trans.X, trans.Y, trans.Z));
                    frame.Quaternion.Add(new RmvVector4(rot.X, rot.Y, rot.Z, rot.W));
                }
                else
                {
                    var trans = skeleton.Translation[originalBoneIndex];
                    var rot   = skeleton.Rotation[originalBoneIndex];

                    frame.Transforms.Add(new RmvVector3(trans.X, trans.Y, trans.Z));
                    frame.Quaternion.Add(new RmvVector4(rot.X, rot.Y, rot.Z, rot.W));
                }
            }

            return(animFile);
            //var sample = AnimationSampler.Sample(0, 0, skeleton, new List<AnimationClip>() { animation }, true, true);
        }
コード例 #15
0
        private static void CreateStaticFrameTable(AnimationFile existingAnim, int[] bones, ref AnimationFile newAnim)
        {
            newAnim.StaticFrame = new AnimationFile.Frame();
            for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
            {
                //existingAnim.TranslationMappings.Count
                var originalBoneIndex      = bones[boneIndex];
                var tanslationMappingValue = existingAnim.TranslationMappings[originalBoneIndex];
                if (tanslationMappingValue.IsStatic)
                {
                    newAnim.StaticFrame.Transforms.Add(existingAnim.StaticFrame.Transforms[tanslationMappingValue.Id]);
                }

                var rotationMappingValue = existingAnim.RotationMappings[originalBoneIndex];
                if (rotationMappingValue.IsStatic)
                {
                    newAnim.StaticFrame.Quaternion.Add(existingAnim.StaticFrame.Quaternion[rotationMappingValue.Id]);
                }
            }
        }
コード例 #16
0
        public AnimationFile ConvertToFileFormat(GameSkeleton skeleton)
        {
            AnimationFile output = new AnimationFile();

            //float frameRate =
            var fRate = (DynamicFrames.Count() - 1) / PlayTimeInSec;

            output.Header.FrameRate     = (float)Math.Floor(fRate);
            output.Header.AnimationType = 7;
            output.Header.AnimationTotalPlayTimeInSec = PlayTimeInSec;
            output.Header.SkeletonName = skeleton.SkeletonName;

            output.Bones = new BoneInfo[skeleton.BoneCount];
            for (int i = 0; i < skeleton.BoneCount; i++)
            {
                output.Bones[i] = new BoneInfo()
                {
                    Id       = i,
                    Name     = skeleton.BoneNames[i],
                    ParentId = skeleton.GetParentBone(i)
                };
            }

            // Mappings
            output.RotationMappings    = RotationMappings.ToList();
            output.TranslationMappings = TranslationMappings.ToList();

            // Static
            if (StaticFrame != null)
            {
                output.StaticFrame = CreateFrameFromKeyFrame(StaticFrame);
            }

            // Dynamic
            foreach (var frame in DynamicFrames)
            {
                output.DynamicFrames.Add(CreateFrameFromKeyFrame(frame));
            }

            return(output);
        }
コード例 #17
0
ファイル: DebugStuff.cs プロジェクト: sarath263/openvice
        /// <summary>
        /// Initialize debug data<para/>
        /// Инициализация отладочной иноформации
        /// </summary>
        public static void Init()
        {
            //Entities.Camera.Position = new OpenTK.Vector3(-1647.534f, 26.54692f, -667.5128f);

            rend         = new Graphics.Renderers.DebugRenderer();
            box          = new Graphics.Renderers.DebugRenderer.Box();
            box.LineSize = 2f;
            box.Size     = Vector3.One * 0.5f;
            //rend.Primitives.Add(box);

            AnimationFile fg = new AnimationFile(PathManager.GetAbsolute("anim/ped.ifp"));


            man    = new Model(new ModelFile(ArchiveManager.Get("cop.dff"), true), true, true);
            manTex = new TextureDictionary(new TextureFile(ArchiveManager.Get("cop.txd"), true), true, true);



            re = new Graphics.Renderers.SkinnedRenderer();
            RenderBonesRecursively(man.Children);
        }
コード例 #18
0
        static public PackFile SaveAnimation(PackFileService pfs, string riderAnimationName, string savePrefix, bool ensureUniqeName, AnimationClip clip, GameSkeleton skeleton)
        {
            var animFile = clip.ConvertToFileFormat(skeleton);
            var bytes    = AnimationFile.GetBytes(animFile);

            string savePath = "";

            if (string.IsNullOrWhiteSpace(savePrefix) == false)
            {
                if (ensureUniqeName)
                {
                    savePath = GenerateNewAnimationName(pfs, riderAnimationName, savePrefix);
                }
                else
                {
                    savePath = Path.GetDirectoryName(riderAnimationName) + "\\" + savePrefix + Path.GetFileName(riderAnimationName);
                }
            }

            return(SaveHelper.Save(pfs, savePath, null, bytes));
        }
        public void LoadFromPackFileContainer(PackFileService pfs, PackFileContainer packFileContainer)
        {
            var allAnimations = pfs.FindAllWithExtentionIncludePaths(".anim", packFileContainer);

            foreach (var animation in allAnimations)
            {
                try
                {
                    var animationSkeletonName = AnimationFile.GetAnimationHeader(animation.Item2).SkeletonName;
                    if (_skeletonNameToAnimationMap.ContainsKey(animationSkeletonName) == false)
                    {
                        _skeletonNameToAnimationMap.Add(animationSkeletonName, new ObservableCollection <AnimationReference>());
                    }

                    _skeletonNameToAnimationMap[animationSkeletonName].Add(new AnimationReference(pfs.GetFullPath(animation.Item2, packFileContainer), packFileContainer));
                }
                catch (Exception e)
                {
                    _logger.Here().Error("Parsing failed for " + pfs.GetFullPath(animation.Item2, packFileContainer) + "\n" + e.ToString());
                }
            }

            var allNormalSkeletons = allAnimations.Where(x => x.Item1.Contains("animations\\skeletons", StringComparison.InvariantCultureIgnoreCase));

            foreach (var item in allNormalSkeletons)
            {
                SkeletonFileNames.Add(item.Item1);
            }

            var techSkeletons = allAnimations.Where(x => x.Item1.Contains("tech", StringComparison.InvariantCultureIgnoreCase));

            foreach (var item in techSkeletons)
            {
                SkeletonFileNames.Add(item.Item1);
            }

            _logger.Here().Information("Animations found =" + allAnimations.Count());
            _logger.Here().Information("Skeletons found =" + SkeletonFileNames.Count());
        }
コード例 #20
0
ファイル: AnimationBaker.cs プロジェクト: MaddJhin/Holdout
 public void LoadAnimationDump(string filePath)
 {
     animClip = (AnimationFile) BINS.Load (filePath);
 }
コード例 #21
0
        public void WriteAnimation(AnimationFile animation, StreamWriter file)
        {
            // Node name list in the order that the nodes are written.
            List <string> serializedNames = new List <string>();

            file.WriteLine("HIERARCHY");

            void writeRecursiveNodes(AnimationFrame node, int indent)
            {
                string indentStr = new String('\t', indent);

                if (indent != 0)
                {
                    file.WriteLine(indentStr + "JOINT " + node.Name);
                }
                else
                {
                    file.WriteLine(indentStr + "ROOT " + node.Name);
                }

                // TODO: Make this properly read the model's bind pose.
                float3 offset = animation.Offsets[node.Name];

                file.WriteLine(indentStr + "{");
                file.WriteLine(indentStr + "\tOFFSET " + offset.x + " " + offset.y + " " + offset.z);
                file.WriteLine(indentStr + "\tCHANNELS 6 Xposition Yposition Zposition Xrotation Yrotation Zrotation");

                if (node.Children.Count > 0)
                {
                    // Write children
                    foreach (AnimationFrame child in node.Children)
                    {
                        serializedNames.Add(child.Name);
                        writeRecursiveNodes(child, indent + 1);
                    }
                }
                else
                {
                    // Write the bone end.
                    file.WriteLine(indentStr + "\tEnd Site");
                    file.WriteLine(indentStr + "\t{");
                    file.WriteLine(indentStr + "\t\tOFFSET .25 .25 .25");
                    file.WriteLine(indentStr + "\t}");
                }
                file.WriteLine(indentStr + "}");
            }

            // Get first frame to create skeleton from.
            AnimationFrame root = animation.Frames[0];

            serializedNames.Add(root.Name);
            writeRecursiveNodes(root, 0);

            List <AnimationFrame> frames = animation.Frames;

            file.WriteLine("MOTION");
            file.WriteLine("Frames: " + frames.Count);
            file.WriteLine("Frame Time: " + animation.FrameTimeMillis / 1000);

            void writeNode(AnimationFrame node)
            {
                // Convert quaternion to euler and radians to degrees.
                float3 rotation = (float3)(node.Rotation.xyz * (180 / Math.PI));

                file.Write(node.Position.x + " " + node.Position.y + " " + node.Position.z + " " + rotation.x + " " + rotation.y + " " + rotation.z + " ");

                if (node.Children.Count > 0)
                {
                    foreach (AnimationFrame child in node.Children)
                    {
                        writeNode(child);
                    }
                }
            }

            for (int i = 0; i < frames.Count; i++)
            {
                writeNode(frames[i]);
                file.WriteLine("");
            }
        }
コード例 #22
0
        public void Load(System.IO.Stream stream)
        {
            CanSave = false;

            using (var reader = new FileReader(stream))
            {
                reader.SetByteOrder(true);

                Text = FileName;
                while (!reader.EndOfStream)
                {
                    ChunkHeader chunk = new ChunkHeader();
                    chunk.Position   = reader.Position;
                    chunk.Identifier = reader.ReadUInt32();
                    uint unk = reader.ReadUInt32();
                    chunk.ChunkSize   = reader.ReadUInt32();
                    chunk.ChunkId     = reader.ReadUInt32();
                    chunk.NextFilePtr = reader.ReadUInt32();
                    chunk.FileSize    = reader.ReadUInt32();
                    uint unk2 = reader.ReadUInt32();
                    uint unk3 = reader.ReadUInt32();
                    Chunks.Add(chunk);

                    var Identifer = chunk.Identifier.Reverse();
                    switch (Identifer)
                    {
                    case ChunkTextureFile:
                        SWUTexture texture = new SWUTexture();
                        reader.SeekBegin(chunk.Position + 72);
                        texture.ImageKey         = "texture";
                        texture.SelectedImageKey = "texture";
                        texture.ReadChunk(reader);
                        chunk.ChunkData = texture;
                        if (chunk.ChunkSize > 244)
                        {
                            reader.Seek(chunk.Position + 244, System.IO.SeekOrigin.Begin);
                            chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
                            texture.Text   = chunk.FileName;
                        }
                        Nodes.Add(texture);
                        break;

                    case ChunkMetaInfo:
                        break;

                    case ChunkAnimInfo:
                        if (chunk.ChunkSize > 0xB0)
                        {
                            reader.Seek(chunk.Position + 0xB0, System.IO.SeekOrigin.Begin);
                            chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
                        }
                        break;

                    case ChunkAnimData:
                        AnimationFile animFile = new AnimationFile();
                        animFile.Read(reader);
                        chunk.ChunkData = animFile;
                        break;

                    case ChunkSkeletonData:
                        SkeletonFile skelFile = new SkeletonFile();
                        skelFile.Read(reader);
                        chunk.ChunkData = skelFile;
                        break;

                    case ChunkModelData:
                        ModelFile modelFile = new ModelFile();
                        modelFile.Read(reader);
                        chunk.ChunkData = modelFile;
                        break;

                    case ChunkMaterialData:
                        MaterialFile matFile = new MaterialFile();
                        matFile.Read(reader);
                        chunk.ChunkData = matFile;
                        break;
                    }

                    reader.Seek(chunk.Position + chunk.ChunkSize, System.IO.SeekOrigin.Begin);
                }

                ReadGPUFile(FilePath);
            }

            TreeHelper.CreateFileDirectory(this);
        }
コード例 #23
0
        private void BtnConvert_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(TxtInputFolder.Text))
            {
                MessageBox.Show(
                    "Input folder not found!",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                return;
            }

            if (!Directory.Exists(TxtOutFolder.Text))
            {
                MessageBox.Show(
                    "Output folder not found!",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);

                return;
            }

            string[] Files          = Directory.GetFiles(TxtInputFolder.Text);
            string[] AnimationFiles = Directory.GetFiles(TxtInputAnimationFolder.Text);

            bool ExportModels = ChkExportModels.Checked;
            bool ExportAnims  = ChkExportAnimations.Checked;
            bool ExportTexs   = ChkExportTextures.Checked;
            bool PrefixNames  = ChkPrefixNames.Checked;

            int Format = CmbFormat.SelectedIndex;

            int FileIndex = 0;

            int CountFiles = 0;

            //TODO: Use Parallel loop for more speed and keep UI responsive
            foreach (string File in Files)
            {
                H3D Data = FormatIdentifier.IdentifyAndOpen(File);
                if (Data != null)
                {
                    string BaseName = PrefixNames ? Path.GetFileNameWithoutExtension(File) + "_" : string.Empty;

                    BaseName = Path.Combine(TxtOutFolder.Text, BaseName);

                    if (!PrefixNames)
                    {
                        BaseName += Path.DirectorySeparatorChar;
                    }

                    if (ExportModels)
                    {
                        for (int Index = 0; Index < Data.Models.Count; Index++)
                        {
                            string FileName = BaseName + Data.Models[Index].Name;

                            switch (Format)
                            {
                            case 0: new DAE(Data, Index).Save(FileName + ".dae"); break;

                            case 1: new SMD(Data, Index).Save(FileName + ".smd"); break;
                            }
                        }
                    }
                    if (ExportAnims)
                    {
                        string Filename    = Path.GetFileName(File);
                        string ModelFolder = File.Replace(Filename, "");

                        foreach (string AnimationFile in AnimationFiles)
                        {
                            if (AnimationFile.Contains(Filename))
                            {
                                string   AnimationFolder = AnimationFile.Replace(Filename, "");
                                string[] MergedFiles     = new string[] { Path.Combine(ModelFolder, Filename), Path.Combine(AnimationFolder, Filename) };
                                H3D      MergedData      = FileIO.Merge(MergedFiles, new Rendering.Renderer(1, 1), Data);
                                for (int Index = 0; Index < MergedData.SkeletalAnimations.Count; Index++)
                                {
                                    string FileName = BaseName + MergedData.Models[0].Name + "_" + MergedData.SkeletalAnimations[Index].Name;
                                    switch (Format)
                                    {
                                    case 0: new DAE(MergedData, 0, Index).Save(FileName + ".dae"); break;

                                    case 1: new SMD(MergedData, 0, Index).Save(FileName + ".smd"); break;
                                    }
                                }
                            }
                        }
                    }

                    if (ExportTexs)
                    {
                        foreach (H3DTexture Tex in Data.Textures)
                        {
                            Tex.ToBitmap().Save(Path.Combine(TxtOutFolder.Text, Tex.Name + ".png"));
                        }
                    }
                }

                float Progress = ++FileIndex;

                Progress = (Progress / Files.Length) * 100;

                ProgressConv.Value = (int)Progress;

                Application.DoEvents();
                CountFiles++;
            }
        }
コード例 #24
0
ファイル: EditorScripts.cs プロジェクト: thegreatpl/GGJ2020
    static void CreateAnimations()
    {
        var fileCollection = new AnimationFile();

        fileCollection.Collections = new List <AnimationCollection>();
        var files = Directory.GetFiles($"{FileLoader.ModPath}/{SpriteManager.SpritePath}", "*.png", SearchOption.AllDirectories);

        foreach (var file in files)
        {
            var filename   = Path.GetFileNameWithoutExtension(file);
            var collection = new AnimationCollection();
            collection.LayerName  = Path.GetFileNameWithoutExtension(file);
            collection.Animations = new List <AnimationDefine>()
            {
                new AnimationDefine()
                {
                    AnimationName = "WalkRight", Sprites = new string[]
                    {
                        $"{filename}_0_9",
                        $"{filename}_1_9",
                        $"{filename}_2_9",
                        $"{filename}_8_9",
                        $"{filename}_3_9",
                        $"{filename}_4_9",
                        $"{filename}_5_9",
                        $"{filename}_6_9",
                        $"{filename}_7_9",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "WalkLeft", Sprites = new string[]
                    {
                        $"{filename}_0_11",
                        $"{filename}_1_11",
                        $"{filename}_2_11",
                        $"{filename}_3_11",
                        $"{filename}_4_11",
                        $"{filename}_5_11",
                        $"{filename}_6_11",
                        $"{filename}_7_11",
                        $"{filename}_8_11",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "WalkUp", Sprites = new string[]
                    {
                        $"{filename}_0_12",
                        $"{filename}_1_12",
                        $"{filename}_2_12",
                        $"{filename}_3_12",
                        $"{filename}_4_12",
                        $"{filename}_5_12",
                        $"{filename}_6_12",
                        $"{filename}_7_12",
                        $"{filename}_8_12",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "WalkDown", Sprites = new string[]
                    {
                        $"{filename}_0_10",
                        $"{filename}_1_10",
                        $"{filename}_2_10",
                        $"{filename}_3_10",
                        $"{filename}_4_10",
                        $"{filename}_5_10",
                        $"{filename}_6_10",
                        $"{filename}_7_10",
                        $"{filename}_8_10",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "IdleRight", Sprites = new string[]
                    {
                        $"{filename}_0_9",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "IdleLeft", Sprites = new string[]
                    {
                        $"{filename}_0_11",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "IdleUp", Sprites = new string[]
                    {
                        $"{filename}_0_12",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "IdleDown", Sprites = new string[]
                    {
                        $"{filename}_0_10",
                    }
                },
                //5-8
                new AnimationDefine()
                {
                    AnimationName = "AttackLeft", Sprites = new string[]
                    {
                        $"{filename}_0_7",
                        $"{filename}_1_7",
                        $"{filename}_2_7",
                        $"{filename}_3_7",
                        $"{filename}_4_7",
                        $"{filename}_5_7",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "AttackRight", Sprites = new string[]
                    {
                        $"{filename}_0_5",
                        $"{filename}_1_5",
                        $"{filename}_2_5",
                        $"{filename}_3_5",
                        $"{filename}_4_5",
                        $"{filename}_5_5",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "AttackUp", Sprites = new string[]
                    {
                        $"{filename}_0_8",
                        $"{filename}_1_8",
                        $"{filename}_2_8",
                        $"{filename}_3_8",
                        $"{filename}_4_8",
                        $"{filename}_5_8",
                    }
                },
                new AnimationDefine()
                {
                    AnimationName = "AttackDown", Sprites = new string[]
                    {
                        $"{filename}_0_6",
                        $"{filename}_1_6",
                        $"{filename}_2_6",
                        $"{filename}_3_6",
                        $"{filename}_4_6",
                        $"{filename}_5_6",
                    }
                },
            };
            fileCollection.Collections.Add(collection);
        }
        FileLoader.SaveAsJson($"{FileLoader.ModPath}/{AnimationManager.AnimationFolder}/animations.json", fileCollection);
    }
コード例 #25
0
ファイル: AnimationBaker.cs プロジェクト: MaddJhin/Holdout
 public void ResetAnimationDump()
 {
     animClip = new AnimationFile("dump",-1,-1,new BoneState[0]);
 }
コード例 #26
0
        public MeshFitterViewModel(RemappedAnimatedBoneConfiguration configuration, List <Rmv2MeshNode> meshNodes, GameSkeleton targetSkeleton, AnimationFile currentSkeletonFile, IComponentManager componentManager) : base(configuration)
        {
            _meshNodes        = meshNodes;
            _dwarfSkeleton    = targetSkeleton;
            _componentManager = componentManager;

            _animationPlayer    = _componentManager.GetComponent <AnimationsContainerComponent>().RegisterAnimationPlayer(new AnimationPlayer(), "Temp animation rerig");
            _humanoid01Skeleton = new GameSkeleton(currentSkeletonFile, _animationPlayer);


            // Build empty animation
            _animationClip = new AnimationClip();
            _animationClip.DynamicFrames.Add(new AnimationClip.KeyFrame());

            for (int i = 0; i < _humanoid01Skeleton.BoneCount; i++)
            {
                _animationClip.DynamicFrames[0].Rotation.Add(_humanoid01Skeleton.Rotation[i]);
                _animationClip.DynamicFrames[0].Position.Add(_humanoid01Skeleton.Translation[i]);
                _animationClip.DynamicFrames[0].Scale.Add(Vector3.One);

                _animationClip.RotationMappings.Add(new AnimationFile.AnimationBoneMapping(i));
                _animationClip.TranslationMappings.Add(new AnimationFile.AnimationBoneMapping(i));
            }


            _animationPlayer.SetAnimation(_animationClip, _humanoid01Skeleton);
            _animationPlayer.Play();


            var resourceLib = _componentManager.GetComponent <ResourceLibary>();

            _currentSkeletonNode = new SkeletonNode(resourceLib.Content, new SimpleSkeletonProvider(_humanoid01Skeleton));
            _componentManager.GetComponent <SceneManager>().RootNode.AddObject(_currentSkeletonNode);


            _oldAnimationPlayer = _meshNodes.First().AnimationPlayer;
            foreach (var mesh in _meshNodes)
            {
                mesh.AnimationPlayer = _animationPlayer;
            }
        }