protected override void _Read(BinaryReader reader) { uint identifier = reader.ReadUInt32(); reader.BaseStream.Seek(-4, SeekOrigin.Current); if (!TEXN.IsValid(identifier)) { return; } while (reader.BaseStream.CanRead) { if (reader.BaseStream.Position >= reader.BaseStream.Length - 16) { break; } uint token = reader.ReadUInt32(); if (token == 0) { continue; } reader.BaseStream.Seek(-4, SeekOrigin.Current); TEXN texture = new TEXN(reader); if (TextureDatabase.Automatic) { TextureDatabase.AddTexture(texture); } Textures.Add(texture); } }
public static void RenameTextures(TextureSet textures, TextureDatabase textureDatabase = null) { foreach (var texture in textures.Textures) { RenameTexture(texture, textures, textureDatabase); } }
protected override void OnReplace(object oldData) { TextureSet oldDataT = ( TextureSet )oldData; // Pass the format/endianness Data.Format = oldDataT.Format; Data.Endianness = oldDataT.Endianness; // Pass new texture database to the node we adopted if (TextureDatabaseNode != null) { var textureDatabase = new TextureDatabase(); textureDatabase.Textures.Capacity = Data.Textures.Count; foreach (var texture in Data.Textures) { textureDatabase.Textures.Add(new TextureEntry { Name = texture.Name, ID = texture.ID, }); } TextureDatabaseNode.Replace(textureDatabase); } base.OnReplace(oldData); }
public void Load(string filePath, ObjectDatabase objectDatabase, TextureDatabase textureDatabase) { string textureSetFilePath = string.Empty; var objectEntry = objectDatabase?.GetObjectByFileName(Path.GetFileName(filePath)); if (objectEntry != null) { textureSetFilePath = Path.Combine(Path.GetDirectoryName(filePath), objectEntry.TextureFileName); } if (string.IsNullOrEmpty(textureSetFilePath) || !File.Exists(textureSetFilePath)) { if (filePath.EndsWith("_obj.bin", StringComparison.OrdinalIgnoreCase)) { textureSetFilePath = $"{filePath.Substring( 0, filePath.Length - 8 )}_tex.bin"; } else if (filePath.EndsWith(".osd", StringComparison.OrdinalIgnoreCase)) { textureSetFilePath = Path.ChangeExtension(filePath, "txd"); } } TextureSet textureSet = null; if (File.Exists(textureSetFilePath)) { textureSet = Load <TextureSet>(textureSetFilePath); } using (var source = File.OpenRead(filePath)) Load(source, textureSet, textureDatabase); }
public void Save(string filePath, ObjectDatabase objectDatabase, TextureDatabase textureDatabase, BoneDatabase boneDatabase) { // Assume it's being exported for F2nd PS3 if (BinaryFormatUtilities.IsClassic(Format) && filePath.EndsWith(".osd", StringComparison.OrdinalIgnoreCase)) { Format = BinaryFormat.F2nd; Endianness = Endianness.BigEndian; } // Or reverse else if (BinaryFormatUtilities.IsModern(Format) && filePath.EndsWith(".bin", StringComparison.OrdinalIgnoreCase)) { Format = BinaryFormat.DT; Endianness = Endianness.LittleEndian; } string fileName = Path.GetFileName(filePath); bool exported = false; if (objectDatabase != null && TextureSet != null) { var objectEntry = objectDatabase.GetObjectByFileName(fileName); if (objectEntry != null) { string textureOutputPath = Path.Combine(Path.GetDirectoryName(filePath), objectEntry.TextureFileName); TextureSet.Save(textureOutputPath); exported = true; } } if (!exported && TextureSet != null) { string textureOutputPath = string.Empty; // Try to assume a texture output name if (filePath.EndsWith("_obj.bin", StringComparison.OrdinalIgnoreCase)) { textureOutputPath = $"{filePath.Substring( 0, filePath.Length - 8 )}_tex.bin"; } else if (filePath.EndsWith(".osd", StringComparison.OrdinalIgnoreCase)) { textureOutputPath = Path.ChangeExtension(filePath, "txd"); } if (!string.IsNullOrEmpty(textureOutputPath)) { TextureSet.Save(textureOutputPath); } } using (var destination = File.Create(filePath)) Save(destination, objectDatabase, textureDatabase, boneDatabase); }
private void addTextureToDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { VistaFolderBrowserDialog folderDialog = new VistaFolderBrowserDialog(); if (folderDialog.ShowDialog() == DialogResult.OK) { TextureDatabase.SearchDirectory(folderDialog.SelectedPath); } }
public static void ConvertAiSceneFromObjectSet(ObjectSet objectSet, string outputFileName, TextureDatabase textureDatabase = null, bool appendTags = false) { SceneUtilities.Export(ConvertAiSceneFromObjectSet(objectSet, textureDatabase, appendTags), outputFileName); if (objectSet.TextureSet != null) { var texturesOutputDirectory = Path.GetDirectoryName(outputFileName); TextureUtilities.SaveTextures(objectSet.TextureSet, texturesOutputDirectory); } }
public static void ConvertAiSceneFromObjectSets(List <ObjectSet> objectSets, string outputFileName, TextureDatabase textureDatabase = null) { SceneUtilities.Export(ConvertAiSceneFromObjectSets(objectSets, textureDatabase), outputFileName); var texturesOutputDirectory = Path.GetDirectoryName(outputFileName); foreach (var objectSet in objectSets.Where(x => x.TextureSet != null)) { TextureUtilities.SaveTextures(objectSet.TextureSet, texturesOutputDirectory); } }
private void Start() { if (instance == null) { instance = this; } else if (instance != this) { Debug.LogError("Duplicate " + this.GetType().Name); Destroy(gameObject); } }
public static Ai.Scene ConvertAiSceneFromObjectSets(List <ObjectSet> objectSets, TextureDatabase textureDatabase = null) { var aiScene = new Ai.Scene(); aiScene.RootNode = new Ai.Node("RootNode"); foreach (var objectSet in objectSets.Where(x => x.TextureSet != null)) { TextureUtilities.RenameTextures(objectSet.TextureSet, textureDatabase); } foreach (var objectSet in objectSets) { foreach (var obj in objectSet.Objects) { ConvertAiMaterialsFromMaterials(aiScene, obj.Materials, objectSet.TextureSet); } } var bones = new List <BoneInfo>(); var boneParentMap = new Dictionary <string, string>(); foreach (var objectSet in objectSets) { foreach (var obj in objectSet.Objects.Where(x => x.Skin != null)) { foreach (var boneInfo in obj.Skin.Bones) { if (!boneParentMap.ContainsKey(boneInfo.Name)) { var parentBone = obj.Skin.Bones.FirstOrDefault(x => x.Id == boneInfo.ParentId); bones.Add(boneInfo); boneParentMap.Add(boneInfo.Name, parentBone?.Name); } } } } ConvertAiNodesFromBones(aiScene, bones, boneParentMap); foreach (var objectSet in objectSets) { ConvertAiNodesFromObjects(aiScene, objectSet.Objects); } return(aiScene); }
public static Ai.Scene ConvertAiSceneFromModels(List <Model> models, TextureDatabase textureDatabase = null) { var aiScene = new Ai.Scene(); aiScene.RootNode = new Ai.Node("RootNode"); foreach (var model in models.Where(x => x.TextureSet != null)) { TextureUtilities.RenameTextures(model.TextureSet, textureDatabase); } foreach (var model in models) { foreach (var mesh in model.Meshes) { ConvertAiMaterialsFromMaterials(aiScene, mesh.Materials, model.TextureSet); } } var bones = new List <Bone>(); var boneParentMap = new Dictionary <string, string>(); foreach (var model in models) { foreach (var mesh in model.Meshes.Where(x => x.Skin != null)) { foreach (var bone in mesh.Skin.Bones) { if (!boneParentMap.ContainsKey(bone.Name)) { var parentBone = mesh.Skin.Bones.FirstOrDefault(x => x.Id == bone.ParentId); bones.Add(bone); boneParentMap.Add(bone.Name, parentBone?.Name); } } } } ConvertAiNodesFromBones(aiScene, bones, boneParentMap); foreach (var model in models) { ConvertAiNodesFromMeshes(aiScene, model.Meshes); } return(aiScene); }
public override void Randomize(int seed) { _generator = new Random(seed); using (_textureDatabase = new TextureDatabase()) { if (NightModeOnly) { RandomizeNightModeTextures(); } else { RandomizeAllTextures(); } } }
public void Load(Stream source, TextureSet textureSet, TextureDatabase textureDatabase, bool leaveOpen = false) { Load(source, leaveOpen); if (textureSet != null && TextureIDs.Count <= textureSet.Textures.Count) { TextureSet = textureSet; for (int i = 0; i < TextureIDs.Count; i++) { TextureSet.Textures[i].ID = TextureIDs[i]; var textureEntry = textureDatabase?.GetTexture(TextureIDs[i]); if (textureEntry != null) { TextureSet.Textures[i].Name = textureEntry.Name; } } } }
protected override void SynchronizeCore() { if (mTextureDatabaseNode == null) { return; } var textureDatabase = new TextureDatabase(); foreach (var texture in Data.Textures) { textureDatabase.Textures.Add(new TextureInfo { Id = texture.Id, Name = texture.Name }); } mTextureDatabaseNode.Replace(textureDatabase); }
public models Stripify(string filePath) { var stgpv = new Model(); var textures = new MikuMikuLibrary.Textures.TextureSet(); var texdb = new TextureDatabase(); using (var farcArchive = BinaryFile.Load <FarcArchive>(filePath)) { using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txi")).First(), EntryStreamMode.MemoryStream)) texdb.Load(entryStream); using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txd")).First(), EntryStreamMode.MemoryStream)) textures.Load(entryStream); using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream)) stgpv.Load(entryStream, textures, texdb); } foreach (var meshes in stgpv.Meshes) { foreach (var submeshes in meshes.SubMeshes) { foreach (var indexTable in submeshes.IndexTables) { ushort[] triangleStrip = Stripifier.Stripify(indexTable.Indices); if (triangleStrip != null) { indexTable.PrimitiveType = PrimitiveType.TriangleStrip; indexTable.Indices = triangleStrip; } } } } var le_model = new models(); le_model.model = stgpv; le_model.fileName = filePath; Logs.WriteLine("Stripified " + Path.GetFileName(filePath)); return(le_model); }
public void Load(Stream source, TextureSet textureSet, TextureDatabase textureDatabase, bool leaveOpen = false) { Load(source, leaveOpen); if (textureSet == null || TextureIds.Count != textureSet.Textures.Count) { return; } TextureSet = textureSet; for (int i = 0; i < TextureIds.Count; i++) { TextureSet.Textures[i].Id = TextureIds[i]; var textureInfo = textureDatabase?.GetTextureInfo(TextureIds[i]); if (textureInfo != null) { TextureSet.Textures[i].Name = textureInfo.Name; } } }
public override void Save(string filePath) { // Assume it's being exported for F2nd PS3 if (BinaryFormatUtilities.IsClassic(Format) && filePath.EndsWith(".txd", StringComparison.OrdinalIgnoreCase)) { Format = BinaryFormat.F2nd; Endianness = Endianness.Big; } // Or vice versa else if (BinaryFormatUtilities.IsModern(Format) && filePath.EndsWith(".bin", StringComparison.OrdinalIgnoreCase)) { Format = BinaryFormat.DT; Endianness = Endianness.Little; } // Save a TXI if we are modern if (filePath.EndsWith(".txd", StringComparison.OrdinalIgnoreCase)) { var textureDatabase = new TextureDatabase(); foreach (var texture in Textures) { textureDatabase.Textures.Add(new TextureInfo { Id = texture.Id, Name = texture.Name ?? Guid.NewGuid().ToString() }); } textureDatabase.Format = Format; textureDatabase.Endianness = Endianness; textureDatabase.Save(Path.ChangeExtension(filePath, "txi")); } base.Save(filePath); }
public static void RenameTexture(Texture texture, TextureSet textures, TextureDatabase textureDatabase = null) { bool empty = string.IsNullOrEmpty(texture.Name); if (textureDatabase == null) { if (empty) { texture.Name = string.Format("Texture_{0}", textures.Textures.IndexOf(texture)); } } else { var info = textureDatabase.Textures.FirstOrDefault(x => x.Id == texture.Id); if (info != null) { texture.Name = info.Name; } else if (empty) { texture.Name = string.Format("Texture_{0}", textures.Textures.IndexOf(texture)); } } }
protected override void _Read(BinaryReader reader) { byte[] gzipSignature = reader.ReadBytes(2); reader.BaseStream.Seek(-2, SeekOrigin.Current); Compress = false; MemoryStream streamOut = null; if (GZ.IsValid(gzipSignature)) { streamOut = new MemoryStream(); GZipStream streamGZip = new GZipStream(reader.BaseStream, CompressionMode.Decompress); streamGZip.CopyTo(streamOut); reader = new BinaryReader(streamOut); reader.BaseStream.Seek(0, SeekOrigin.Begin); Compress = true; } //Read header Identifier = reader.ReadUInt32(); if (!IsValid(Identifier)) { throw new InvalidFileSignatureException(); } ContentSize = reader.ReadUInt32(); Unknown = reader.ReadUInt32(); FileCount = reader.ReadUInt32(); //Check for DUMY if (reader.ReadUInt32() == PKFEntry.DUMY_Entry.Token) { //Skip DUMY int dummySize = reader.ReadInt32(); reader.BaseStream.Seek(dummySize - 8, SeekOrigin.Current); } else { reader.BaseStream.Seek(-4, SeekOrigin.Current); } //Read files for (int i = 0; i < FileCount; i++) { if (reader.BaseStream.Position == reader.BaseStream.Length) { break; } //Test read token to filter out broken PKF files uint token = reader.ReadUInt32(); if (token == 0) { continue; } reader.BaseStream.Seek(-4, SeekOrigin.Current); PKFEntry entry = new PKFEntry(); entry.Read(reader); entry.Index = (uint)i; Entries.Add(entry); if (TextureDatabase.Automatic) { if (entry.TokenString.ToUpper() == "TEXN") { using (MemoryStream stream = new MemoryStream(entry.Buffer)) { TextureDatabase.AddTexture(new TEXN(stream)); } } } } reader.BaseStream.Seek(ContentSize, SeekOrigin.Begin); if (reader.BaseStream.CanRead && reader.BaseStream.Position + 8 < reader.BaseStream.Length) { try { IPAC = new IPAC(reader); } catch (Exception e) { } } if (Compress) { reader.Close(); } }
public void Save(Stream destination, ObjectDatabase objectDatabase, TextureDatabase textureDatabase, BoneDatabase boneDatabase, bool leaveOpen = false) { if (objectDatabase != null) { foreach (var mesh in Meshes) { mesh.Id = objectDatabase.GetMesh(mesh.Name)?.Id ?? mesh.Id; } } if (boneDatabase != null) { string fileName = destination is FileStream fileStream ? Path.GetFileName(fileStream.Name) : string.Empty; var skeletonEntry = boneDatabase.Skeletons.FirstOrDefault(x => fileName.StartsWith(x.Name, StringComparison.OrdinalIgnoreCase)) ?? boneDatabase.Skeletons.FirstOrDefault(x => x.Name.Equals("CMN", StringComparison.OrdinalIgnoreCase)) ?? boneDatabase.Skeletons[0]; if (skeletonEntry != null) { foreach (var skin in Meshes.Where(x => x.Skin != null).Select(x => x.Skin)) { foreach (var bone in skin.Bones) { int index = skin.ExData?.BoneNames?.FindIndex(x => x.Equals(bone.Name, StringComparison.OrdinalIgnoreCase)) ?? -1; if (index == -1) { index = skeletonEntry.BoneNames1.FindIndex(x => x.Equals(bone.Name, StringComparison.OrdinalIgnoreCase)); } else { index = 0x8000 | index; } if (index == -1) { continue; } foreach (var childBone in skin.Bones.Where(x => x.ParentId == bone.Id)) { childBone.ParentId = index; } bone.Id = index; } } } } if (textureDatabase != null && TextureSet != null) { int id = textureDatabase.Textures.Max(x => x.Id) + 1; var idDictionary = new Dictionary <int, int>(TextureSet.Textures.Count); foreach (var texture in TextureSet.Textures) { var textureEntry = !string.IsNullOrEmpty(texture.Name) ? textureDatabase.GetTexture(texture.Name) : textureDatabase.GetTexture(texture.Id); if (textureEntry == null) { textureDatabase.Textures.Add( textureEntry = new TextureEntry { Name = texture.Name, Id = id++ }); if (string.IsNullOrEmpty(textureEntry.Name)) { textureEntry.Name = $"Unnamed {textureEntry.Id}"; } } idDictionary[texture.Id] = textureEntry.Id; texture.Name = textureEntry.Name; texture.Id = textureEntry.Id; } foreach (var materialTexture in Meshes.SelectMany(x => x.Materials) .SelectMany(x => x.MaterialTextures)) { if (idDictionary.TryGetValue(materialTexture.TextureId, out id)) { materialTexture.TextureId = id; } } TextureIds.Clear(); TextureIds.AddRange(TextureSet.Textures.Select(x => x.Id)); } Save(destination, leaveOpen); }
public void Read(BinaryReader reader) { Offset = (uint)reader.BaseStream.Position; Identifier = reader.ReadUInt32(); HeaderSize = reader.ReadUInt32(); TextureCount = reader.ReadUInt32(); reader.BaseStream.Seek(Offset + HeaderSize, SeekOrigin.Begin); for (int i = 0; i < TextureCount; i++) { uint nodeOffset = (uint)reader.BaseStream.Position; uint NodeIdentifier = reader.ReadUInt32(); uint NodeSize = reader.ReadUInt32(); if (NodeIdentifier == 0x4E584554) //TEXN { Texture tex = new Texture(); tex.TextureID = new TextureID(reader); tex.Image = new PVRT(reader); Textures.Add(tex); } else if (NodeIdentifier == 0x454D414E) //NAME { for (i = 0; i < ((NodeSize - 8) / 8); i++) { Texture tex = new Texture(); tex.TextureID = new TextureID(reader); reader.BaseStream.Seek(-8, SeekOrigin.Current); UInt64 idName = reader.ReadUInt64(); if (MT5.SearchTexturesOneDirUp) { FileStream fileStream = (FileStream)reader.BaseStream; string dir = Path.GetDirectoryName(Path.GetDirectoryName(fileStream.Name)); TextureDatabase.SearchDirectory(dir); } if (MT5.UseTextureDatabase) { TEXN texture = TextureDatabase.FindTexture(idName); if (texture != null) { tex.Image = texture.Texture; Textures.Add(tex); } else { Textures.Add(tex); } } } } reader.BaseStream.Seek(nodeOffset + NodeSize, SeekOrigin.Begin); } while (reader.BaseStream.Position < reader.BaseStream.Length) { uint identifier = reader.ReadUInt32(); if (TEXL.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); TEXL = new TEXL(reader); } if (PTRL.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); PTRL = new PTRL(reader); } } }
protected override void _Read(BinaryReader reader) { Offset = (uint)reader.BaseStream.Position; Identifier = reader.ReadUInt32(); if (!IsValid(Identifier)) { return; } Size = reader.ReadUInt32(); FirstNodeOffset = reader.ReadUInt32(); TextureCount = reader.ReadUInt32(); //Read texture entries if there are any for (uint i = 0; i < TextureCount; i++) { TextureEntries.Add(new TextureEntry(reader)); } foreach (TextureEntry entry in TextureEntries) { entry.ReadTextureID(reader); } //If we are not at the first node yet, we still have an node offset table to read if (reader.BaseStream.Position != FirstNodeOffset) { NodeOffsetTableSize = reader.ReadUInt32(); for (int i = 0; i < NodeOffsetTableSize; i++) { NodeOffsetTable.Add(reader.ReadUInt32()); } } //Read first node and as an result create the whole node tree structure reader.BaseStream.Seek(Offset + FirstNodeOffset, SeekOrigin.Begin); RootNode = new MT7Node(reader, null); //Search for optional extra sections until EOF while (reader.BaseStream.Position < reader.BaseStream.Length - 4) { uint identifier = reader.ReadUInt32(); if (FACE.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); FACE = new FACE(reader); } else if (CLSG.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); CLSG = new CLSG(reader); } else if (TXT7.IsValid(identifier)) { reader.BaseStream.Seek(-4, SeekOrigin.Current); TXT7 = new TXT7(reader); } } //Filling the texture entries with the actual textures if (TXT7 != null) { foreach (TextureEntry entry in TextureEntries) { entry.Texture = TXT7.GetTexture(entry.TextureID); } } if (SearchTexturesOneDirUp) { FileStream fileStream = (FileStream)reader.BaseStream; string dir = Path.GetDirectoryName(Path.GetDirectoryName(fileStream.Name)); TextureDatabase.SearchDirectory(dir); } if (MT7.UseTextureDatabase) { foreach (TextureEntry entry in TextureEntries) { if (entry.Texture != null) { continue; } TEXN texture = TextureDatabase.FindTexture(entry.TextureID.Data); if (texture == null) { Console.WriteLine("Couldn't find texture: {0}", entry.TextureID.Name); continue; } entry.Texture = new Texture(); entry.Texture.TextureID = new TextureID(texture.TextureID); entry.Texture.Image = texture.Texture; } } //Populate base class textures foreach (TextureEntry entry in TextureEntries) { if (entry.Texture == null) { entry.Texture = new Texture(); entry.Texture.TextureID = entry.TextureID; } Textures.Add(entry.Texture); } //Resolve the textures in the faces RootNode.ResolveFaceTextures(Textures); }
public void GenerateObjSet(string filePath, Model stgpv, ObjectDatabase objdb, TextureDatabase texturedb, StageDatabase staged, string acpath, divamodgen divamods, bool doProcess = true, bool debug = false) { /* * var stgpv = new Model(); * var textures = new MikuMikuLibrary.Textures.TextureSet(); * var texdb = new TextureDatabase(); * * using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath)) * using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txi")).First(), EntryStreamMode.MemoryStream)) * texdb.Load(entryStream); * * if (debug) * { * string farcpath = acpath + "\\rom\\objset\\" + Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + ".farc"; * * using (var farcArchive = BinaryFile.Load<FarcArchive>(farcpath)) * using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("tex")).First(), EntryStreamMode.MemoryStream)) * textures.Load(entryStream); * * } * else * { * using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath)) * using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txd")).First(), EntryStreamMode.MemoryStream)) * textures.Load(entryStream); * * using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath)) * using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream)) * stgpv.Load(entryStream, textures, texdb); * } * */ if (Path.GetFileNameWithoutExtension(filePath).Contains("effpv")) { filePath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath).Replace("effpv", "stgpv") + "hrc2.farc"; } var texdb = new TextureDatabase(); //using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath)) //using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txi")).First(), EntryStreamMode.MemoryStream)) // texdb.Load(entryStream); var objentry = new ObjectEntry(); objentry.ArchiveFileName = Path.GetFileName(filePath).Replace("stgpv0", "stgpv8"); objentry.FileName = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_obj.bin"; objentry.Id = FindUnusedID(objdb); objentry.Name = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8").ToUpper(); objentry.TextureFileName = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_tex.bin"; int ground_id = -1; ushort counter = 1; foreach (var meshes in stgpv.Meshes) { meshes.SubMeshes.RemoveAll(x => x.Vertices == null || x.Vertices.Length == 0); meshes.Name = meshes.Name.Replace("STGPV0", "STGPV8"); meshes.Name = meshes.Name.Replace("EFFPV", "STGPV"); if (Path.GetFileName(filePath).Contains("hrc")) { int pvid = int.Parse(Path.GetFileName(filePath).Substring(5, 3)); if (pvid < 200) { pvid = pvid + 800; } { var check2 = divamods.Divamods.Where(c => c.pvid == pvid).FirstOrDefault(); if (check2 == null) { divamods.Divamods.Add(new pdaconversion.divamods(pvid)); Logs.WriteLine("objset: Created new PV at id " + pvid); check2 = divamods.Divamods.Where(c => c.pvid == pvid).First(); } check2.item_pv.Add(meshes.Name); Logs.WriteLine("objset: Added item_pv for PV at id " + pvid + "," + meshes.Name); } if (pvid >= 800) { var check2 = divamods.Divamods.Where(c => c.pvid == (pvid - 100)).FirstOrDefault(); if (check2 == null) { divamods.Divamods.Add(new pdaconversion.divamods(pvid - 100)); Logs.WriteLine("objset: Created new PV at id " + (pvid - 100)); check2 = divamods.Divamods.Where(c => c.pvid == (pvid - 100)).First(); } check2.item_pv.Add(meshes.Name); Logs.WriteLine("objset: Added item_pv for PV at id " + (pvid - 100) + "," + meshes.Name); } } var meshentry = new MeshEntry(); meshes.Id = counter; meshentry.Id = (ushort)meshes.Id; meshentry.Name = meshes.Name; if (meshes.Name.Contains("GND")) { ground_id = meshes.Id; } objentry.Meshes.Add(meshentry); if (doProcess) { if (!debug) { /* * foreach (var submeshes in meshes.SubMeshes) * { * foreach (var indexTable in submeshes.IndexTables) * { * ushort[] triangleStrip = Stripifier.Stripify(indexTable.Indices); * if (triangleStrip != null) * { * indexTable.PrimitiveType = PrimitiveType.TriangleStrip; * indexTable.Indices = triangleStrip; * } * } * } */ } //foreach (var textures in M) foreach (var material in meshes.Materials) { if ((Path.GetFileName(filePath).Contains("hrc2")) || (Path.GetFileName(filePath).Contains("hrc"))) { material.Shader = "ITEM"; material.IsAlphaEnabled = false; //material.Field00 = 0x00000001; //material.Field02 = 0x00000A80; //material.Diffuse.Field00 = 0x00000000; //material.Diffuse.Field01 = 0x016400E1; //material.Diffuse.Field02 = 0x000000F1; MikuMikuLibrary.Misc.Color asdf = new MikuMikuLibrary.Misc.Color(0, 0, 0, 0); material.SpecularColor = asdf; //material.AmbientColor = asdf; //material.EmissionColor = asdf; //material.SpecularColor = asdf; //material.Shininess = 1; //material.Diffuse.Field00 = 0x00000000; //material.Diffuse.Field01 = 0x002400E0; //material.Diffuse.Field02 = 0x000000F1; if (material.Ambient.TextureId == 1509989155) { material.Ambient.TextureId = -1; } if (material.Normal.TextureId == 1509989155) { material.Normal.TextureId = -1; } if (material.Specular.TextureId == 1509989155) { material.Specular.TextureId = -1; material.SpecularColor = asdf; } //else { material.Field00 = 0x0000002D; } /* * * // this blacken the screen on STAGE SHADER * material.Specular.Field01 = 0x002418C3; * material.Specular.Field02 = 0x000000F3; * material.Specular.Field05 = 1; * material.Specular.Field06 = 1; * material.Specular.Field11 = 1; * material.Specular.Field16 = 1; * material.Specular.Field21 = 1; * * * material.Specular.TextureId = -1; * material.Specular.Field01 = 0x00000000; * material.Specular.Field02 = 0x000000F0; * material.Specular.Field05 = 1; * material.Specular.Field06 = 0; * material.Specular.Field11 = 0; * material.Specular.Field16 = 0; * material.Specular.Field21 = 0; * * material.Reflection.TextureId = -1; * material.Reflection.Field01 = 0x00000000; * material.Reflection.Field02 = 0x000000F0; * material.Reflection.Field05 = 1; * material.Reflection.Field06 = 0; * material.Reflection.Field11 = 0; * material.Reflection.Field16 = 0; * material.Reflection.Field21 = 0; */ if (material.Reflection.TextureId == 1509989155) { material.Reflection.TextureId = -1; } if (material.ToonCurve.TextureId == 1509989155) { material.ToonCurve.TextureId = -1; } if (material.SpecularPower.TextureId == 1509989155) { material.SpecularPower.TextureId = -1; } if (material.Texture08.TextureId == 1509989155) { material.Texture08.TextureId = -1; } } else { material.Shader = "BLINN"; //material.Field00 = 0x0000000D; //material.Field02 = 0x00000A80; MikuMikuLibrary.Misc.Color asdf = new MikuMikuLibrary.Misc.Color(0, 0, 0, 0); //material.AmbientColor = asdf; //material.EmissionColor = asdf; //material.Shininess = 1; //material.Diffuse.Field00 = 0x00000230; //material.Diffuse.Field02 = 0x002418C3; if (material.Ambient.TextureId == 1509989155) { material.Ambient.TextureId = -1; } if (material.Normal.TextureId == 1509989155) { material.Normal.TextureId = -1; } if (material.Specular.TextureId == 1509989155) { material.Specular.TextureId = -1; material.SpecularColor = asdf; } //else { material.Field00 = 0x0000002D; } /* * * // this blacken the screen on STAGE SHADER * material.Specular.Field01 = 0x002418C3; * material.Specular.Field02 = 0x000000F3; * material.Specular.Field05 = 1; * material.Specular.Field06 = 1; * material.Specular.Field11 = 1; * material.Specular.Field16 = 1; * material.Specular.Field21 = 1; * */ /* * material.Specular.TextureId = -1; * material.Specular.Field01 = 0x00000000; * material.Specular.Field02 = 0x000000F0; * material.Specular.Field05 = 5; * material.Specular.Field06 = 0; * material.Specular.Field11 = 0; * material.Specular.Field16 = 0; * material.Specular.Field21 = 0; * * * material.Normal.Field01 = 0x00000000; * material.Normal.Field02 = 0x000000F0; * material.Normal.Field05 = 5; * material.Normal.Field06 = 0; * material.Normal.Field11 = 0; * material.Normal.Field16 = 0; * material.Normal.Field21 = 0; * * * material.ToonCurve.TextureId = -1; * material.ToonCurve.Field01 = 0x00000000; * material.ToonCurve.Field02 = 0x000000F0; * material.ToonCurve.Field05 = 5; * material.ToonCurve.Field06 = 0; * material.ToonCurve.Field11 = 0; * material.ToonCurve.Field16 = 0; * material.ToonCurve.Field21 = 0; */ if (material.Reflection.TextureId == 1509989155) { material.Reflection.TextureId = -1; } if (material.ToonCurve.TextureId == 1509989155) { material.ToonCurve.TextureId = -1; } if (material.SpecularPower.TextureId == 1509989155) { material.SpecularPower.TextureId = -1; } if (material.Texture08.TextureId == 1509989155) { material.Texture08.TextureId = -1; } } } } counter++; } stgpv.TextureSet.Format = BinaryFormat.DT; stgpv.Format = BinaryFormat.DT; if (doProcess) { stgpv.Save("temp\\" + Path.GetFileNameWithoutExtension(filePath) + "_obj.bin", null, texturedb, null); } objdb.Objects.Add(objentry); if (Path.GetFileNameWithoutExtension(filePath).Count() == 8) { StageEntry stage = new StageEntry(); stage.Id = FindUnusedID(staged); stage.Name = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8").ToUpper(); stage.ObjectGroundId = (short)ground_id; stage.ObjectGroundIdFlag = (short)objentry.Id; stage.ObjectId3 = -1; stage.ObjectIdFlag3 = -1; stage.ObjectId5 = -1; stage.ObjectIdFlag5 = -1; stage.ObjectId7 = -1; stage.ObjectIdFlag7 = -1; stage.RingRectangleX = -8; stage.RingRectangleY = -8; stage.RingRectangleWidth = 16; stage.RingRectangleHeight = 16; stage.RingRingHeight = 0; stage.RingOutHeight = -1000; stage.Field00 = 1; stage.Field11 = -1; stage.Field02 = -1; stage.LensFlareScaleX = -1; stage.LensFlareScaleY = -1; stage.LensFlareScaleZ = -1; stage.ObjectSkyId = -1; stage.ObjectSkyIdFlag = -1; stage.ObjectReflectId = -1; stage.ObjectReflectIdFlag = -1; stage.CollisionFilePath = @"rom/STGTST_COLI.000.bin"; stage.ObjectId1 = (short)objentry.Id; stage.StageEffect1 = StageEntry.StageEffect.Empty; stage.Auth3dName = "EFF" + stage.Name; staged.Stages.Add(stage); } if (doProcess) { var newfarc = new FarcArchive(); newfarc.Add(Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_obj.bin", "temp\\" + Path.GetFileNameWithoutExtension(filePath) + "_obj.bin"); newfarc.Add(Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_tex.bin", "temp\\" + Path.GetFileNameWithoutExtension(filePath) + "_tex.bin"); newfarc.Alignment = 16; newfarc.IsCompressed = false; newfarc.Save(acpath + "\\rom\\objset\\" + Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + ".farc"); } }
public static void ConvertAiSceneFromModels(List <Model> models, string outputFileName, TextureDatabase textureDatabase = null) { SceneUtilities.Export(ConvertAiSceneFromModels(models, textureDatabase), outputFileName); var texturesOutputDirectory = Path.GetDirectoryName(outputFileName); foreach (var model in models.Where(x => x.TextureSet != null)) { TextureUtilities.SaveTextures(model.TextureSet, texturesOutputDirectory); } }
static void LoadMesh(Level lvl) { int loadedPolys = 0; Stopwatch sw = new Stopwatch(); sw.Start(); int lightIndex = 0; var fts = lvl.ArxLevelNative.FTS; Dictionary <int, int> tcToIndex = new Dictionary <int, int>(); //texture indices for (int i = 0; i < fts.textureContainers.Length; i++) { tcToIndex[fts.textureContainers[i].tc] = i; } //TODO: use external placeholder texture so it can be set to 0 on export var notFoundMaterialKey = new EditorMaterial(EditorSettings.DataDir + "graph\\interface\\misc\\default[icon].bmp", PolyType.GLOW, 0); for (int c = 0; c < fts.cells.Length; c++) { var cell = fts.cells[c]; loadedPolys += cell.polygons.Length; for (int p = 0; p < cell.polygons.Length; p++) { var poly = cell.polygons[p]; var matKey = notFoundMaterialKey; if (tcToIndex.TryGetValue(poly.tex, out int textureIndex)) { string texArxPath = ArxIOHelper.GetString(fts.textureContainers[textureIndex].fic); string texPath = TextureDatabase.GetRealTexturePath(EditorSettings.DataDir + texArxPath); matKey = new EditorMaterial(texPath, poly.type, poly.transval); //TODO: speed up by using a pool of some sort? } MaterialMesh mm = lvl.EditableLevelMesh.GetMaterialMesh(matKey); EditablePrimitiveInfo prim = new EditablePrimitiveInfo { polyType = poly.type, norm = poly.norm.ToVector3(), norm2 = poly.norm2.ToVector3(), area = poly.area, room = poly.room, paddy = poly.paddy }; int vertCount = prim.VertexCount; for (int i = 0; i < vertCount; i++) { var vert = poly.vertices[i]; prim.vertices[i] = new EditableVertexInfo(new Vector3(vert.posX, vert.posY, vert.posZ), new Vector2(vert.texU, 1 - vert.texV), poly.normals[i].ToVector3(), ArxIOHelper.FromBGRA(lvl.ArxLevelNative.LLF.lightColors[lightIndex++])); } if (prim.IsTriangle) { //load 4th vertex manually as it has no lighting value and would break lighting otherwise var lastVert = poly.vertices[3]; prim.vertices[3] = new EditableVertexInfo(new Vector3(lastVert.posX, lastVert.posY, lastVert.posZ), new Vector2(lastVert.texU, 1 - lastVert.texV), poly.normals[3].ToVector3(), Color.white); } mm.AddPrimitive(prim); } } foreach (var kv in lvl.EditableLevelMesh.MaterialMeshes) { kv.Value.UpdateMesh(); } UnityEngine.Debug.Log("total load time: " + sw.Elapsed); UnityEngine.Debug.Log("Loaded polys: " + loadedPolys); }
public BaseDrawer() { _colorStack = new ColorStack(); _textureDatabase = TextureDatabaseProvider.GetDatabase(this); _contentCache = new GUIContentCache(); }
public GlobalGrouping(TextureDatabase database) { Sources = new Dictionary <StaticTextureSource, List <StaticTextureTarget> >(); Grouping = new List <TextureGrouping>(); Dictionary <string, object> globalData = JsonConvert.DeserializeObject <Dictionary <string, object> >(File.ReadAllText(@"Resources\Textures\Source\Static\global_grouping.json")); // These sources will be added to all levels automatically without having to explicitly map them. The targets // can be empty for such things as dynamic sprite sequence mapping, or filled with shared values in all levels // (not currently used). if (globalData.ContainsKey("GlobalSources")) { Dictionary <string, List <StaticTextureTarget> > sources = JsonConvert.DeserializeObject <Dictionary <string, List <StaticTextureTarget> > >(globalData["GlobalSources"].ToString()); foreach (string sourceName in sources.Keys) { Sources.Add(database.GetStaticSource(sourceName), sources[sourceName]); } } if (globalData.ContainsKey("GlobalGrouping")) { List <Dictionary <string, object> > groupListData = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(globalData["GlobalGrouping"].ToString()); foreach (IDictionary <string, object> groupData in groupListData) { TextureGrouping grouping = new TextureGrouping { Leader = database.GetStaticSource(groupData["Leader"].ToString()) }; if (groupData.ContainsKey("Masters")) { // Masters can be defined and if they are present in a source list, the leader will be ignored SortedSet <string> masters = JsonConvert.DeserializeObject <SortedSet <string> >(groupData["Masters"].ToString()); foreach (string sourceName in masters) { grouping.Masters.Add(database.GetStaticSource(sourceName)); } } SortedSet <string> followers = JsonConvert.DeserializeObject <SortedSet <string> >(groupData["Followers"].ToString()); foreach (string sourceName in followers) { grouping.Followers.Add(database.GetStaticSource(sourceName)); } if (groupData.ContainsKey("ThemeAlternatives")) { Dictionary <string, Dictionary <string, string> > alternatives = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(groupData["ThemeAlternatives"].ToString()); foreach (string theme in alternatives.Keys) { Dictionary <StaticTextureSource, string> map = new Dictionary <StaticTextureSource, string>(); foreach (string sourceName in alternatives[theme].Keys) { map.Add(database.GetStaticSource(sourceName), alternatives[theme][sourceName]); } grouping.ThemeAlternatives.Add(theme, map); } } Grouping.Add(grouping); } } }
public void Convert(string path, string objdbpath, string texdbpath, string stagedbpath, string a3ddbpath, string mot_db, string acpath) { maxWorker = Environment.ProcessorCount; Console.Title = "LYB DIVA X2A"; Console.WriteLine("lyb's Diva X to A Conversion Utility"); Console.WriteLine("Credit : Skyth (MikuMikuLibrary), KorenKonder (KKtLib)," + " Raki Saionji (DivaScriptConv), Samyuu (DivaScript, ScriptUtilities)"); Console.WriteLine(""); divapvmod divapvmods = new divapvmod(); divapvmods.RestoreDb(true); if (Directory.Exists("a3d")) { Directory.Delete("a3d", true); } if (Directory.Exists("farc")) { Directory.Delete("farc", true); } if (Directory.Exists("temp")) { Directory.Delete("temp", true); } if (Directory.Exists("dsc")) { Directory.Delete("dsc", true); } if (Directory.Exists("mot")) { Directory.Delete("mot", true); } Directory.CreateDirectory("temp"); Directory.CreateDirectory("farc"); Directory.CreateDirectory("dsc"); Directory.CreateDirectory("farc"); if (!Directory.Exists(acpath + "\\divamods")) { Directory.CreateDirectory(acpath + "\\divamods"); } objdb.Load(objdbpath); staged.Load(stagedbpath); auth3d_db.load(a3ddbpath); new Thread(() => { Thread.CurrentThread.IsBackground = true; auth3d.ExtractA3D(path, acpath, auth3d_db); Interlocked.Decrement(ref currentWorker); }).Start(); Interlocked.Increment(ref currentWorker); foreach (string file in Directory.EnumerateFiles(path, "stgpv*.farc", SearchOption.TopDirectoryOnly)) { while (currentWorker > maxWorker) { Thread.Sleep(33); } new Thread(() => { Thread.CurrentThread.IsBackground = true; var le_model = divax.Stripify(file); model_list.Push(le_model); Interlocked.Decrement(ref currentWorker); }).Start(); Interlocked.Increment(ref currentWorker); } foreach (string file in Directory.EnumerateFiles(path, "effpv*.farc", SearchOption.TopDirectoryOnly)) { while (currentWorker > maxWorker) { Thread.Sleep(33); } new Thread(() => { Thread.CurrentThread.IsBackground = true; var le_model = divax.Stripify(file); model_list.Push(le_model); Interlocked.Decrement(ref currentWorker); }).Start(); Interlocked.Increment(ref currentWorker); } while (currentWorker != 0) { Thread.Sleep(33); } new Thread(() => { Thread.CurrentThread.IsBackground = true; auth3d.ConvertA3D(path, acpath, auth3d_db); Interlocked.Decrement(ref currentWorker); }).Start(); Interlocked.Increment(ref currentWorker); var texturedb = new TextureDatabase(); texturedb.Load(texdbpath); while (model_list.Count > 0) { models stgpv; model_list.TryPop(out stgpv); Console.WriteLine(Path.GetFileName(stgpv.fileName)); divax.GenerateObjSet(stgpv.fileName, stgpv.model, objdb, texturedb, staged, acpath, divamods, true, false); GC.Collect(); GC.WaitForPendingFinalizers(); } texturedb.Save(acpath + @"\rom\objset\tex_db.bin"); model_list.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); /* * foreach (string file in Directory.EnumerateFiles(path, "stgpv*.farc", SearchOption.TopDirectoryOnly)) * { * Console.WriteLine(Path.GetFileName(file)); * var stgpv = model_list.Where(c => c.fileName == Path.GetFileName(path)).First(); * divax.GenerateObjSet(file, stgpv.model, objdb, texdbpath, staged, acpath, divamods, true, false); * GC.Collect(); * GC.WaitForPendingFinalizers(); * } * * foreach (string file in Directory.EnumerateFiles(path, "effpv*.farc", SearchOption.TopDirectoryOnly)) * { * Console.WriteLine(Path.GetFileName(file)); * var stgpv = model_list.Where(c => c.fileName == Path.GetFileName(path)).First(); * divax.GenerateObjSet(file, stgpv.model, objdb, texdbpath, staged, acpath, divamods, true, false); * GC.Collect(); * GC.WaitForPendingFinalizers(); * } */ objdb.Save(acpath + @"\rom\objset\obj_db.bin"); staged.Save(acpath + @"\rom\stage_data.bin"); while (currentWorker != 0) { Thread.Sleep(33); } auth3d.CreateDBEntries(acpath, auth3d_db, divamods); auth3d_db.save(acpath + @"\rom\auth_3d\auth_3d_db.bin"); motion.Convert(path, acpath, mot_db, divamods); //motion.dbgme(path, acpath, divamods); dsc.ConvertDSC(path, acpath, divamods); var csv = File.ReadAllLines("x_pv.csv"); foreach (var i in csv) { var lines = i.Split(','); divamods.SetU1P2P(lines[0], lines[1], lines[2], lines[4]); } divamods.GenerateDivamods(acpath); divapvmods.ApplyMods(acpath, true); Console.WriteLine("DONE!"); Console.BackgroundColor = ConsoleColor.DarkBlue; Console.Beep(); Console.ReadKey(); }
internal TexturePositionMonitorBroker() { _monitors = new Dictionary <string, TexturePositionMonitor>(); _textureDatabase = new TextureDatabase(); _lock = new object(); }
public void Save(Stream destination, ObjectDatabase objectDatabase, TextureDatabase textureDatabase, BoneDatabase boneDatabase, bool leaveOpen = false) { if (objectDatabase != null) { foreach (var mesh in Meshes) { mesh.ID = objectDatabase.GetMesh(mesh.Name)?.ID ?? mesh.ID; } } if (boneDatabase != null) { string fileName = (destination is FileStream fileStream) ? Path.GetFileName(fileStream.Name) : string.Empty; // Assume we are exporting in game's style var skeleton = boneDatabase.Skeletons.FirstOrDefault(x => fileName.StartsWith(x.Name, StringComparison.OrdinalIgnoreCase)); // If we couldn't find it, default to CMN skeleton if (skeleton == null) { skeleton = boneDatabase.Skeletons.FirstOrDefault(x => x.Name.Equals("CMN", StringComparison.OrdinalIgnoreCase)); } // Still?? Then default to the first skeleton (this is unlikely to happen though) if (skeleton == null) { skeleton = boneDatabase.Skeletons[0]; } // Pretty much impossible to miss if (skeleton != null) { foreach (var skin in Meshes.Where(x => x.Skin != null).Select(x => x.Skin)) { foreach (var bone in skin.Bones) { int index = skin.ExData?.BoneNames?.FindIndex(x => x.Equals(bone.Name, StringComparison.OrdinalIgnoreCase)) ?? -1; if (index == -1) { index = skeleton.BoneNames1.FindIndex(x => x.Equals(bone.Name, StringComparison.OrdinalIgnoreCase)); } else { index = 0x8000 | index; } if (index != -1) { // Before we do this, fix the child bones foreach (var childBone in skin.Bones.Where(x => x.ParentID.Equals(bone.ID))) { childBone.ParentID = index; } // Now replace the ID bone.ID = index; } else { Debug.WriteLine($"Model.Save: Bone wasn't found in bone database or ex-data: {bone.Name}"); } } } } } if (textureDatabase != null && TextureSet != null) { var newIDs = new List <int>(TextureSet.Textures.Count); int currentID = textureDatabase.Textures.Max(x => x.ID) + 1; foreach (var texture in TextureSet.Textures) { var textureEntry = !string.IsNullOrEmpty(texture.Name) ? textureDatabase.GetTexture(texture.Name) : textureDatabase.GetTexture(texture.ID); if (textureEntry == null) { textureDatabase.Textures.Add(textureEntry = new TextureEntry { ID = currentID++, Name = texture.Name ?? $"Texture{currentID}", }); } newIDs.Add(textureEntry.ID); } if (!newIDs.SequenceEqual(TextureIDs)) { TextureUtilities.ReAssignTextureIDs(this, newIDs); } } Save(destination, leaveOpen); }