private void buttonImport_Click(object sender, EventArgs e) { OpenFileDialog a = new OpenFileDialog() { Filter = ImportTextures.filter }; if (a.ShowDialog() == DialogResult.OK) { archive.UnsavedChanges = true; string i = a.FileName; if (Path.GetExtension(i).ToLower().Equals(".rwtex")) { asset.Data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 }, textureNativeList = new List <TextureNative_0015>() { new TextureNative_0015().FromBytes(File.ReadAllBytes(i)) }, textureDictionaryExtension = new Extension_0003() }, currentTextureVersion(archive.game)); } else { asset.Data = CreateRWTXFromBitmap(archive.game, archive.platform, i, false, checkBoxFlipTextures.Checked, checkBoxMipmaps.Checked, checkBoxCompress.Checked, checkBoxTransFix.Checked).data; } if (asset.game == HipHopFile.Game.Scooby) { byte[] data = asset.Data; FixTextureForScooby(ref data); asset.Data = data; } RefreshPropertyGrid(); archive.EnableTextureForDisplay(asset); } }
public Dictionary <string, Bitmap> GetTexturesAsBitmaps(string[] textureNames) { List <TextureNative_0015> textures = new List <TextureNative_0015>(); ReadFileMethods.treatStuffAsByteArray = true; foreach (string t in textureNames) { AssetRWTX RWTX; uint assetID = BKDRHash(t + ".RW3"); if (ContainsAsset(assetID)) { RWTX = (AssetRWTX)GetFromAssetID(assetID); } else { assetID = BKDRHash(t); if (ContainsAsset(assetID)) { RWTX = (AssetRWTX)GetFromAssetID(assetID); } else { continue; } } foreach (TextureNative_0015 texture in ((TextureDictionary_0016)ReadFileMethods.ReadRenderWareFile(RWTX.Data)[0]).textureNativeList) { texture.textureNativeStruct.textureName = t; textures.Add(texture); } } return(ExportTXDToBitmap(ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = (short)textures.Count, unknown = 0 }, textureNativeList = textures, textureDictionaryExtension = new Extension_0003() }, currentTextureVersion(game)))); }
public static void LoadTexturesFromTXD(string textureFile, bool reapply = true) { foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(textureFile)) { if (rw is TextureDictionary_0016 td) { foreach (TextureNative_0015 tn in td.textureNativeList) { AddTextureNative(tn.textureNativeStruct); } } } if (reapply) { ReapplyTextures(); } }
public override void OnImportAsset(AssetImportContext ctx) { int pos = ctx.assetPath.LastIndexOf("/") + 1; string LevelExtension = ctx.assetPath.Substring(pos, ctx.assetPath.Length - pos); string LevelName = LevelExtension.Substring(0, LevelExtension.IndexOf(".")); var hipFile = new HipFile(ctx.assetPath); if (!AssetDatabase.IsValidFolder("Assets/" + LevelName)) { AssetDatabase.CreateFolder("Assets", LevelName); foreach (var AHDR in hipFile.DICT.ATOC.AHDRList) { if (AHDR.assetType == AssetType.MODL) { var model = ReadFileMethods.ReadRenderWareFile(AHDR.data)[0]; } } } }
public static void ExportSingleTextureToDictionary(string fileName, byte[] data, string textureName) { ReadFileMethods.treatStuffAsByteArray = true; List <TextureNative_0015> textNativeList = new List <TextureNative_0015>(); int fileVersion = 0; foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(data)) { if (rw is TextureDictionary_0016 td) { foreach (TextureNative_0015 tn in td.textureNativeList) { fileVersion = tn.renderWareVersion; tn.textureNativeStruct.textureName = textureName; textNativeList.Add(tn); } } } TextureDictionary_0016 rws = new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = (short)textNativeList.Count(), unknown = 0 }, textureNativeList = textNativeList, textureDictionaryExtension = new Extension_0003() { extensionSectionList = new List <RWSection>() } }; rws.textureNativeList = rws.textureNativeList.OrderBy(f => f.textureNativeStruct.textureName).ToList(); File.WriteAllBytes(fileName, ReadFileMethods.ExportRenderWareFile(rws, fileVersion)); ReadFileMethods.treatStuffAsByteArray = false; }
private void buttonImport_Click(object sender, EventArgs e) { OpenFileDialog a = new OpenFileDialog() { Filter = "All supported types|*.obj;*.bsp|OBJ Files|*.obj|BSP Files|*.bsp|All files|*.*", Multiselect = true }; if (a.ShowDialog() == DialogResult.OK) { foreach (string i in a.FileNames) { ReadFileMethods.isCollision = true; RenderWareModelFile file = new RenderWareModelFile(Path.GetFileNameWithoutExtension(i) + ".BSP"); file.isShadowCollision = true; try { file.ChunkNumber = Convert.ToByte(Path.GetFileNameWithoutExtension(i).Split('_').Last()); } catch { file.ChunkNumber = -1; }; if (Path.GetExtension(i).ToLower() == ".obj") { file.SetForRendering(Program.MainForm.renderer.Device, CreateShadowCollisionBSPFile(ReadOBJFile(i, true)), null); } else { file.SetForRendering(Program.MainForm.renderer.Device, ReadFileMethods.ReadRenderWareFile(i), File.ReadAllBytes(i)); } bspRenderer.ShadowColBSPList.Add(file); listBoxLevelModels.Items.Add(file.fileName); ReadFileMethods.isCollision = false; } buttonExport.Enabled = true; } }
private void buttonImport_Click(object sender, EventArgs e) { using (OpenFileDialog a = new OpenFileDialog() { Filter = "All supported types|*.dae;*.obj;*.bsp|DAE Files|*.dae|OBJ Files|*.obj|BSP Files|*.bsp|All files|*.*", Multiselect = true }) if (a.ShowDialog() == DialogResult.OK) { progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Step = 1; progressBar1.Maximum = a.FileNames.Count(); foreach (string i in a.FileNames) { RenderWareModelFile file = new RenderWareModelFile(Path.GetFileNameWithoutExtension(i) + ".BSP"); file.SetChunkNumberAndName(); if (Path.GetExtension(i).ToLower() == ".obj") { file.SetForRendering(CreateBSPFile(i, ReadOBJFile(i, false)), null); } else if (Path.GetExtension(i).ToLower() == ".dae") { file.SetForRendering(CreateBSPFile(i, ConvertDataFromDAEObject(ReadDAEFile(i), false)), null); } else if (new string[] { ".bsp", ".rg1", ".rp2", ".rx1" }.Contains(Path.GetExtension(i).ToLower())) { file.SetForRendering(ReadFileMethods.ReadRenderWareFile(i), File.ReadAllBytes(i)); } BSPStream.Add(file); listBoxLevelModels.Items.Add(file.fileName); progressBar1.PerformStep(); } progressBar1.Value = 0; } }
public static void SetHeroesMeshStream(Archive heroesONEfile) { foreach (RenderWareModelFile r in BSPStream) { foreach (SharpMesh mesh in r.meshList) { mesh.Dispose(); } } foreach (RenderWareModelFile r in ShadowCollisionBSPStream) { foreach (SharpMesh mesh in r.meshList) { mesh.Dispose(); } } LoadTextures(currentFileNamePrefix); ReadFileMethods.isShadow = false; ShadowCollisionBSPStream = new List <RenderWareModelFile>(); BSPStream = new List <RenderWareModelFile>(heroesONEfile.Files.Count); foreach (ArchiveFile file in heroesONEfile.Files) { if (Path.GetExtension(file.Name).ToLower() != ".bsp") { continue; } RenderWareModelFile TempBSPFile = new RenderWareModelFile(file.Name); TempBSPFile.SetChunkNumberAndName(); byte[] uncompressedData = file.DecompressThis(); TempBSPFile.SetForRendering(ReadFileMethods.ReadRenderWareFile(uncompressedData), uncompressedData); BSPStream.Add(TempBSPFile); } }
private void ConvertAllAssetTypes(Platform previousPlatform, Game previousGame, out List <uint> unsupported) { unsupported = new List <uint>(); foreach (Asset asset in assetDictionary.Values) { try { if (asset is AssetRenderWareModel MODL && !MODL.IsNativeData) { MODL.Data = ReadFileMethods.ExportRenderWareFile( ReadFileMethods.ReadRenderWareFile(asset.Data), Models.BSP_IO_Shared.modelRenderWareVersion(game)); } else { asset.AHDR = ConvertAssetType(asset.AHDR, EndianConverter.PlatformEndianness(previousPlatform), EndianConverter.PlatformEndianness(platform), previousGame, game); } asset.SetGamePlatform(game, platform); }
public void SetHeroesBSPList(SharpDevice device, Archive heroesONEfile) { Dispose(); ReadFileMethods.isShadow = false; BSPList = new List <RenderWareModelFile>(heroesONEfile.Files.Count); ShadowColBSPList = new List <RenderWareModelFile>(); foreach (ArchiveFile file in heroesONEfile.Files) { if (!(new string[] { ".bsp", ".rg1", ".rx1" }.Contains(Path.GetExtension(file.Name).ToLower()))) { continue; } RenderWareModelFile TempBSPFile = new RenderWareModelFile(file.Name); TempBSPFile.SetChunkNumberAndName(); byte[] uncompressedData = file.DecompressThis(); TempBSPFile.SetForRendering(device, ReadFileMethods.ReadRenderWareFile(uncompressedData), uncompressedData); BSPList.Add(TempBSPFile); } }
public virtual void Setup(SharpRenderer renderer) { if (model != null) model.Dispose(); #if !DEBUG try { #endif ReadFileMethods.treatStuffAsByteArray = false; model = new RenderWareModelFile(renderer.device, ReadFileMethods.ReadRenderWareFile(Data)); SetupAtomicFlagsForRender(); #if !DEBUG } catch (Exception ex) { if (model != null) model.Dispose(); model = null; throw new Exception("Error: " + ToString() + " has an unsupported format and cannot be rendered. " + ex.Message); } #endif }
private void buttonImport_Click(object sender, System.EventArgs e) { OpenFileDialog a = new OpenFileDialog() { Filter = ImportTextures.filter }; if (a.ShowDialog() == DialogResult.OK) { archive.UnsavedChanges = true; string i = a.FileName; if (Path.GetExtension(i).ToLower().Equals(".rwtex")) { asset.Data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 }, textureNativeList = new List <TextureNative_0015>() { new TextureNative_0015().FromBytes(File.ReadAllBytes(i)) }, textureDictionaryExtension = new Extension_0003() }, ArchiveEditorFunctions.currentTextureVersion); } else { asset.Data = ArchiveEditorFunctions.CreateRWTXFromBitmap(i, false, false, true, true).data; } archive.EnableTextureForDisplay(asset); } }
private void buttonImport_Click(object sender, EventArgs e) { OpenFileDialog openFile = new OpenFileDialog() { Filter = GetImportFilter(), // "All supported types|*.dae;*.obj;*.bsp|DAE Files|*.dae|OBJ Files|*.obj|BSP Files|*.bsp|All files|*.*", Multiselect = true }; if (openFile.ShowDialog() == DialogResult.OK) { progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Step = 1; progressBar1.Maximum = openFile.FileNames.Count(); foreach (string i in openFile.FileNames) { RenderWareModelFile file = new RenderWareModelFile(Path.GetFileNameWithoutExtension(i) + ".BSP"); file.SetChunkNumberAndName(); try { if (new string[] { ".bsp", ".rg1", ".rp2", ".rx1" }.Contains(Path.GetExtension(i).ToLower())) { file.SetForRendering(Program.MainForm.renderer.Device, ReadFileMethods.ReadRenderWareFile(i), File.ReadAllBytes(i)); } else if (Path.GetExtension(i).ToLower() == ".obj" || Path.GetExtension(i).ToLower() == ".dae") { try { if (Path.GetExtension(i).ToLower() == ".obj") { file.SetForRendering(Program.MainForm.renderer.Device, CreateBSPFile(i, ReadOBJFile(i, false), checkBoxTristrip.Checked, checkBoxFlipUVs.Checked), null); } else { file.SetForRendering(Program.MainForm.renderer.Device, CreateBSPFile(i, ConvertDataFromDAEObject(ReadDAEFile(i), false), checkBoxTristrip.Checked, checkBoxFlipUVs.Checked), null); } } catch { file.SetForRendering(Program.MainForm.renderer.Device, CreateBSPFromAssimp(i, checkBoxFlipUVs.Checked), null); } } else { file.SetForRendering(Program.MainForm.renderer.Device, CreateBSPFromAssimp(i, checkBoxFlipUVs.Checked), null); } } catch (Exception ex) { MessageBox.Show($"Error importing {Path.GetFileName(i)} : {ex.Message}"); progressBar1.PerformStep(); continue; } bspRenderer.BSPList.Add(file); listBoxLevelModels.Items.Add(file.fileName); progressBar1.PerformStep(); } progressBar1.Value = 0; } }
public static Section_AHDR CreateRWTXFromBitmap(string fileName, bool appendRW3, bool flip, bool mipmaps, bool compress) { string textureName = Path.GetFileNameWithoutExtension(fileName); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fileName); List <byte> bitmapData = new List <byte>(bitmap.Width * bitmap.Height * 4); if (flip) { bitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY); } for (int j = 0; j < bitmap.Height; j++) { for (int i = 0; i < bitmap.Width; i++) { bitmapData.Add(bitmap.GetPixel(i, j).B); bitmapData.Add(bitmap.GetPixel(i, j).G); bitmapData.Add(bitmap.GetPixel(i, j).R); bitmapData.Add(bitmap.GetPixel(i, j).A); } } TextureDictionary_0016 td = new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 }, textureNativeList = new List <TextureNative_0015>() { new TextureNative_0015() { textureNativeStruct = new TextureNativeStruct_0001() { textureName = textureName, alphaName = "", height = (short)bitmap.Height, width = (short)bitmap.Width, mipMapCount = 1, addressModeU = TextureAddressMode.TEXTUREADDRESSWRAP, addressModeV = TextureAddressMode.TEXTUREADDRESSWRAP, filterMode = TextureFilterMode.FILTERLINEAR, bitDepth = 32, platformType = 8, compression = 0, hasAlpha = false, rasterFormatFlags = TextureRasterFormat.RASTER_C8888, type = 4, mipMaps = new MipMapEntry[] { new MipMapEntry(bitmapData.Count, bitmapData.ToArray()) }, }, textureNativeExtension = new Extension_0003() } }, textureDictionaryExtension = new Extension_0003() }; bitmap.Dispose(); // created PC txd, now will convert to gamecube. if (!Directory.Exists(tempPcTxdsDir)) { Directory.CreateDirectory(tempPcTxdsDir); } if (!Directory.Exists(tempGcTxdsDir)) { Directory.CreateDirectory(tempGcTxdsDir); } ExportSingleTextureToDictionary(pathToPcTXD, ReadFileMethods.ExportRenderWareFile(td, currentTextureVersion), textureName); PerformTXDConversionExternal(false, compress, mipmaps); string assetName = textureName + (appendRW3 ? ".RW3" : ""); ReadFileMethods.treatStuffAsByteArray = true; Section_AHDR AHDR = new Section_AHDR(BKDRHash(assetName), AssetType.RWTX, AHDRFlagsFromAssetType(AssetType.RWTX), new Section_ADBG(0, assetName, "", 0), ReadFileMethods.ExportRenderWareFile(ReadFileMethods.ReadRenderWareFile(pathToGcTXD), currentTextureVersion)); ReadFileMethods.treatStuffAsByteArray = false; File.Delete(pathToGcTXD); File.Delete(pathToPcTXD); return(AHDR); }
public static void LoadTexturesFromTXD(byte[] txdData, SharpRenderer renderer, BSPRenderer bspRenderer) { LoadTexturesFromTXD(ReadFileMethods.ReadRenderWareFile(txdData), renderer, bspRenderer); }
private void SetupForModel(AssetRenderWareModel asset) { AddRow(); AddRow(); AddRow(); AddRow(); Button buttonSetVertexColors = new Button() { Dock = DockStyle.Fill, Text = "Set Vertex Colors", AutoSize = true }; buttonSetVertexColors.Click += (object sender, EventArgs e) => { var(color, operation) = ApplyVertexColors.GetColor(); if (color.HasValue) { asset.SetVertexColors(color.Value, operation); archive.UnsavedChanges = true; } }; buttonSetVertexColors.Enabled = !asset.IsNativeData; tableLayoutPanel1.Controls.Add(buttonSetVertexColors, 0, 2); CheckBox ignoreMeshColors = new CheckBox() { Dock = DockStyle.Fill, Text = "Ignore Mesh Colors", AutoSize = true }; ignoreMeshColors.Checked = true; tableLayoutPanel1.Controls.Add(ignoreMeshColors, 0, 3); CheckBox flipUVs = new CheckBox() { Dock = DockStyle.Fill, Text = "Flip UVs", AutoSize = true }; tableLayoutPanel1.Controls.Add(flipUVs, 0, 4); Button buttonImport = new Button() { Dock = DockStyle.Fill, Text = "Import", AutoSize = true }; buttonImport.Click += (object sender, EventArgs e) => { OpenFileDialog openFile = new OpenFileDialog() { Filter = GetImportFilter(), // "All supported types|*.dae;*.obj;*.bsp|DAE Files|*.dae|OBJ Files|*.obj|BSP Files|*.bsp|All files|*.*", }; if (openFile.ShowDialog() == DialogResult.OK) { if (asset.AHDR.assetType == HipHopFile.AssetType.MODL) { asset.Data = Path.GetExtension(openFile.FileName).ToLower().Equals(".dff") ? File.ReadAllBytes(openFile.FileName) : ReadFileMethods.ExportRenderWareFile(CreateDFFFromAssimp(openFile.FileName, flipUVs.Checked, ignoreMeshColors.Checked), modelRenderWareVersion(asset.game)); } if (asset.AHDR.assetType == HipHopFile.AssetType.BSP) { asset.Data = Path.GetExtension(openFile.FileName).ToLower().Equals(".bsp") ? File.ReadAllBytes(openFile.FileName) : ReadFileMethods.ExportRenderWareFile(CreateBSPFromAssimp(openFile.FileName, flipUVs.Checked, ignoreMeshColors.Checked), modelRenderWareVersion(asset.game)); } asset.Setup(Program.MainForm.renderer); archive.UnsavedChanges = true; } }; tableLayoutPanel1.Controls.Add(buttonImport, 0, 5); CheckBox exportTextures = new CheckBox() { Dock = DockStyle.Fill, Text = "Export Textures", AutoSize = true }; tableLayoutPanel1.Controls.Add(exportTextures, 1, 4); Button buttonExport = new Button() { Dock = DockStyle.Fill, Text = "Export", AutoSize = true }; buttonExport.Click += (object sender, EventArgs e) => { (Assimp.ExportFormatDescription format, string textureExtension) = ChooseTarget.GetTarget(); if (format != null) { SaveFileDialog a = new SaveFileDialog() { Filter = format == null ? "RenderWare BSP|*.bsp" : format.Description + "|*." + format.FileExtension, }; if (a.ShowDialog() == DialogResult.OK) { if (format == null) { File.WriteAllBytes(a.FileName, asset.Data); } else if (format.FileExtension.ToLower().Equals("obj") && asset.AHDR.assetType == HipHopFile.AssetType.BSP) { ConvertBSPtoOBJ(a.FileName, ReadFileMethods.ReadRenderWareFile(asset.Data), true); } else { ExportAssimp(Path.ChangeExtension(a.FileName, format.FileExtension), ReadFileMethods.ReadRenderWareFile(asset.Data), true, format, textureExtension, Matrix.Identity); } if (exportTextures.Checked) { string folderName = Path.GetDirectoryName(a.FileName); var bitmaps = archive.GetTexturesAsBitmaps(asset.Textures); ReadFileMethods.treatStuffAsByteArray = false; foreach (string textureName in bitmaps.Keys) { bitmaps[textureName].Save(folderName + "/" + textureName + ".png", System.Drawing.Imaging.ImageFormat.Png); } } } } }; tableLayoutPanel1.Controls.Add(buttonExport, 1, 5); }
public static (List <Section_AHDR> AHDRs, bool overwrite, bool simps, bool ledgeGrab, bool piptVColors) GetModels(Game game) { using (ImportModel a = new ImportModel()) if (a.ShowDialog() == DialogResult.OK) { List <Section_AHDR> AHDRs = new List <Section_AHDR>(); AssetType assetType = (AssetType)a.comboBoxAssetTypes.SelectedItem; bool simps = false, ledgeGrab = false, piptVColors = false; if (assetType == AssetType.MODL) { piptVColors = a.checkBoxEnableVcolors.Checked; simps = a.checkBoxGenSimps.Checked; ledgeGrab = a.checkBoxLedgeGrab.Checked; if (simps) { MessageBox.Show("a SIMP for each imported MODL will be generated and placed on a new DEFAULT layer."); } } foreach (string filePath in a.filePaths) { string assetName; byte[] assetData; ReadFileMethods.treatStuffAsByteArray = false; if (assetType == AssetType.MODL) { assetName = Path.GetFileNameWithoutExtension(filePath) + ".dff"; assetData = Path.GetExtension(filePath).ToLower().Equals(".dff") ? File.ReadAllBytes(filePath) : ReadFileMethods.ExportRenderWareFile( CreateDFFFromAssimp(filePath, a.checkBoxFlipUVs.Checked, a.checkBoxIgnoreMeshColors.Checked), modelRenderWareVersion(game)); } else if (assetType == AssetType.BSP) { assetName = Path.GetFileNameWithoutExtension(filePath) + ".bsp"; assetData = Path.GetExtension(filePath).ToLower().Equals(".bsp") ? File.ReadAllBytes(filePath) : ReadFileMethods.ExportRenderWareFile( CreateBSPFromAssimp(filePath, a.checkBoxFlipUVs.Checked, a.checkBoxIgnoreMeshColors.Checked), modelRenderWareVersion(game)); } else { throw new ArgumentException(); } AHDRs.Add(new Section_AHDR( Functions.BKDRHash(assetName), assetType, ArchiveEditorFunctions.AHDRFlagsFromAssetType(assetType), new Section_ADBG(0, assetName, "", 0), assetData)); } return(AHDRs, a.checkBoxOverwrite.Checked, simps, ledgeGrab, piptVColors); } return(null, false, false, false, false); }
public Dictionary <string, Bitmap> ExportTXDToBitmap(byte[] txdFile) { if (!Directory.Exists(tempPcTxdsDir)) { Directory.CreateDirectory(tempPcTxdsDir); } if (!Directory.Exists(tempGcTxdsDir)) { Directory.CreateDirectory(tempGcTxdsDir); } File.WriteAllBytes(pathToPcTXD, txdFile); PerformTXDConversionExternal(platform, false, false, false, "gameRoot=" + tempPcTxdsDir + "\r\n" + "outputRoot=" + tempGcTxdsDir + "\r\n" + "targetVersion=VC\r\n" + "targetPlatform=uncompressed_mobile\r\n" ); PerformTXDConversionExternal(platform); Dictionary <string, Bitmap> bitmaps = new Dictionary <string, Bitmap>(); foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(pathToPcTXD)) { if (rw is TextureDictionary_0016 td) { // For each texture in the dictionary... foreach (TextureNative_0015 tn in td.textureNativeList) { List <System.Drawing.Color> bitmapData = new List <System.Drawing.Color>(); byte[] imageData = tn.textureNativeStruct.mipMaps[0].data; //if (tn.textureNativeStruct.compression == 0) if (tn.textureNativeStruct.mipMaps[0].dataSize == tn.textureNativeStruct.width * tn.textureNativeStruct.height * 4) { for (int i = 0; i < imageData.Length; i += 4) { bitmapData.Add(System.Drawing.Color.FromArgb( imageData[i + 3], imageData[i + 2], imageData[i + 1], imageData[i])); } } else { for (int i = 0; i < imageData.Length; i += 2) { short value = BitConverter.ToInt16(imageData, i); byte R = (byte)((value >> 11) & 0x1F); byte G = (byte)((value >> 5) & 0x3F); byte B = (byte)((value) & 0x1F); System.Drawing.Color color = System.Drawing.Color.FromArgb(0xFF, (R << 3) | (R >> 2), (G << 2) | (G >> 4), (B << 3) | (B >> 2)); bitmapData.Add(color); } } Bitmap b = new Bitmap(tn.textureNativeStruct.width, tn.textureNativeStruct.height); int k = 0; for (int j = 0; j < b.Height; j++) { for (int i = 0; i < b.Width; i++) { int v = k; int v2 = bitmapData.Count; System.Drawing.Color c = bitmapData[k]; b.SetPixel(i, j, c); k++; } } if (!bitmaps.ContainsKey(tn.textureNativeStruct.textureName)) { bitmaps.Add(tn.textureNativeStruct.textureName, b); } } } } File.Delete(pathToGcTXD); File.Delete(pathToPcTXD); return(bitmaps); }
public void SetForRendering(SharpDevice device, RWSection[] rwChunkList, byte[] rwByteArray) { rwSectionArray = rwChunkList; if (rwByteArray == null) { rwSectionByteArray = ReadFileMethods.ExportRenderWareFile(rwSectionArray, isShadowCollision ? LevelEditor.BSP_IO_ShadowCollision.shadowRenderWareVersion : LevelEditor.BSP_IO_Heroes.heroesRenderWareVersion); #if RELEASE if (fileSizeCheck && rwSectionByteArray.Length > 450 * 1024) { System.Windows.Forms.MessageBox.Show(fileName + " is a very large file. It might crash the game if you don't use TONER mod to enable the game to load bigger files than normally."); } #endif } else { rwSectionByteArray = rwByteArray; } meshList = new List <SharpMesh>(); vertexListG = new List <Vector3>(); triangleList = new List <Triangle>(); triangleListOffset = 0; foreach (RWSection rwSection in rwSectionArray) { if (rwSection is World_000B w) { vertexAmount = w.worldStruct.numVertices; triangleAmount = w.worldStruct.numTriangles; foreach (Material_0007 m in w.materialList.materialList) { if (isShadowCollision) { MaterialList.Add(m.materialStruct.color.ToString()); } else if (m.texture != null) { MaterialList.Add(m.texture.diffuseTextureName.stringString); } else { MaterialList.Add(DefaultTexture); } } if (w.firstWorldChunk is AtomicSector_0009 a) { AddAtomic(device, a); } else if (w.firstWorldChunk is PlaneSector_000A p) { AddPlane(device, p); } } else if (rwSection is Clump_0010 c) { for (int g = 0; g < c.geometryList.geometryList.Count; g++) { AddGeometry(device, c.geometryList.geometryList[g], CreateMatrix(c.frameList, c.atomicList[g].atomicStruct.frameIndex)); } } } }
public static void SetShadowMeshStream(List <Archive> OpenShadowONEFiles) { foreach (RenderWareModelFile r in BSPStream) { foreach (SharpMesh mesh in r.meshList) { mesh.Dispose(); } } foreach (RenderWareModelFile r in ShadowCollisionBSPStream) { foreach (SharpMesh mesh in r.meshList) { mesh.Dispose(); } } LoadTextures(currentShadowFolderNamePrefix); BSPStream = new List <RenderWareModelFile>(); ShadowCollisionBSPStream = new List <RenderWareModelFile>(); ReadFileMethods.isShadow = true; foreach (Archive f in OpenShadowONEFiles) { foreach (ArchiveFile file in f.Files) { string ChunkName = Path.GetFileNameWithoutExtension(file.Name); if (ChunkName.Contains("COLI")) { ReadFileMethods.isCollision = true; RenderWareModelFile TempBSPFile = new RenderWareModelFile(file.Name); try { TempBSPFile.ChunkNumber = Convert.ToByte(ChunkName.Split('_').Last()); } catch { TempBSPFile.ChunkNumber = -1; }; TempBSPFile.isShadowCollision = true; try { byte[] data = file.DecompressThis(); TempBSPFile.SetForRendering(ReadFileMethods.ReadRenderWareFile(data), data); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Error on opening " + file.Name + ": " + e.Message); } ShadowCollisionBSPStream.Add(TempBSPFile); ReadFileMethods.isCollision = false; } else { RenderWareModelFile TempBSPFile = new RenderWareModelFile(file.Name); TempBSPFile.SetChunkNumberAndName(); byte[] data = file.DecompressThis(); TempBSPFile.SetForRendering(ReadFileMethods.ReadRenderWareFile(data), data); BSPStream.Add(TempBSPFile); } } } }
public static List <Section_AHDR> GetAssets(Game game, Platform platform, out bool success, out bool overwrite) { ImportTextures a = new ImportTextures(); if (a.ShowDialog() == DialogResult.OK) { ReadFileMethods.treatStuffAsByteArray = true; List <Section_AHDR> AHDRs = new List <Section_AHDR>(); List <string> forBitmap = new List <string>(); for (int i = 0; i < a.filePaths.Count; i++) { if (Path.GetExtension(a.filePaths[i]).ToLower().Equals(".rwtex")) { byte[] data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 }, textureNativeList = new List <TextureNative_0015>() { new TextureNative_0015().FromBytes(File.ReadAllBytes(a.filePaths[i])) }, textureDictionaryExtension = new Extension_0003() }, currentTextureVersion(game)); string assetName = Path.GetFileNameWithoutExtension(a.filePaths[i]) + (a.checkBoxRW3.Checked ? ".RW3" : ""); Section_ADBG ADBG = new Section_ADBG(0, assetName, "", 0); Section_AHDR AHDR = new Section_AHDR(Functions.BKDRHash(assetName), AssetType.RWTX, ArchiveEditorFunctions.AHDRFlagsFromAssetType(AssetType.RWTX), ADBG, data); AHDRs.Add(AHDR); } else { forBitmap.Add(a.filePaths[i]); } } AHDRs.AddRange(CreateRWTXsFromBitmaps(game, platform, forBitmap, a.checkBoxRW3.Checked, a.checkBoxFlipTextures.Checked, a.checkBoxMipmaps.Checked, a.checkBoxCompress.Checked)); ReadFileMethods.treatStuffAsByteArray = false; if (game == Game.Scooby) { for (int i = 0; i < AHDRs.Count; i++) { byte[] data = AHDRs[i].data; FixTextureForScooby(ref data); AHDRs[i].data = data; } } success = true; overwrite = a.checkBoxOverwrite.Checked; return(AHDRs); } else { success = false; overwrite = false; return(null); } }
public void SetForRendering(RWSection[] rwChunkList, byte[] rwByteArray) { rwSectionArray = rwChunkList; if (rwByteArray == null) { rwSectionByteArray = ReadFileMethods.ExportRenderWareFile(rwSectionArray, isShadowCollision ? LevelEditor.LevelEditorFunctions.shadowRenderWareVersion : LevelEditor.LevelEditorFunctions.renderWareVersion); if (rwSectionByteArray.Length > 450 * 1024) { System.Windows.Forms.MessageBox.Show(fileName + " is larger than 450 kb. I will still import it for you, but be warned that files too large might make the game crash."); } } else { rwSectionByteArray = rwByteArray; } meshList = new List <SharpMesh>(); vertexList = new List <Vector3>(); triangleList = new List <Triangle>(); foreach (RWSection rwSection in rwSectionArray) { if (rwSection is World_000B w) { vertexAmount = w.worldStruct.numVertices; triangleAmount = w.worldStruct.numTriangles; foreach (Material_0007 m in w.materialList.materialList) { if (isShadowCollision) { MaterialList.Add(m.materialStruct.color.ToString()); } else if (m.texture != null) { MaterialList.Add(m.texture.diffuseTextureName.stringString); } else { MaterialList.Add(DefaultTexture); } } if (w.firstWorldChunk is AtomicSector_0009 a) { AddAtomic(a); } else if (w.firstWorldChunk is PlaneSector_000A p) { AddPlane(p); } } else if (rwSection is Clump_0010 c) { foreach (Geometry_000F g in c.geometryList.geometryList) { AddGeometry(g); } } } }
public static List <Section_AHDR> CreateRWTXsFromBitmaps (Game game, Platform platform, List <string> fileNames, bool appendRW3, bool flip, bool mipmaps, bool compress, bool transFix) { lock (locker) { if (transFix) { compress = false; } List <TextureNative_0015> textureNativeList = new List <TextureNative_0015>(); foreach (string fileName in fileNames) { string textureName = Path.GetFileNameWithoutExtension(fileName); Bitmap bitmap = new Bitmap(fileName); List <byte> bitmapData = new List <byte>(bitmap.Width * bitmap.Height * 4); if (flip) { bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); } for (int j = 0; j < bitmap.Height; j++) { for (int i = 0; i < bitmap.Width; i++) { bitmapData.Add(bitmap.GetPixel(i, j).B); bitmapData.Add(bitmap.GetPixel(i, j).G); bitmapData.Add(bitmap.GetPixel(i, j).R); bitmapData.Add(bitmap.GetPixel(i, j).A); } } textureNativeList.Add( new TextureNative_0015() { textureNativeStruct = new TextureNativeStruct_0001() { textureName = textureName + (appendRW3 ? ".RW3" : ""), alphaName = "", height = (short)bitmap.Height, width = (short)bitmap.Width, mipMapCount = 1, addressModeU = TextureAddressMode.TEXTUREADDRESSWRAP, addressModeV = TextureAddressMode.TEXTUREADDRESSWRAP, filterMode = TextureFilterMode.FILTERLINEAR, bitDepth = 32, platformType = 8, compression = 0, hasAlpha = false, rasterFormatFlags = TextureRasterFormat.RASTER_C8888, type = 4, mipMaps = new MipMapEntry[] { new MipMapEntry(bitmapData.Count, bitmapData.ToArray()) }, }, textureNativeExtension = new Extension_0003() } ); bitmap.Dispose(); } if (!Directory.Exists(tempPcTxdsDir)) { Directory.CreateDirectory(tempPcTxdsDir); } if (!Directory.Exists(tempGcTxdsDir)) { Directory.CreateDirectory(tempGcTxdsDir); } File.WriteAllBytes(pathToPcTXD, ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = (short)textureNativeList.Count, unknown = 0 }, textureNativeList = textureNativeList, textureDictionaryExtension = new Extension_0003() }, currentTextureVersion(game))); PerformTXDConversionExternal(platform, false, compress, mipmaps); ReadFileMethods.treatStuffAsByteArray = true; List <Section_AHDR> AHDRs = new List <Section_AHDR>(); foreach (TextureNative_0015 texture in ((TextureDictionary_0016)ReadFileMethods.ReadRenderWareFile(pathToGcTXD)[0]).textureNativeList) { AHDRs.Add(new Section_AHDR(BKDRHash(texture.textureNativeStruct.textureName), AssetType.RWTX, ArchiveEditorFunctions.AHDRFlagsFromAssetType(AssetType.RWTX), new Section_ADBG(0, texture.textureNativeStruct.textureName, "", 0), ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 }, textureNativeList = new List <TextureNative_0015>() { texture }, textureDictionaryExtension = new Extension_0003() }, currentTextureVersion(game)))); } // fix for apparent transparency issue if (transFix && platform == Platform.GameCube) { foreach (var AHDR in AHDRs) { AHDR.data[0x9B] = 0x01; } } ReadFileMethods.treatStuffAsByteArray = false; File.Delete(pathToGcTXD); File.Delete(pathToPcTXD); return(AHDRs); } }
public static List <Section_AHDR> GetAssets(out bool success) { ImportModel a = new ImportModel(); if (a.ShowDialog() == DialogResult.OK) { List <Section_AHDR> AHDRs = new List <Section_AHDR>(); for (int i = 0; i < a.filePaths.Count; i++) { ModelConverterData m; if (Path.GetExtension(a.filePaths[i]).ToLower().Equals(".obj")) { m = ReadOBJFile(a.filePaths[i]); } else if (Path.GetExtension(a.filePaths[i]).ToLower().Equals(".dae")) { m = ConvertDataFromDAEObject(ReadDAEFile(a.filePaths[i]), false); } else { MessageBox.Show("Unknown file format for " + a.filePaths[i] + ", skipping"); continue; } byte[] data; AssetType assetType; string assetName = Path.GetFileNameWithoutExtension(a.filePaths[i]); // + ".dff"; //switch (a.comboBoxAssetTypes.SelectedIndex) //{ // case 0: // assetType = AssetType.BSP; // data = ReadFileMethods.ExportRenderWareFile(CreateBSPFile(m, a.checkBoxFlipUVs.Checked), scoobyRenderWareVersion); // break; // case 1: // assetType = AssetType.MODL; // scooby // data = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), scoobyRenderWareVersion); // break; // case 2: // assetType = AssetType.MODL; // bfbb // data = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), bfbbRenderWareVersion); // break; // default: // assetType = AssetType.MODL; // movie // data = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), tssmRenderWareVersion); // break; //} assetType = AssetType.MODL; data = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), currentRenderWareVersion); Section_ADBG ADBG = new Section_ADBG(0, assetName, "", 0); Section_AHDR AHDR = new Section_AHDR(Functions.BKDRHash(assetName), assetType, ArchiveEditorFunctions.AHDRFlagsFromAssetType(assetType), ADBG, data); AHDRs.Add(AHDR); } success = true; return(AHDRs); } else { success = false; return(null); } }
public void AddTextureDictionary(string fileName, bool RW3) { UnsavedChanges = true; int layerIndex = 0; List <Section_LHDR> LHDRs = new List <Section_LHDR> { new Section_LHDR() { layerType = 1, assetIDlist = new List <uint>(), LDBG = new Section_LDBG(-1) } }; LHDRs.AddRange(DICT.LTOC.LHDRList); DICT.LTOC.LHDRList = LHDRs; ReadFileMethods.treatStuffAsByteArray = true; foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(fileName)) { if (rw is TextureDictionary_0016 td) { // For each texture in the dictionary... foreach (TextureNative_0015 tn in td.textureNativeList) { string textureName = tn.textureNativeStruct.textureName; if (RW3 && !textureName.Contains(".RW3")) { textureName += ".RW3"; } // Create a new dictionary that has only that texture. byte[] data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016() { textureDictionaryStruct = new TextureDictionaryStruct_0001() { textureCount = 1, unknown = 0 }, textureDictionaryExtension = new Extension_0003(), textureNativeList = new List <TextureNative_0015>() { tn } }, tn.renderWareVersion); // And add the new dictionary as an asset. Section_ADBG ADBG = new Section_ADBG(0, textureName, "", 0); Section_AHDR AHDR = new Section_AHDR(BKDRHash(textureName), AssetType.RWTX, AHDRFlags.SOURCE_VIRTUAL | AHDRFlags.READ_TRANSFORM, ADBG, data); if (ContainsAsset(AHDR.assetID)) { RemoveAsset(AHDR.assetID); } AddAsset(layerIndex, AHDR); } } } ReadFileMethods.treatStuffAsByteArray = false; }
public static System.Drawing.Bitmap ExportRWTXToBitmap(byte[] textureData) { if (!Directory.Exists(tempPcTxdsDir)) { Directory.CreateDirectory(tempPcTxdsDir); } if (!Directory.Exists(tempGcTxdsDir)) { Directory.CreateDirectory(tempGcTxdsDir); } File.WriteAllBytes(pathToGcTXD, textureData); PerformTXDConversionExternal(true); System.Drawing.Bitmap bitmap = null; foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(pathToPcTXD)) { if (rw is TextureDictionary_0016 td) { // For each texture in the dictionary... foreach (TextureNative_0015 tn in td.textureNativeList) { List <System.Drawing.Color> bitmapData = new List <System.Drawing.Color>(); byte[] imageData = tn.textureNativeStruct.mipMaps[0].data; if (tn.textureNativeStruct.compression == 0) { for (int i = 0; i < imageData.Length; i += 4) { bitmapData.Add(System.Drawing.Color.FromArgb( imageData[i + 3], imageData[i + 2], imageData[i + 1], imageData[i])); } } else { for (int i = 0; i < imageData.Length; i += 2) { short value = BitConverter.ToInt16(imageData, i); byte R = (byte)((value >> 11) & 0x1F); byte G = (byte)((value >> 5) & 0x3F); byte B = (byte)((value) & 0x1F); System.Drawing.Color color = System.Drawing.Color.FromArgb(0xFF, (R << 3) | (R >> 2), (G << 2) | (G >> 4), (B << 3) | (B >> 2)); bitmapData.Add(color); } } bitmap = new System.Drawing.Bitmap(tn.textureNativeStruct.width, tn.textureNativeStruct.height); int k = 0; for (int i = 0; i < bitmap.Width; i++) { for (int j = 0; j < bitmap.Height; j++) { int v = k; int v2 = bitmapData.Count; System.Drawing.Color c = bitmapData[k]; bitmap.SetPixel(i, j, c); k++; } } } } } File.Delete(pathToGcTXD); File.Delete(pathToPcTXD); return(bitmap); }
public static void ExportScene(string folderName, Assimp.ExportFormatDescription format, string textureExtension, out string[] textureNames) { List <string> textureNamesList = new List <string>(); lock (renderableJSPs) foreach (var v in renderableJSPs) { try { textureNamesList.AddRange(v.Textures); Assimp_IO.ExportAssimp( Path.Combine(folderName, v.assetName + "." + format.FileExtension), ReadFileMethods.ReadRenderWareFile(v.Data), true, format, textureExtension, Matrix.Identity); } catch (Exception e) { MessageBox.Show($"Unable to export asset {v}: {e.Message}"); } } lock (renderableAssets) foreach (var v in renderableAssets) { try { Asset modelAsset; string assetName; Matrix world; if (v is EntityAsset entity) { if (entity.isInvisible || entity.DontRender || entity is AssetTRIG) { continue; } if (entity is AssetPKUP pkup) { if (AssetPICK.pickEntries.ContainsKey(pkup.PickReferenceID)) { modelAsset = (Asset)renderingDictionary[pkup.PickReferenceID]; } else { continue; } } else { modelAsset = (Asset)renderingDictionary[entity.Model_AssetID]; } assetName = entity.assetName; world = entity.world; } else if (v is AssetDYNA dyna && !AssetDYNA.dontRender && dyna is IRenderableAsset) { if (dyna.isInvisible) { continue; } if (dyna is DynaGObjectRing ring) { modelAsset = (Asset)renderingDictionary[DynaGObjectRingControl.RingModelAssetID]; world = ring.world; } else if (dyna is DynaEnemySB enemySb) { modelAsset = (Asset)renderingDictionary[enemySb.Model_AssetID]; world = enemySb.world; } else { continue; } assetName = dyna.assetName; } else { continue; } if (modelAsset is AssetMINF minf) { modelAsset = (Asset)renderingDictionary[minf.MinfReferences[0].Model_AssetID]; } if (modelAsset is AssetMODL modl) { textureNamesList.AddRange(modl.Textures); } else { continue; } Assimp_IO.ExportAssimp( Path.Combine(folderName, assetName + "." + format.FileExtension), ReadFileMethods.ReadRenderWareFile(modl.Data), true, format, textureExtension, world); }