예제 #1
0
        public void TryToLoadTexturesFromBinder(string path)
        {
            List <string> textures = MainMesh.GetAllTexNamesToLoad();

            TexturePool.AddSpecificTexturesFromBinder(path, textures);
        }
예제 #2
0
        public Model(IProgress <double> loadingProgress, string name, IBinder chrbnd, int modelIndex,
                     IBinder anibnd, IBinder texbnd = null, List <string> additionalTpfNames = null,
                     string possibleLooseTpfFolder  = null, int baseDmyPolyID         = 0,
                     bool ignoreStaticTransforms    = false, IBinder additionalTexbnd = null)
            : this()
        {
            Name = name;
            List <BinderFile> flverFileEntries = new List <BinderFile>();

            List <TPF> tpfsUsed = new List <TPF>();

            if (additionalTpfNames != null)
            {
                foreach (var t in additionalTpfNames)
                {
                    if (File.Exists(t))
                    {
                        tpfsUsed.Add(TPF.Read(t));
                    }
                }
            }

            FLVER2 flver = null;

            foreach (var f in chrbnd.Files)
            {
                var nameCheck = f.Name.ToLower();
                if (flver == null && (nameCheck.EndsWith(".flver") || FLVER2.Is(f.Bytes)))
                {
                    if (nameCheck.EndsWith($"_{modelIndex}.flver") || modelIndex == 0)
                    {
                        flver = FLVER2.Read(f.Bytes);
                    }
                }
                else if (nameCheck.EndsWith(".tpf") || TPF.Is(f.Bytes))
                {
                    tpfsUsed.Add(TPF.Read(f.Bytes));
                }
                else if (anibnd == null && nameCheck.EndsWith(".anibnd"))
                {
                    if (nameCheck.EndsWith($"_{modelIndex}.anibnd") || modelIndex == 0)
                    {
                        if (BND3.Is(f.Bytes))
                        {
                            anibnd = BND3.Read(f.Bytes);
                        }
                        else
                        {
                            anibnd = BND4.Read(f.Bytes);
                        }
                    }
                }
            }

            if (flver == null)
            {
                throw new ArgumentException("No FLVERs found within CHRBND.");
            }

            LoadFLVER2(flver, useSecondUV: false, baseDmyPolyID, ignoreStaticTransforms);

            loadingProgress.Report(1.0 / 4.0);

            AnimContainer = new NewAnimationContainer(this);

            if (anibnd != null)
            {
                LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_ANIBND", $"Loading ANIBND for {Name}...", innerProg =>
                {
                    AnimContainer.LoadBaseANIBND(anibnd, innerProg);
                });
            }
            else
            {
                // This just messes up the model cuz they're already in
                // reference pose, whoops
                //Skeleton.ApplyBakedFlverReferencePose();
            }

            loadingProgress.Report(2.0 / 3.0);

            if (tpfsUsed.Count > 0)
            {
                LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_TPFs", $"Loading TPFs for {Name}...", innerProg =>
                {
                    for (int i = 0; i < tpfsUsed.Count; i++)
                    {
                        TexturePool.AddTpf(tpfsUsed[i]);
                        MainMesh.TextureReloadQueued = true;
                        innerProg.Report(1.0 * i / tpfsUsed.Count);
                    }
                    MainMesh.TextureReloadQueued = true;
                });
            }

            loadingProgress.Report(3.0 / 4.0);

            if (texbnd != null)
            {
                LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_TEXBND", $"Loading TEXBND for {Name}...", innerProg =>
                {
                    TexturePool.AddTextureBnd(texbnd, innerProg);
                    MainMesh.TextureReloadQueued = true;
                });
            }

            loadingProgress.Report(3.5 / 4.0);

            if (additionalTexbnd != null)
            {
                LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_AdditionalTEXBND",
                                                        $"Loading extra TEXBND for {Name}...", innerProg =>
                {
                    TexturePool.AddTextureBnd(additionalTexbnd, innerProg);
                    MainMesh.TextureReloadQueued = true;
                });
            }

            loadingProgress.Report(3.9 / 4.0);
            if (possibleLooseTpfFolder != null && Directory.Exists(possibleLooseTpfFolder))
            {
                TexturePool.AddTPFFolder(possibleLooseTpfFolder);
                MainMesh.TextureReloadQueued = true;
            }

            MainMesh.TextureReloadQueued = true;

            loadingProgress.Report(1.0);
        }