예제 #1
0
        /// <summary>
        /// Exports the given asset
        /// </summary>
        /// <param name="asset"></param>
        private void ExportAsset(Asset asset)
        {
            try
            {
                Log(string.Format("Exporting {0}", Path.GetFileNameWithoutExtension(asset.Name)), "INFO");

                switch (asset.Type)
                {
                case "Mesh":
                    ExportModel(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
                    break;

                case "Texture":
                    ExportImage(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
                    break;

                case "MotionList":
                    ExportMotionList(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
                    break;

                default:
                    ExportUnknownFile(asset.PackageEntry, Path.Combine("exported_files", asset.Name));
                    break;
                }

                Log(string.Format("Exported {0}", Path.GetFileNameWithoutExtension(asset.Name)), "INFO");
            }
            catch (Exception e)
            {
#if DEBUG
                File.WriteAllBytes("BAD_BUFFER.dat", ActivePackage.LoadEntry(asset.PackageEntry));
#endif
                Log(string.Format("Error has occured while exporting {0}: {1}", Path.GetFileNameWithoutExtension(asset.Name), e), "ERROR");
            }
        }
예제 #2
0
        /// <summary>
        /// Exports a Motion List Asset
        /// </summary>
        private string ExportMotionList(Package.Entry entry, string name)
        {
            var scale   = float.TryParse(Settings["ModelScale", "1.0"], out var val) ? val : 1.0f;
            var motions = MotionList.Convert(ActivePackage.LoadEntry(entry));

            var path   = name.Split('.')[0];
            var folder = Path.Combine(path, motions.Item1);

            var result = path;

            Directory.CreateDirectory(folder);

            foreach (var motion in motions.Item2)
            {
                var motionPath = Path.Combine(folder, motion.Item1);

                if (Settings["ExportSEAnim", "Yes"] == "Yes")
                {
                    motion.Item2.Scale(scale);
                    motion.Item2.ToSEAnim(motionPath + ".seanim");
                }
            }

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Exports the Image Asset
        /// </summary>
        private string ExportImage(Package.Entry entry, string name)
        {
            var path   = name.Split('.')[0];
            var result = path + ".png";

            bool requiresExport = false;

            // Determine if we should even bother loading
            foreach (var format in ImageFormats)
            {
                // PNG is default
                if (Settings["Export" + format.ToUpper(), format == "png" ? "Yes" : "No"] == "Yes")
                {
                    // Set our path to the last exported type
                    result = path + "." + format;

                    if (!File.Exists(path + "." + format))
                    {
                        requiresExport = true;
                    }
                }
            }

            if (requiresExport)
            {
                using (var image = Texture.Convert(ActivePackage.LoadEntry(entry)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));

                    foreach (var format in ImageFormats)
                    {
                        if (Settings["Export" + format.ToUpper(), format == "png" ? "Yes" : "No"] == "Yes" && !File.Exists(path + "." + format))
                        {
                            // Everything besides DDS we need to decompress & convert
                            if (format != "dds")
                            {
                                image.ConvertImage(ScratchImage.DXGIFormat.R8G8B8A8UNORM);
                            }

                            image.Save(path + "." + format);
                        }
                    }
                }
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Exports a Model Asset
        /// </summary>
        private void ExportModel(Package.Entry entry, string name)
        {
            var scale  = float.TryParse(Settings["ModelScale", "1.0"], out var val) ? val : 1.0f;
            var models = Mesh.Convert(ActivePackage.LoadEntry(entry));

            var path = name.Split('.')[0];

            var materials = new Dictionary <string, Model.Material>();

            // Attempt to load the materials file
            foreach (var prefix in FileSuffixes)
            {
                if (ActivePackage.Entries.TryGetValue(MurMur3.Calculate(Encoding.Unicode.GetBytes(path.Replace("exported_files\\", "") + prefix)), out var result))
                {
                    try
                    {
                        materials = MaterialDefs.Convert(ActivePackage.LoadEntry(result), prefix.Split('.').Last());
                        break;
                    }
                    catch
                    {
                        continue;
                    }
                }
            }


            var folder = Path.GetDirectoryName(path);

            Directory.CreateDirectory(folder);

            for (int mdl = 0; mdl < models.Count; mdl++)
            {
                for (int lod = 0; lod < models[mdl].Count; lod++)
                {
                    // Must generate for formats that need it
                    models[mdl][lod].GenerateGlobalBoneData();
                    models[mdl][lod].Scale(scale);

                    foreach (var material in models[mdl][lod].Materials)
                    {
                        if (materials.TryGetValue(material.Name, out var fileMtl))
                        {
                            material.Images   = fileMtl.Images;
                            material.Settings = fileMtl.Settings;

                            // Determine image keys as they change depending on shader/type
                            if (material.Images.ContainsKey("BaseMetalMap"))
                            {
                                material.DiffuseMapName = "BaseMetalMap";
                            }
                            else if (material.Images.ContainsKey("BaseMap"))
                            {
                                material.DiffuseMapName = "BaseMap";
                            }

                            if (material.Images.ContainsKey("NormalRoughnessMap"))
                            {
                                material.NormalMapName = "NormalRoughnessMap";
                            }
                            else if (material.Images.ContainsKey("NormalMap"))
                            {
                                material.NormalMapName = "NormalMap";
                            }
                        }
                    }

                    foreach (var material in models[mdl][lod].Materials)
                    {
                        if (Settings["ExportMaterialInfo", "Yes"] == "Yes")
                        {
                            ExportMaterialInfo(material, Path.Combine(folder, material.Name + ".txt"));
                        }

                        if (Settings["ExportImagesWithModel", "Yes"] == "Yes")
                        {
                            ExportMaterialImages(material, folder);
                        }
                    }

                    var result = Path.Combine(folder, string.Format("{0}_model{1}_lod{2}", Path.GetFileNameWithoutExtension(path), mdl, lod));

                    foreach (var format in ModelFormats)
                    {
                        // PNG is default
                        if (Settings["Export" + format.ToUpper(), format == "semodel" ? "Yes" : "No"] == "Yes")
                        {
                            models[mdl][lod].Save(result + "." + format);
                        }
                    }
                }
            }
        }
예제 #5
0
        private void ExportUnknownFile(Package.Entry entry, string name)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(name));

            File.WriteAllBytes(name, ActivePackage.LoadEntry(entry));
        }