Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion SPICA.WinForms/FrmExport.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 43 additions & 49 deletions SPICA.WinForms/FrmExport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SPICA.Formats.CtrH3D;
using SPICA.Formats.CtrH3D.Model;
using SPICA.Formats.CtrH3D.Texture;
using SPICA.Formats.Generic.COLLADA;
using SPICA.Formats.Generic.StudioMdl;
Expand All @@ -9,40 +10,34 @@
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SPICA.WinForms
{
public partial class FrmExport : Form
{
public FrmExport()
{
namespace SPICA.WinForms {
public partial class FrmExport : Form {
public FrmExport() {
InitializeComponent();
}

private void FrmExport_Load(object sender, EventArgs e)
{
private void FrmExport_Load(object sender, EventArgs e) {
CmbFormat.SelectedIndex = 0;
}

private void BtnBrowseIn_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog Browser = new FolderBrowserDialog())
{
private void BtnBrowseIn_Click(object sender, EventArgs e) {
using (FolderBrowserDialog Browser = new FolderBrowserDialog()) {
if (Browser.ShowDialog() == DialogResult.OK) TxtInputFolder.Text = Browser.SelectedPath;
}
}

private void BtnBrowseOut_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog Browser = new FolderBrowserDialog())
{
private void BtnBrowseAnimationIn_Click(object sender, EventArgs e) {
using (FolderBrowserDialog Browser = new FolderBrowserDialog()) {
if (Browser.ShowDialog() == DialogResult.OK) TxtInputAnimationFolder.Text = Browser.SelectedPath;
}
}
private void BtnBrowseOut_Click(object sender, EventArgs e) {
using (FolderBrowserDialog Browser = new FolderBrowserDialog()) {
if (Browser.ShowDialog() == DialogResult.OK) TxtOutFolder.Text = Browser.SelectedPath;
}
}

private void BtnConvert_Click(object sender, EventArgs e)
{
if (!Directory.Exists(TxtInputFolder.Text))
{
private void BtnConvert_Click(object sender, EventArgs e) {
if (!Directory.Exists(TxtInputFolder.Text)) {
MessageBox.Show(
"Input folder not found!",
"Error",
Expand All @@ -52,8 +47,7 @@ private void BtnConvert_Click(object sender, EventArgs e)
return;
}

if (!Directory.Exists(TxtOutFolder.Text))
{
if (!Directory.Exists(TxtOutFolder.Text)) {
MessageBox.Show(
"Output folder not found!",
"Error",
Expand All @@ -64,6 +58,7 @@ private void BtnConvert_Click(object sender, EventArgs e)
}

string[] Files = Directory.GetFiles(TxtInputFolder.Text);
string[] AnimationFiles = Directory.GetFiles(TxtInputAnimationFolder.Text);

bool ExportModels = ChkExportModels.Checked;
bool ExportAnims = ChkExportAnimations.Checked;
Expand All @@ -74,51 +69,49 @@ private void BtnConvert_Click(object sender, EventArgs e)

int FileIndex = 0;

int CountFiles = 0;
//TODO: Use Parallel loop for more speed and keep UI responsive
foreach (string File in Files)
{
foreach (string File in Files) {
H3D Data = FormatIdentifier.IdentifyAndOpen(File);

if (Data != null)
{
if (Data != null) {
string BaseName = PrefixNames ? Path.GetFileNameWithoutExtension(File) + "_" : string.Empty;

BaseName = Path.Combine(TxtOutFolder.Text, BaseName);

if (!PrefixNames) BaseName += Path.DirectorySeparatorChar;

if (ExportModels)
{
for (int Index = 0; Index < Data.Models.Count; Index++)
{
if (ExportModels) {
for (int Index = 0; Index < Data.Models.Count; Index++) {
string FileName = BaseName + Data.Models[Index].Name;

switch (Format)
{
switch (Format) {
case 0: new DAE(Data, Index).Save(FileName + ".dae"); break;
case 1: new SMD(Data, Index).Save(FileName + ".smd"); break;
}
}
}

if (ExportAnims && Data.Models.Count > 0)
{
for (int Index = 0; Index < Data.SkeletalAnimations.Count; Index++)
{
string FileName = BaseName + Data.Models[0].Name + "_" + Data.SkeletalAnimations[Index].Name;

switch (Format)
{
case 0: new DAE(Data, 0, Index).Save(FileName + ".dae"); break;
case 1: new SMD(Data, 0, Index).Save(FileName + ".smd"); break;
if (ExportAnims) {
string Filename = Path.GetFileName(File);
string ModelFolder = File.Replace(Filename, "");

foreach (string AnimationFile in AnimationFiles) {
if (AnimationFile.Contains(Filename)) {
string AnimationFolder = AnimationFile.Replace(Filename, "");
string[] MergedFiles = new string[] { Path.Combine(ModelFolder, Filename), Path.Combine(AnimationFolder, Filename) };
H3D MergedData = FileIO.Merge(MergedFiles, new Rendering.Renderer(1, 1), Data);
for (int Index = 0; Index < MergedData.SkeletalAnimations.Count; Index++) {
string FileName = BaseName + MergedData.Models[0].Name + "_" + MergedData.SkeletalAnimations[Index].Name;
switch (Format) {
case 0: new DAE(MergedData, 0, Index).Save(FileName + ".dae"); break;
case 1: new SMD(MergedData, 0, Index).Save(FileName + ".smd"); break;
}
}
}
}
}

if (ExportTexs)
{
foreach (H3DTexture Tex in Data.Textures)
{
if (ExportTexs) {
foreach (H3DTexture Tex in Data.Textures) {
Tex.ToBitmap().Save(Path.Combine(TxtOutFolder.Text, Tex.Name + ".png"));
}
}
Expand All @@ -131,6 +124,7 @@ private void BtnConvert_Click(object sender, EventArgs e)
ProgressConv.Value = (int)Progress;

Application.DoEvents();
CountFiles++;
}
}
}
Expand Down