Example #1
0
        public static IEnumerable <Bar.Entry> AddOrReplace(
            this IEnumerable <Bar.Entry> entries, Bar.Entry entry)
        {
            var existingEntry = entries
                                .FirstOrDefault(x => x.Type == entry.Type && x.Name == entry.Name && x.Index == 0);

            if (existingEntry == null)
            {
                entries = entries.Concat(new Bar.Entry[] {
                    new Bar.Entry
                    {
                        Type   = entry.Type,
                        Name   = entry.Name,
                        Index  = 0,
                        Stream = entry.Stream
                    }
                });
            }
            else
            {
                existingEntry.Stream = entry.Stream;
            }

            return(entries);
        }
Example #2
0
        // Loads the User Control required for the given bar entry
        public void openBarEntry(Bar.Entry barEntry)
        {
            if (barEntry == null)
            {
                contentFrame.Content = null;
                return;
            }

            switch (barEntry.Type)
            {
            case Bar.EntryType.Model:
                contentFrame.Content = new ModelFile_Control(mainWiewModel.ModelFile);
                break;

            case Bar.EntryType.ModelTexture:
                contentFrame.Content = new TextureFile_Control(mainWiewModel.TextureFile);
                break;

            case Bar.EntryType.ModelCollision:
                contentFrame.Content = new Collision_Control(mainWiewModel.CollisionFile);
                break;

            default:
                break;
            }
        }
Example #3
0
        private static void LoadFontTest(
            int expectedWidth,
            int expectedHeight,
            int bitsPerPixel,
            string name,
            Func <FontContext, IImage> getter)
        {
            var expectedLength = expectedWidth * expectedHeight * bitsPerPixel / 8;

            var fontContext = new FontContext();
            var entry       = new Bar.Entry
            {
                Name   = name,
                Type   = Bar.EntryType.RawBitmap,
                Stream = CreateStream(expectedLength)
            };

            fontContext.Read(new Bar.Entry[] { entry });

            var image = getter(fontContext);

            Assert.NotNull(image);
            Assert.Equal(expectedWidth, image.Size.Width);
            Assert.Equal(expectedHeight, image.Size.Height);
            Assert.Equal(expectedLength, entry.Stream.Position);
        }
Example #4
0
        public static IEnumerable <Bar.Entry> ForEntry(this IEnumerable <Bar.Entry> entries, Bar.EntryType type, string name, int index, Action <Bar.Entry> funcEntry)
        {
            var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name && x.Index == index);

            if (entry == null)
            {
                entry = new Bar.Entry
                {
                    Type   = type,
                    Name   = name,
                    Index  = index,
                    Stream = new MemoryStream()
                };

                entries = entries.Concat(new Bar.Entry[] { entry });
            }

            funcEntry(entry);
            return(entries);
        }
Example #5
0
        // Loads the User Control required for the given bar entry
        public void openBarEntry(Bar.Entry barEntry)
        {
            saveLoadedAnimationBinary();
            if (barEntry == null || barEntry.Stream.Length == 0)
            {
                contentFrame.Content = null;
                return;
            }

            switch (barEntry.Type)
            {
            case Bar.EntryType.Anb:
                contentFrame.Content  = new AnimBin_Control(barEntry.Stream);
                loadedAnimationBinary = barEntry;
                break;

            default:
                break;
            }
        }
Example #6
0
        public void Run()
        {
            ImGui.Text("The selected file contains multiple elements.");
            ImGui.Text("Please choose the appropiate sub-files you want to load.");

            ImGui.Columns(2, "resources", true);
            ImGui.Text("Animation");
            for (var i = 0; i < _animations.Length; i++)
            {
                if (ImGui.Selectable($"{_animations[i].Name}##anm",
                                     _selectedAnimIndex == i,
                                     ImGuiSelectableFlags.DontClosePopups))
                {
                    _selectedAnimIndex = i;
                }
            }

            ImGui.NextColumn();
            ImGui.Text("Texture");
            for (var i = 0; i < _textures.Length; i++)
            {
                if (ImGui.Selectable($"{_textures[i].Name}##tex",
                                     _selectedTextureIndex == i,
                                     ImGuiSelectableFlags.DontClosePopups))
                {
                    _selectedTextureIndex = i;
                }
            }

            ImGui.Columns(1);
            ImGui.Separator();
            if (ImGui.Button("Open"))
            {
                HasResourceBeenSelected = true;
                SelectedAnimation       = _animations[_selectedAnimIndex];
                SelectedTexture         = _textures[_selectedTextureIndex];
                ImGui.CloseCurrentPopup();
            }
        }
Example #7
0
        private static void PatchBinarc(Context context, AssetFile assetFile, Stream stream)
        {
            var binarc = Bar.IsValid(stream) ? Bar.Read(stream) :
                         new Bar()
            {
                Motionset = assetFile.MotionsetType
            };

            foreach (var file in assetFile.Source)
            {
                if (!Enum.TryParse <Bar.EntryType>(file.Type, true, out var barEntryType))
                {
                    throw new Exception($"BinArc type {file.Type} not recognized");
                }

                var entry = binarc.FirstOrDefault(x => x.Name == file.Name && x.Type == barEntryType);
                if (entry == null)
                {
                    entry = new Bar.Entry
                    {
                        Name   = file.Name,
                        Type   = barEntryType,
                        Stream = new MemoryStream()
                    };
                    binarc.Add(entry);
                }

                PatchFile(context, file, entry.Stream);
            }

            Bar.Write(stream.SetPosition(0), binarc);
            foreach (var entry in binarc)
            {
                entry.Stream?.Dispose();
            }
        }
Example #8
0
 public AnbEntryWrapper(int index, Bar.Entry entry)
 {
     Index = index;
     Entry = entry;
     Name  = "[" + Index + "] " + Entry.Name + " [" + (MotionSet.MotionName)(index / 4) + "]";
 }
Example #9
0
 private static bool IsDoct(Bar.Entry entry) => entry.Type == Bar.EntryType.MeshOcclusion;
Example #10
0
 private static bool IsMapModel(Bar.Entry entry) => entry.Type == Bar.EntryType.Model && entry.Name == "MAP";
Example #11
0
 private static string GetSuggestedFileName(Bar.Entry item) =>
 $"{item.Name}_{item.Index}.{Helpers.GetSuggestedExtension(item.Type)}";
Example #12
0
 private static bool IsDoct(Bar.Entry entry) => entry.Type == Bar.EntryType.DrawOctalTree;
Example #13
0
        public static ToolInvokeDesc.ContentChangeInfo?OpenTool(string fileName, string temporaryFileName, Bar.Entry entry)
        {
            string name;

            switch (entry.Type)
            {
            // Disabling it, since it is veeeeeery buggy at the moment.
            //case Bar.EntryType.Bar:
            //	name = "OpenKh.Tools.BarEditor";
            //	break;
            case Bar.EntryType.Imgd:
            case Bar.EntryType.Imgz:
                name = "OpenKh.Tools.ImageViewer";
                break;

            case Bar.EntryType.Layout:
                name = "OpenKh.Tools.LayoutViewer";
                break;

            default:
                throw new NotImplementedException($"Unable to find a tool for \"{entry.Type}\" files.");
            }

            var toolModule = Plugins
                             .GetModules <IToolModule <ToolInvokeDesc> >(null, x => x.Contains(name) && Path.GetExtension(x) == ".dll")
                             .FirstOrDefault();

            if (toolModule.Item1 == null || toolModule.Item2 == null)
            {
                MessageBox.Show($"Unable to find a tool module for the tool {name}.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            var tool = Activator.CreateInstance(toolModule.Item2) as IToolModule <ToolInvokeDesc>;

            entry.Stream.Position = 0;
            var toolInvokeDesc = new ToolInvokeDesc
            {
                Title          = $"{entry.Name}@{Path.GetFileName(fileName)}",
                ActualFileName = temporaryFileName,
                SelectedEntry  = entry,
                ContentChange  = ToolInvokeDesc.ContentChangeInfo.None
            };

            tool?.ShowDialog(toolInvokeDesc);

            return(toolInvokeDesc.ContentChange);
        }
Example #14
0
        protected int OnExecute(CommandLineApplication app)
        {
            FramePerSecond = Math.Max(1, FramePerSecond);

            if (Timeline == null || Timeline?.Length == 0)
            {
                Timeline = new string[] { $"Linear,{FrameLoop},0,0,0", $"Linear,{FrameEnd},100,0,0" };
            }

            var mdlxFile = MdlxMaker.CreateMdlxHaving2Bones(tx: MatrixValue);

            var motion       = Motion.CreateInterpolatedFromScratch();
            var interpolated = motion.Interpolated;

            interpolated.ModelBoneAnimation.Add(
                new BoneAnimationTable
            {
                JointIndex         = 1,
                Channel            = (byte)(6 | ((3 & Pre) << 4) | ((3 & Post) << 6)),
                TimelineStartIndex = 0,
                TimelineCount      = Convert.ToByte(Timeline.Length),
            }
                );
            interpolated.BoneCount      = 2;
            interpolated.FrameCount     = FrameCount;
            interpolated.FrameEnd       = FrameEnd;
            interpolated.FrameLoop      = FrameLoop;
            interpolated.FramePerSecond = FramePerSecond;
            interpolated.StaticPose.Add(
                new Motion.StaticPoseTable
            {
                BoneIndex = 1,
                Channel   = 6,
                Value     = InitialValue,
            }
                );
            interpolated.Joints.Add(new JointTable {
                JointIndex = 0,
            });
            interpolated.Joints.Add(new JointTable {
                JointIndex = 1,
            });
            interpolated.TotalFrameCount = TotalFrameCount;
            interpolated.Footer.Unknown  = new int[9];

            var converter = new TimelineTableConverter();

            interpolated.Timeline.AddRange(
                (Timeline ?? new string[0])
                .Select(text => converter.ConvertFromInvariantString(text))
                .Cast <TimelineTable>()
                );

            var motionBin = new MemoryStream();

            Motion.Write(motionBin, motion);

            motionBin.Position = 0;

            var anbFile = new MemoryStream();

            var anbBarEntries = new Bar.Entry[]
            {
                new Bar.Entry
                {
                    Type   = Bar.EntryType.Motion,
                    Stream = motionBin,
                    Name   = "A000",
                },
            };

            Bar.Write(
                anbFile,
                anbBarEntries
                );

            anbFile.Position = 0;

            var msetFile = new MemoryStream();

            Bar.Write(
                msetFile,
                new Bar.Entry[]
            {
                new Bar.Entry
                {
                    Type   = Bar.EntryType.Anb,
                    Stream = anbFile,
                    Name   = "A000",
                },
            }
                );

            msetFile.Position = 0;

            if (!string.IsNullOrEmpty(OutputMset))
            {
                File.WriteAllBytes(OutputMset, msetFile.ToArray());
            }

            motionBin.Position = 0;

            var animReader = new AnimReader(motionBin);

            mdlxFile.Position = 0;

            var outFiles = new Dictionary <string, object>();

            {
                var dat     = new StringWriter();
                var gnuplot = new StringWriter();
                gnuplot.WriteLine($"set terminal png");
                gnuplot.WriteLine($"set title '{Prefix}'");
                gnuplot.WriteLine($"set output '{Prefix}.png'");
                gnuplot.WriteLine($"plot '{Prefix}.dat' index 0 title 'out' with lines, \\");
                gnuplot.WriteLine($"     '' index 1 title 'in' with points");

                outFiles[$"{Prefix}.dat"] = dat;
                outFiles[$"{Prefix}.txt"] = gnuplot;

                var provider = (IAnimMatricesProvider) new EmuBasedAnimMatricesProvider(animReader, mdlxFile, motionBin);

                dat.WriteLine("# X Y");

                foreach (var x in Enumerable.Range(0, (int)((FrameEnd - FrameLoop + 1) * FramePerSecond)))
                {
                    var matrices = provider.ProvideMatrices((x == 0) ? 0 : 1);

                    var xVal = FrameLoop + (x / FramePerSecond);
                    var yVal = matrices[1].M41;

                    dat.WriteLine($"{xVal} {yVal}");
                }

                dat.WriteLine();
                dat.WriteLine();

                dat.WriteLine("# X Y");

                interpolated.Timeline
                .ForEach(
                    indir =>
                {
                    dat.WriteLine($"{indir.KeyFrame} {indir.Value}");
                }
                    );
            }

            if (!string.IsNullOrEmpty(Prefix))
            {
                outFiles.ForEach(
                    pair => File.WriteAllText(
                        pair.Key,
                        "" + pair.Value,
                        new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)
                        )
                    );

                Console.WriteLine($"Run: gnuplot {Prefix}.txt");
            }

            return(0);
        }
 public ImagesSelectionEntryModel(Bar.Entry entry)
 {
     _entry = entry;
 }
 public LayoutSelectionEntryModel(Bar.Entry entry)
 {
     _entry = entry;
 }