Exemple #1
0
        public static Matl LibraryToMATL(MaterialLibrary library)
        {
            Matl matl = new Matl
            {
                Entries = new MatlEntry[library.material.Length]
            };

            for (int i = 0; i < library.material.Length; i++)
            {
                MatlEntry entry = new MatlEntry
                {
                    MaterialLabel = library.material[i].label,
                    MaterialName  = library.material[i].name,
                    Attributes    = new MatlAttribute[library.material[i].param.Length]
                };

                for (int j = 0; j < library.material[i].param.Length; j++)
                {
                    entry.Attributes[j] = new MatlAttribute
                    {
                        ParamId = library.material[i].param[j].name,

                        DataObject = library.material[i].param[j].value
                    };
                }

                matl.Entries[i] = entry;
            }

            return(matl);
        }
Exemple #2
0
        public static MaterialLibrary MATLtoLibrary(Matl matlFile)
        {
            MaterialLibrary library = new MaterialLibrary
            {
                material = new Material[matlFile.Entries.Length]
            };

            int entryIndex = 0;

            foreach (var entry in matlFile.Entries)
            {
                Material mat = new Material();
                mat.name  = entry.MaterialName;
                mat.label = entry.MaterialLabel;

                mat.param = new MatlXmlAttribute[entry.Attributes.Length];

                int attribIndex = 0;
                foreach (var attr in entry.Attributes)
                {
                    MatlXmlAttribute attrib = new MatlXmlAttribute();
                    attrib.name              = attr.ParamId;
                    attrib.value             = attr.DataObject;
                    mat.param[attribIndex++] = attrib;
                }

                library.material[entryIndex] = mat;
                entryIndex++;
            }

            return(library);
        }
Exemple #3
0
        private static void SerializeMatl(string inputPath, string outputPath, XmlSerializer serializer)
        {
            if (outputPath == null)
            {
                outputPath = GetFullPathWithoutExtension(inputPath) + "_out.xml";
            }

            Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}...");
            if (Ssbh.TryParseSsbhFile(inputPath, out SsbhFile file))
            {
                Matl matlFile = (Matl)file;

                MaterialLibrary library = MATLtoLibrary(matlFile);

                using (TextWriter writer = new StringWriter())
                {
                    serializer.Serialize(writer, library);
                    string serial = writer.ToString();
                    File.WriteAllText(outputPath, serial);
                }
            }
            else
            {
                Console.WriteLine("Error reading matl file");
            }
        }
Exemple #4
0
        private static void SerializeMatl(string inputPath, string outputPath, XmlSerializer serializer)
        {
            Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {outputPath}_out.xml...");
            if (SSBH.TryParseSSBHFile(inputPath, out ISSBH_File file))
            {
                MATL matlFile = (MATL)file;

                MaterialLibrary library = MATLtoLibrary(matlFile);

                using (TextWriter writer = new StringWriter())
                {
                    serializer.Serialize(writer, library);
                    string serial = writer.ToString();
                    File.WriteAllText(outputPath + "_out.xml", serial);
                }
            }
            else
            {
                Console.WriteLine("Error reading matl file");
            }
        }