Exemple #1
0
            /// <inheritdoc />
            public long GetHashCode64(ref AlertsSubscriptionKey k)
            {
                var value = $"{k.ChatId}-{k.Channel}";
                var hash  = MurMur3.Hash(value);

                return(BitConverter.ToInt64(hash));
            }
Exemple #2
0
        /// <summary>
        /// Exports Material Images
        /// </summary>
        private void ExportMaterialImages(Model.Material material, string folder)
        {
            var imageKeys = material.Images.Keys.ToArray();

            foreach (var key in imageKeys)
            {
                // Resolve, we try the streaming folder first, as they contain the highest quality images
                // vs the lowest ones loaded in memory
                foreach (var prefix in DirectoryPrefixes)
                {
                    var fullPath = prefix + material.Images[key];

                    foreach (var suffix in FileSuffixes)
                    {
                        if (ActivePackage.Entries.TryGetValue(MurMur3.Calculate(Encoding.Unicode.GetBytes(fullPath + suffix)), out var imageFile))
                        {
                            try
                            {
                                var imagePath = ExportImage(imageFile, Path.Combine(folder, "_images", Path.GetFileNameWithoutExtension(fullPath)));
                                Directory.CreateDirectory(Path.GetDirectoryName(imagePath));
                                material.Images[key] = Path.Combine("_images", Path.GetFileName(imagePath));
                                break;
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                }
            }
        }
        public MetadataHeader(DependencyReader reader)
        {
            reader.RegisterInstance(this);

            Header               = reader.ReadObject <TagHeader>();
            Dependencies         = reader.ReadEnumerable <TagDependency>(Header.DependencyCount).ToList();
            DataBlocks           = reader.ReadEnumerable <DataBlock>(Header.DataBlockCount).ToList();
            StructureDefinitions = reader.ReadEnumerable <TagStructureDefinition>(Header.TagStructureCount).ToList();
            DataReferences       = reader.ReadEnumerable <DataBlockReference>(Header.DataReferenceCount).ToList();
            TagReferences        = reader.ReadEnumerable <TagBlockReference>(Header.TagReferenceCount).ToList();
            StringIds            = reader.ReadEnumerable <StringId>(Header.StringIdCount).ToList();

            stringTable     = new List <string>(StringIds.Count);
            stringsByOffset = new Dictionary <int, int>(StringIds.Count);
            stringsByHash   = new Dictionary <uint, int>(StringIds.Count);

            var startPos = reader.BaseStream.Position;

            while (reader.BaseStream.Position < startPos + Header.StringTableSize)
            {
                var relative     = reader.BaseStream.Position - startPos;
                var currentValue = reader.ReadNullTerminatedString();
                stringsByOffset.Add((int)relative, stringTable.Count);

                var hash = MurMur3.Hash32(currentValue);
                if (!stringsByHash.ContainsKey(hash))
                {
                    stringsByHash.Add(hash, stringTable.Count);
                }

                stringTable.Add(currentValue);
            }
        }
Exemple #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);
                        }
                    }
                }
            }
        }