mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-05-27 10:33:03 -05:00
Extracted ModelUtils from DSUtils
This commit is contained in:
parent
bb9631841c
commit
07102cd7e0
|
|
@ -275,7 +275,7 @@ namespace DSPRE {
|
|||
}
|
||||
|
||||
private void bldExportDAEbutton_Click(object sender, EventArgs e) {
|
||||
DSUtils.ModelToDAE(
|
||||
ModelUtils.ModelToDAE(
|
||||
modelName: buildingEditorBldListBox.SelectedItem.ToString().TrimEnd('\0'),
|
||||
modelData: currentModelData,
|
||||
textureData: textureComboBox.SelectedIndex < 1 ? null : File.ReadAllBytes(RomInfo.gameDirs[DirNames.buildingTextures].unpackedDir + "\\" + (textureComboBox.SelectedIndex - 1).ToString("D4"))
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ARM9.cs" />
|
||||
<Compile Include="DSUtils\ModelUtils.cs" />
|
||||
<Compile Include="EventFileImport.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
|
|||
|
|
@ -37,136 +37,6 @@ namespace DSPRE {
|
|||
}
|
||||
}
|
||||
|
||||
public static void ModelToDAE(string modelName, byte[] modelData, byte[] textureData) {
|
||||
MessageBox.Show("Choose output folder.\nDSPRE will automatically create a sub-folder in it.", "Awaiting user input", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
CommonOpenFileDialog cofd = new CommonOpenFileDialog {
|
||||
IsFolderPicker = true,
|
||||
Multiselect = false
|
||||
};
|
||||
if (cofd.ShowDialog() != CommonFileDialogResult.Ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
string outDir = Path.Combine(cofd.FileName, modelName);
|
||||
|
||||
if (Directory.Exists(outDir)) {
|
||||
if (Directory.GetFiles(outDir).Length > 0) {
|
||||
DialogResult d = MessageBox.Show($"Directory \"{outDir}\" already exists and is not empty.\nIts contents will be lost.\n\nDo you want to proceed?", "Directory not empty", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
if (d.Equals(DialogResult.No)) {
|
||||
return;
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
}
|
||||
string tempNSBMDPath = outDir + "_temp.nsbmd";
|
||||
|
||||
if (textureData != null && textureData.Length > 0) {
|
||||
modelData = NSBUtils.BuildNSBMDwithTextures(modelData, textureData);
|
||||
}
|
||||
|
||||
File.WriteAllBytes(tempNSBMDPath, modelData);
|
||||
|
||||
/* Check correct creation of temp NSBMD file*/
|
||||
if (!File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("Expected NSBMD file could not be found.\nAborting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
Process apicula = new Process();
|
||||
apicula.StartInfo.FileName = @"Tools\apicula.exe";
|
||||
apicula.StartInfo.Arguments = $" convert \"{tempNSBMDPath}\" --output \"{outDir}\"";
|
||||
apicula.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
apicula.StartInfo.CreateNoWindow = true;
|
||||
apicula.Start();
|
||||
apicula.WaitForExit();
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
File.Delete(tempNSBMDPath);
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("Temporary NSBMD file deletion failed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
} else {
|
||||
MessageBox.Show("Temporary NSBMD file corresponding to this map disappeared.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
if (apicula.ExitCode == 0) {
|
||||
MessageBox.Show("NSBMD was exported and converted successfully!", "Operation successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
} else {
|
||||
MessageBox.Show("NSBMD to DAE conversion failed.", "Apicula error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ModelToGLB(string modelName, byte[] modelData, byte[] textureData) {
|
||||
MessageBox.Show("Choose output folder.\nDSPRE will automatically create a sub-folder in it.", "Awaiting user input", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
CommonOpenFileDialog cofd = new CommonOpenFileDialog {
|
||||
IsFolderPicker = true,
|
||||
Multiselect = false
|
||||
};
|
||||
if (cofd.ShowDialog() != CommonFileDialogResult.Ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
string outDir = Path.Combine(cofd.FileName, modelName);
|
||||
|
||||
if (Directory.Exists(outDir)) {
|
||||
if (Directory.GetFiles(outDir).Length > 0) {
|
||||
DialogResult d = MessageBox.Show($"Directory \"{outDir}\" already exists and is not empty.\nIts contents will be lost.\n\nDo you want to proceed?", "Directory not empty", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
if (d.Equals(DialogResult.No)) {
|
||||
return;
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
}
|
||||
string tempNSBMDPath = outDir + "_temp.nsbmd";
|
||||
|
||||
if (textureData != null && textureData.Length > 0) {
|
||||
modelData = NSBUtils.BuildNSBMDwithTextures(modelData, textureData);
|
||||
}
|
||||
|
||||
File.WriteAllBytes(tempNSBMDPath, modelData);
|
||||
|
||||
/* Check correct creation of temp NSBMD file*/
|
||||
if (!File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("NSBMD file corresponding to this map could not be found.\nAborting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
Process apicula = new Process();
|
||||
apicula.StartInfo.FileName = @"Tools\apicula.exe";
|
||||
apicula.StartInfo.Arguments = $" convert \"{tempNSBMDPath}\" -f glb --output \"{outDir}\"";
|
||||
apicula.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
apicula.StartInfo.CreateNoWindow = true;
|
||||
apicula.Start();
|
||||
apicula.WaitForExit();
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
File.Delete(tempNSBMDPath);
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("Temporary NSBMD file deletion failed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
} else {
|
||||
MessageBox.Show("Temporary NSBMD file corresponding to this map disappeared.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
if (apicula.ExitCode == 0) {
|
||||
MessageBox.Show("NSBMD was exported and converted successfully!", "Operation successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
} else {
|
||||
MessageBox.Show("NSBMD to GLB conversion failed.", "Apicula error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteToFile(string filepath, byte[] toOutput, uint writeAt = 0, int indexFirstByteToWrite = 0, int? indexLastByteToWrite = null, FileMode fmode = FileMode.OpenOrCreate) {
|
||||
using (EasyWriter writer = new EasyWriter(filepath, writeAt, fmode)) {
|
||||
writer.Write(toOutput, indexFirstByteToWrite, indexLastByteToWrite is null ? toOutput.Length - indexFirstByteToWrite : (int)indexLastByteToWrite);
|
||||
|
|
|
|||
139
DS_Map/DSUtils/ModelUtils.cs
Normal file
139
DS_Map/DSUtils/ModelUtils.cs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DSPRE {
|
||||
public static class ModelUtils {
|
||||
|
||||
public static void ModelToDAE(string modelName, byte[] modelData, byte[] textureData) {
|
||||
MessageBox.Show("Choose output folder.\nDSPRE will automatically create a sub-folder in it.", "Awaiting user input", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
CommonOpenFileDialog cofd = new CommonOpenFileDialog {
|
||||
IsFolderPicker = true,
|
||||
Multiselect = false
|
||||
};
|
||||
if (cofd.ShowDialog() != CommonFileDialogResult.Ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
string outDir = Path.Combine(cofd.FileName, modelName);
|
||||
|
||||
if (Directory.Exists(outDir)) {
|
||||
if (Directory.GetFiles(outDir).Length > 0) {
|
||||
DialogResult d = MessageBox.Show($"Directory \"{outDir}\" already exists and is not empty.\nIts contents will be lost.\n\nDo you want to proceed?", "Directory not empty", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
if (d.Equals(DialogResult.No)) {
|
||||
return;
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
}
|
||||
string tempNSBMDPath = outDir + "_temp.nsbmd";
|
||||
|
||||
if (textureData != null && textureData.Length > 0) {
|
||||
modelData = NSBUtils.BuildNSBMDwithTextures(modelData, textureData);
|
||||
}
|
||||
|
||||
File.WriteAllBytes(tempNSBMDPath, modelData);
|
||||
|
||||
/* Check correct creation of temp NSBMD file*/
|
||||
if (!File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("Expected NSBMD file could not be found.\nAborting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
Process apicula = new Process();
|
||||
apicula.StartInfo.FileName = @"Tools\apicula.exe";
|
||||
apicula.StartInfo.Arguments = $" convert \"{tempNSBMDPath}\" --output \"{outDir}\"";
|
||||
apicula.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
apicula.StartInfo.CreateNoWindow = true;
|
||||
apicula.Start();
|
||||
apicula.WaitForExit();
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
File.Delete(tempNSBMDPath);
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("Temporary NSBMD file deletion failed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
} else {
|
||||
MessageBox.Show("Temporary NSBMD file corresponding to this map disappeared.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
if (apicula.ExitCode == 0) {
|
||||
MessageBox.Show("NSBMD was exported and converted successfully!", "Operation successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
} else {
|
||||
MessageBox.Show("NSBMD to DAE conversion failed.", "Apicula error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ModelToGLB(string modelName, byte[] modelData, byte[] textureData) {
|
||||
MessageBox.Show("Choose output folder.\nDSPRE will automatically create a sub-folder in it.", "Awaiting user input", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
CommonOpenFileDialog cofd = new CommonOpenFileDialog {
|
||||
IsFolderPicker = true,
|
||||
Multiselect = false
|
||||
};
|
||||
if (cofd.ShowDialog() != CommonFileDialogResult.Ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
string outDir = Path.Combine(cofd.FileName, modelName);
|
||||
|
||||
if (Directory.Exists(outDir)) {
|
||||
if (Directory.GetFiles(outDir).Length > 0) {
|
||||
DialogResult d = MessageBox.Show($"Directory \"{outDir}\" already exists and is not empty.\nIts contents will be lost.\n\nDo you want to proceed?", "Directory not empty", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
if (d.Equals(DialogResult.No)) {
|
||||
return;
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
} else {
|
||||
Directory.Delete(outDir, recursive: true);
|
||||
}
|
||||
}
|
||||
string tempNSBMDPath = outDir + "_temp.nsbmd";
|
||||
|
||||
if (textureData != null && textureData.Length > 0) {
|
||||
modelData = NSBUtils.BuildNSBMDwithTextures(modelData, textureData);
|
||||
}
|
||||
|
||||
File.WriteAllBytes(tempNSBMDPath, modelData);
|
||||
|
||||
/* Check correct creation of temp NSBMD file*/
|
||||
if (!File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("NSBMD file corresponding to this map could not be found.\nAborting", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
Process apicula = new Process();
|
||||
apicula.StartInfo.FileName = @"Tools\apicula.exe";
|
||||
apicula.StartInfo.Arguments = $" convert \"{tempNSBMDPath}\" -f glb --output \"{outDir}\"";
|
||||
apicula.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
apicula.StartInfo.CreateNoWindow = true;
|
||||
apicula.Start();
|
||||
apicula.WaitForExit();
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
File.Delete(tempNSBMDPath);
|
||||
|
||||
if (File.Exists(tempNSBMDPath)) {
|
||||
MessageBox.Show("Temporary NSBMD file deletion failed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
} else {
|
||||
MessageBox.Show("Temporary NSBMD file corresponding to this map disappeared.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
if (apicula.ExitCode == 0) {
|
||||
MessageBox.Show("NSBMD was exported and converted successfully!", "Operation successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
} else {
|
||||
MessageBox.Show("NSBMD to GLB conversion failed.", "Apicula error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4696,7 +4696,7 @@ namespace DSPRE {
|
|||
}
|
||||
|
||||
private void daeExportButton_Click(object sender, EventArgs e) {
|
||||
DSUtils.ModelToDAE(
|
||||
ModelUtils.ModelToDAE(
|
||||
modelName: selectMapComboBox.SelectedItem.ToString().TrimEnd('\0'),
|
||||
modelData: currentMapFile.mapModelData,
|
||||
textureData: mapTextureComboBox.SelectedIndex < 0 ? null : File.ReadAllBytes(RomInfo.gameDirs[DirNames.mapTextures].unpackedDir + "\\" + (mapTextureComboBox.SelectedIndex - 1).ToString("D4"))
|
||||
|
|
@ -4704,7 +4704,7 @@ namespace DSPRE {
|
|||
}
|
||||
|
||||
private void glbExportButton_Click(object sender, EventArgs e) {
|
||||
DSUtils.ModelToGLB(
|
||||
ModelUtils.ModelToGLB(
|
||||
modelName: selectMapComboBox.SelectedItem.ToString().TrimEnd('\0'),
|
||||
modelData: currentMapFile.mapModelData,
|
||||
textureData: mapTextureComboBox.SelectedIndex < 0 ? null : File.ReadAllBytes(RomInfo.gameDirs[DirNames.mapTextures].unpackedDir + "\\" + (mapTextureComboBox.SelectedIndex - 1).ToString("D4"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user