Skip to content

Commit

Permalink
Merge branch 'dev' into 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
corbin-poteet committed Jan 2, 2023
2 parents 97ad85f + fd26404 commit a657d90
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
17 changes: 10 additions & 7 deletions FrostyPlugin/Windows/BatchExportSelectedWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public partial class BatchExportSelectedWindow : FrostyDockableWindow
public List<string> types = new List<string>()
{
"RigidMeshAsset",
"CompositeMeshAsset"
"CompositeMeshAsset",
"TextureAsset"
};

public BatchExportSelectedWindow(AssetPath selectedPath, IEnumerable itemsSource)
Expand All @@ -48,26 +49,26 @@ private void doneButton_Click(object sender, RoutedEventArgs e)
List<EbxAssetEntry> entries = new List<EbxAssetEntry>();
if (includeSubDirectories)
{
foreach (AssetEntry entry in itemsSource)
foreach (EbxAssetEntry entry in itemsSource)
{
if (entry.Path.Contains(fullPath.ToLower()))
if (entry.Path.ToLower().Contains(fullPath.ToLower()))
{
if (types.Contains(entry.Type))
{
entries.Add((EbxAssetEntry)entry);
entries.Add(entry);
}
}
}
}
else
{
foreach (AssetEntry entry in itemsSource)
foreach (EbxAssetEntry entry in itemsSource)
{
if (entry.Path.Equals(fullPath, StringComparison.OrdinalIgnoreCase))
{
if (types.Contains(entry.Type))
{
entries.Add((EbxAssetEntry)entry);
entries.Add(entry);
}
}
}
Expand All @@ -78,13 +79,15 @@ private void doneButton_Click(object sender, RoutedEventArgs e)
int i = 0;
while (entries.Count > 0 && i < entries.Count)
{
int originalCount = entries.Count;
// use the first instance of a given AssetDefinition to export all instances of that AssetDefinition in the array
AssetDefinition assetDefinition = App.PluginManager.GetAssetDefinition(entries[i].Type) ?? new AssetDefinition();
List<EbxAssetEntry> leftOverEntries = assetDefinition.BatchExport(entries, path, stopWatch);

// If we somehow failed to export any entries, add 1 to i to avoid an infinite loop
if (leftOverEntries.Count == entries.Count)
if (leftOverEntries.Count == originalCount)
{
Console.WriteLine("Failed to export a group of asset definitions.");
i++;
}

Expand Down
2 changes: 1 addition & 1 deletion Plugins/MeshSetPlugin/MeshAssetDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private bool PreBatchExport(out MeshExportSettings outSettings)
}
private List<EbxAssetEntry> BatchExportInternal(List<EbxAssetEntry> entries, string path, MeshExportSettings settings, Stopwatch stopWatch = null)
{
FrostyTaskWindow.Show("Exporting MeshSet", "", (task) =>
FrostyTaskWindow.Show("Exporting Static Meshes", "", (task) =>
{
stopWatch?.Start();

Expand Down
41 changes: 41 additions & 0 deletions Plugins/TexturePlugin/TextureAssetDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
using System.Collections.Generic;
using System.Windows.Media;
using FrostySdk.Managers.Entries;
using System.Diagnostics;
using SharpDX.Direct3D11;
using System.IO;
using Frosty.Core.Windows;

namespace TexturePlugin
{
Expand All @@ -33,6 +37,43 @@ public override ImageSource GetIcon()
return imageSource;
}

public override List<EbxAssetEntry> BatchExport(List<EbxAssetEntry> entries, string path, Stopwatch stopWatch)
{
FrostyTaskWindow.Show("Exporting Textures", "", (task) =>
{
TextureExporter exporter = new TextureExporter();

for (int i = entries.Count - 1; i >= 0; i--)
{
if (entries[i].Type == "TextureAsset")
{

EbxAsset asset = App.AssetManager.GetEbx(entries[i]);
dynamic textureAsset = (dynamic)asset.RootObject;

ResAssetEntry resEntry = App.AssetManager.GetResEntry(textureAsset.Resource);
Texture texture = App.AssetManager.GetResAs<Texture>(resEntry);

// define combine user defined path with the asset's data explorer path
string assetPath = Path.Combine(path, entries[i].Path);
string assetFullPath = Path.Combine(path, entries[i].Name);
string assetName = Path.GetFileName(entries[i].Name);
System.IO.Directory.CreateDirectory(assetPath);

task.Update("Writing " + assetName);
exporter.Export(texture, assetFullPath + ".tga", "*.tga");

entries.RemoveAt(i);
}
}

});

return entries;

}


public override bool Export(EbxAssetEntry entry, string path, string filterType)
{
if (!base.Export(entry, path, filterType))
Expand Down

0 comments on commit a657d90

Please sign in to comment.