Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="FileName"></param>
        public override void ExportSceneToFile(string FileName)
        {
            if (Model == null)
            {
                return;
            }

            string name       = Path.GetDirectoryName(FileName) + "/" + Path.GetFileNameWithoutExtension(FileName);
            string simpleName = Path.GetFileNameWithoutExtension(FileName);

            SBConsole.WriteLine("Creating MODL...");
            var modl = MODL_Loader.CreateMODLFile((SBUltimateModel)Model);

            modl.ModelFileName     = simpleName;
            modl.SkeletonFileName  = $"{simpleName}.nusktb";
            modl.MeshString        = $"{simpleName}.numshb";
            modl.UnknownFileName   = "";
            modl.MaterialFileNames = new MODL_MaterialName[] { new MODL_MaterialName()
                                                               {
                                                                   MaterialFileName = $"{simpleName}.numatb"
                                                               } };
            SBConsole.WriteLine("Done");
            SSBH.TrySaveSSBHFile(FileName, modl);

            SBConsole.WriteLine($"Creating MESH... {name}.numshb");
            var mesh = MESH_Loader.CreateMESH((SBUltimateModel)Model, (SBSkeleton)Skeleton);

            SBConsole.WriteLine("Done");
            SSBH.TrySaveSSBHFile(name + ".numshb", mesh);

            SBConsole.WriteLine($"Creating SKEL.. {name}.nusktb");
            SKEL_Loader.Save(name + ".nusktb", this);
            SBConsole.WriteLine("Done");

            //SBConsole.WriteLine("Creating MATL...");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the scene from a NUMDLB file
        /// </summary>
        /// <param name="FileName"></param>
        public override void LoadFromFile(string FileName)
        {
            string folderPath = Path.GetDirectoryName(FileName);

            ISSBH_File File;

            if (!SSBH.TryParseSSBHFile(FileName, out File))
            {
                return;
            }

            MODL modl = (MODL)File;

            string meshPath = "";
            string skelPath = "";
            string matlPath = "";

            foreach (string file in Directory.EnumerateFiles(folderPath))
            {
                // load textures
                if (file.EndsWith(".nutexb"))
                {
                    NUTEX_Loader.Open(file, this);
                }

                string fileName = Path.GetFileName(file);
                if (fileName.Equals(modl.SkeletonFileName))
                {
                    skelPath = file;
                }
                if (fileName.Equals(modl.MeshString))
                {
                    meshPath = file;
                }
                if (fileName.Equals(modl.MaterialFileNames[0].MaterialFileName))
                {
                    matlPath = file;
                }
            }
            // import order Skeleton+Textures->Materials->Mesh
            // mesh needs to be loaded after skeleton
            if (skelPath != "")
            {
                SBConsole.WriteLine($"Importing skeleton: {Path.GetFileName(skelPath)}");
                SKEL_Loader.Open(skelPath, this);
            }
            if (matlPath != "")
            {
                SBConsole.WriteLine($"Importing materials: {Path.GetFileName(matlPath)}");
                MATL_Loader.Open(matlPath, this);
            }
            if (meshPath != "")
            {
                SBConsole.WriteLine($"Importing mesh: {Path.GetFileName(meshPath)}");
                MESH_Loader.Open(meshPath, this);

                // set materials
                foreach (var entry in modl.ModelEntries)
                {
                    UltimateMaterial currentMaterial = null;
                    foreach (UltimateMaterial matentry in Materials)
                    {
                        if (matentry.Label.Equals(entry.MaterialName))
                        {
                            currentMaterial = matentry;
                            break;
                        }
                    }
                    if (currentMaterial == null)
                    {
                        continue;
                    }

                    int    subindex = 0;
                    string prevMesh = "";
                    if (Model != null)
                    {
                        foreach (var mesh in Model.Meshes)
                        {
                            if (prevMesh.Equals(mesh.Name))
                            {
                                subindex++;
                            }
                            else
                            {
                                subindex = 0;
                            }
                            prevMesh = mesh.Name;
                            if (subindex == entry.SubIndex && mesh.Name.Equals(entry.MeshName))
                            {
                                mesh.Material = currentMaterial;
                                break;
                            }
                        }
                    }
                }
            }
        }