Added save all textures options to ModelForm

This commit is contained in:
dexy 2022-01-11 03:04:51 +11:00
parent 52cb8511a0
commit e461de4cfd
3 changed files with 475 additions and 202 deletions

View File

@ -51,6 +51,9 @@
this.SaveButton = new System.Windows.Forms.ToolStripSplitButton();
this.SaveMenuButton = new System.Windows.Forms.ToolStripMenuItem();
this.SaveAsMenuButton = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.SaveAllTexturesMenuButton = new System.Windows.Forms.ToolStripMenuItem();
this.SaveSharedTexturesMenuButton = new System.Windows.Forms.ToolStripMenuItem();
this.ToolsTabControl = new System.Windows.Forms.TabControl();
this.ToolsModelsTabPage = new System.Windows.Forms.TabPage();
this.EnableRootMotionCheckBox = new System.Windows.Forms.CheckBox();
@ -60,9 +63,9 @@
this.ClipDictComboBox = new System.Windows.Forms.ComboBox();
this.ModelsTreeView = new CodeWalker.WinForms.TreeViewFix();
this.ToolsMaterialsTabPage = new System.Windows.Forms.TabPage();
this.TextureEditorButton = new System.Windows.Forms.Button();
this.SaveSharedTexturesButton = new System.Windows.Forms.Button();
this.TexturesTreeView = new CodeWalker.WinForms.TreeViewFix();
this.MaterialEditorButton = new System.Windows.Forms.Button();
this.SaveAllTexturesButton = new System.Windows.Forms.Button();
this.ToolsDetailsTabPage = new System.Windows.Forms.TabPage();
this.DetailsPropertyGrid = new CodeWalker.WinForms.ReadOnlyPropertyGrid();
this.ToolsOptionsTabPage = new System.Windows.Forms.TabPage();
@ -89,7 +92,6 @@
this.label1 = new System.Windows.Forms.Label();
this.OptionsLightingTabPage = new System.Windows.Forms.TabPage();
this.DeferredShadingCheckBox = new System.Windows.Forms.CheckBox();
this.LightEditorButton = new System.Windows.Forms.Button();
this.HDLightsCheckBox = new System.Windows.Forms.CheckBox();
this.label19 = new System.Windows.Forms.Label();
this.HDRRenderingCheckBox = new System.Windows.Forms.CheckBox();
@ -102,6 +104,7 @@
this.ToolsDragPanel = new System.Windows.Forms.Panel();
this.ToolsPanelShowButton = new System.Windows.Forms.Button();
this.SaveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.FolderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
this.StatusStrip.SuspendLayout();
this.ConsolePanel.SuspendLayout();
this.ToolsPanel.SuspendLayout();
@ -195,7 +198,7 @@
this.ToolsPanel.Controls.Add(this.ToolsDragPanel);
this.ToolsPanel.Location = new System.Drawing.Point(12, 12);
this.ToolsPanel.Name = "ToolsPanel";
this.ToolsPanel.Size = new System.Drawing.Size(230, 559);
this.ToolsPanel.Size = new System.Drawing.Size(254, 559);
this.ToolsPanel.TabIndex = 2;
this.ToolsPanel.Visible = false;
//
@ -207,7 +210,7 @@
this.MainToolbarPanel.Controls.Add(this.MainToolbar);
this.MainToolbarPanel.Location = new System.Drawing.Point(39, 2);
this.MainToolbarPanel.Name = "MainToolbarPanel";
this.MainToolbarPanel.Size = new System.Drawing.Size(188, 24);
this.MainToolbarPanel.Size = new System.Drawing.Size(212, 24);
this.MainToolbarPanel.TabIndex = 4;
//
// MainToolbar
@ -225,7 +228,7 @@
this.SaveButton});
this.MainToolbar.Location = new System.Drawing.Point(0, 0);
this.MainToolbar.Name = "MainToolbar";
this.MainToolbar.Size = new System.Drawing.Size(188, 25);
this.MainToolbar.Size = new System.Drawing.Size(212, 25);
this.MainToolbar.TabIndex = 7;
this.MainToolbar.Text = "Main Toolbar";
//
@ -308,11 +311,14 @@
this.SaveButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.SaveButton.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveMenuButton,
this.SaveAsMenuButton});
this.SaveAsMenuButton,
this.toolStripSeparator3,
this.SaveAllTexturesMenuButton,
this.SaveSharedTexturesMenuButton});
this.SaveButton.Image = ((System.Drawing.Image)(resources.GetObject("SaveButton.Image")));
this.SaveButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(32, 20);
this.SaveButton.Size = new System.Drawing.Size(32, 22);
this.SaveButton.Text = "Save";
this.SaveButton.ButtonClick += new System.EventHandler(this.SaveButton_ButtonClick);
//
@ -321,17 +327,37 @@
this.SaveMenuButton.Image = ((System.Drawing.Image)(resources.GetObject("SaveMenuButton.Image")));
this.SaveMenuButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.SaveMenuButton.Name = "SaveMenuButton";
this.SaveMenuButton.Size = new System.Drawing.Size(123, 22);
this.SaveMenuButton.Size = new System.Drawing.Size(192, 22);
this.SaveMenuButton.Text = "Save";
this.SaveMenuButton.Click += new System.EventHandler(this.SaveMenuButton_Click);
//
// SaveAsMenuButton
//
this.SaveAsMenuButton.Name = "SaveAsMenuButton";
this.SaveAsMenuButton.Size = new System.Drawing.Size(123, 22);
this.SaveAsMenuButton.Size = new System.Drawing.Size(192, 22);
this.SaveAsMenuButton.Text = "Save As...";
this.SaveAsMenuButton.Click += new System.EventHandler(this.SaveAsMenuButton_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(189, 6);
//
// SaveAllTexturesMenuButton
//
this.SaveAllTexturesMenuButton.Name = "SaveAllTexturesMenuButton";
this.SaveAllTexturesMenuButton.Size = new System.Drawing.Size(192, 22);
this.SaveAllTexturesMenuButton.Text = "Save All Textures...";
this.SaveAllTexturesMenuButton.Click += new System.EventHandler(this.SaveAllTexturesMenuButton_Click);
//
// SaveSharedTexturesMenuButton
//
this.SaveSharedTexturesMenuButton.Name = "SaveSharedTexturesMenuButton";
this.SaveSharedTexturesMenuButton.Size = new System.Drawing.Size(192, 22);
this.SaveSharedTexturesMenuButton.Text = "Save Shared Textures...";
this.SaveSharedTexturesMenuButton.ToolTipText = "Save only the shared textures for this model (non-embedded)";
this.SaveSharedTexturesMenuButton.Click += new System.EventHandler(this.SaveSharedTexturesMenuButton_Click);
//
// ToolsTabControl
//
this.ToolsTabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -344,7 +370,7 @@
this.ToolsTabControl.Location = new System.Drawing.Point(2, 30);
this.ToolsTabControl.Name = "ToolsTabControl";
this.ToolsTabControl.SelectedIndex = 0;
this.ToolsTabControl.Size = new System.Drawing.Size(225, 526);
this.ToolsTabControl.Size = new System.Drawing.Size(249, 526);
this.ToolsTabControl.TabIndex = 1;
//
// ToolsModelsTabPage
@ -358,7 +384,7 @@
this.ToolsModelsTabPage.Location = new System.Drawing.Point(4, 22);
this.ToolsModelsTabPage.Name = "ToolsModelsTabPage";
this.ToolsModelsTabPage.Padding = new System.Windows.Forms.Padding(3);
this.ToolsModelsTabPage.Size = new System.Drawing.Size(217, 500);
this.ToolsModelsTabPage.Size = new System.Drawing.Size(241, 500);
this.ToolsModelsTabPage.TabIndex = 0;
this.ToolsModelsTabPage.Text = "Models";
this.ToolsModelsTabPage.UseVisualStyleBackColor = true;
@ -438,26 +464,26 @@
//
// ToolsMaterialsTabPage
//
this.ToolsMaterialsTabPage.Controls.Add(this.TextureEditorButton);
this.ToolsMaterialsTabPage.Controls.Add(this.SaveSharedTexturesButton);
this.ToolsMaterialsTabPage.Controls.Add(this.TexturesTreeView);
this.ToolsMaterialsTabPage.Controls.Add(this.MaterialEditorButton);
this.ToolsMaterialsTabPage.Controls.Add(this.SaveAllTexturesButton);
this.ToolsMaterialsTabPage.Location = new System.Drawing.Point(4, 22);
this.ToolsMaterialsTabPage.Name = "ToolsMaterialsTabPage";
this.ToolsMaterialsTabPage.Padding = new System.Windows.Forms.Padding(3);
this.ToolsMaterialsTabPage.Size = new System.Drawing.Size(217, 500);
this.ToolsMaterialsTabPage.Size = new System.Drawing.Size(241, 500);
this.ToolsMaterialsTabPage.TabIndex = 1;
this.ToolsMaterialsTabPage.Text = "Materials";
this.ToolsMaterialsTabPage.UseVisualStyleBackColor = true;
//
// TextureEditorButton
// SaveSharedTexturesButton
//
this.TextureEditorButton.Location = new System.Drawing.Point(111, 3);
this.TextureEditorButton.Name = "TextureEditorButton";
this.TextureEditorButton.Size = new System.Drawing.Size(100, 23);
this.TextureEditorButton.TabIndex = 2;
this.TextureEditorButton.Text = "Texture editor...";
this.TextureEditorButton.UseVisualStyleBackColor = true;
this.TextureEditorButton.Click += new System.EventHandler(this.TextureEditorButton_Click);
this.SaveSharedTexturesButton.Location = new System.Drawing.Point(109, 3);
this.SaveSharedTexturesButton.Name = "SaveSharedTexturesButton";
this.SaveSharedTexturesButton.Size = new System.Drawing.Size(132, 23);
this.SaveSharedTexturesButton.TabIndex = 2;
this.SaveSharedTexturesButton.Text = "Save shared textures...";
this.SaveSharedTexturesButton.UseVisualStyleBackColor = true;
this.SaveSharedTexturesButton.Click += new System.EventHandler(this.SaveSharedTexturesButton_Click);
//
// TexturesTreeView
//
@ -467,25 +493,25 @@
this.TexturesTreeView.Location = new System.Drawing.Point(0, 32);
this.TexturesTreeView.Name = "TexturesTreeView";
this.TexturesTreeView.ShowRootLines = false;
this.TexturesTreeView.Size = new System.Drawing.Size(217, 468);
this.TexturesTreeView.Size = new System.Drawing.Size(241, 468);
this.TexturesTreeView.TabIndex = 1;
//
// MaterialEditorButton
// SaveAllTexturesButton
//
this.MaterialEditorButton.Location = new System.Drawing.Point(6, 3);
this.MaterialEditorButton.Name = "MaterialEditorButton";
this.MaterialEditorButton.Size = new System.Drawing.Size(100, 23);
this.MaterialEditorButton.TabIndex = 3;
this.MaterialEditorButton.Text = "Material editor...";
this.MaterialEditorButton.UseVisualStyleBackColor = true;
this.MaterialEditorButton.Click += new System.EventHandler(this.MaterialEditorButton_Click);
this.SaveAllTexturesButton.Location = new System.Drawing.Point(0, 3);
this.SaveAllTexturesButton.Name = "SaveAllTexturesButton";
this.SaveAllTexturesButton.Size = new System.Drawing.Size(108, 23);
this.SaveAllTexturesButton.TabIndex = 3;
this.SaveAllTexturesButton.Text = "Save all textures...";
this.SaveAllTexturesButton.UseVisualStyleBackColor = true;
this.SaveAllTexturesButton.Click += new System.EventHandler(this.SaveAllTexturesButton_Click);
//
// ToolsDetailsTabPage
//
this.ToolsDetailsTabPage.Controls.Add(this.DetailsPropertyGrid);
this.ToolsDetailsTabPage.Location = new System.Drawing.Point(4, 22);
this.ToolsDetailsTabPage.Name = "ToolsDetailsTabPage";
this.ToolsDetailsTabPage.Size = new System.Drawing.Size(217, 500);
this.ToolsDetailsTabPage.Size = new System.Drawing.Size(241, 500);
this.ToolsDetailsTabPage.TabIndex = 2;
this.ToolsDetailsTabPage.Text = "Details";
this.ToolsDetailsTabPage.UseVisualStyleBackColor = true;
@ -509,7 +535,7 @@
this.ToolsOptionsTabPage.Controls.Add(this.OptionsTabControl);
this.ToolsOptionsTabPage.Location = new System.Drawing.Point(4, 22);
this.ToolsOptionsTabPage.Name = "ToolsOptionsTabPage";
this.ToolsOptionsTabPage.Size = new System.Drawing.Size(217, 500);
this.ToolsOptionsTabPage.Size = new System.Drawing.Size(241, 500);
this.ToolsOptionsTabPage.TabIndex = 3;
this.ToolsOptionsTabPage.Text = "Options";
this.ToolsOptionsTabPage.UseVisualStyleBackColor = true;
@ -522,7 +548,7 @@
this.OptionsTabControl.Location = new System.Drawing.Point(0, 0);
this.OptionsTabControl.Name = "OptionsTabControl";
this.OptionsTabControl.SelectedIndex = 0;
this.OptionsTabControl.Size = new System.Drawing.Size(217, 500);
this.OptionsTabControl.Size = new System.Drawing.Size(241, 500);
this.OptionsTabControl.TabIndex = 26;
//
// OptionsRenderTabPage
@ -549,7 +575,7 @@
this.OptionsRenderTabPage.Location = new System.Drawing.Point(4, 22);
this.OptionsRenderTabPage.Name = "OptionsRenderTabPage";
this.OptionsRenderTabPage.Padding = new System.Windows.Forms.Padding(3);
this.OptionsRenderTabPage.Size = new System.Drawing.Size(209, 474);
this.OptionsRenderTabPage.Size = new System.Drawing.Size(233, 474);
this.OptionsRenderTabPage.TabIndex = 0;
this.OptionsRenderTabPage.Text = "Render";
this.OptionsRenderTabPage.UseVisualStyleBackColor = true;
@ -783,7 +809,6 @@
// OptionsLightingTabPage
//
this.OptionsLightingTabPage.Controls.Add(this.DeferredShadingCheckBox);
this.OptionsLightingTabPage.Controls.Add(this.LightEditorButton);
this.OptionsLightingTabPage.Controls.Add(this.HDLightsCheckBox);
this.OptionsLightingTabPage.Controls.Add(this.label19);
this.OptionsLightingTabPage.Controls.Add(this.HDRRenderingCheckBox);
@ -811,16 +836,6 @@
this.DeferredShadingCheckBox.UseVisualStyleBackColor = true;
this.DeferredShadingCheckBox.CheckedChanged += new System.EventHandler(this.DeferredShadingCheckBox_CheckedChanged);
//
// LightEditorButton
//
this.LightEditorButton.Location = new System.Drawing.Point(7, 214);
this.LightEditorButton.Name = "LightEditorButton";
this.LightEditorButton.Size = new System.Drawing.Size(90, 23);
this.LightEditorButton.TabIndex = 37;
this.LightEditorButton.Text = "Light editor...";
this.LightEditorButton.UseVisualStyleBackColor = true;
this.LightEditorButton.Click += new System.EventHandler(this.LightEditorButton_Click);
//
// HDLightsCheckBox
//
this.HDLightsCheckBox.AutoSize = true;
@ -932,7 +947,7 @@
this.ToolsDragPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.ToolsDragPanel.Cursor = System.Windows.Forms.Cursors.VSplit;
this.ToolsDragPanel.Location = new System.Drawing.Point(227, 0);
this.ToolsDragPanel.Location = new System.Drawing.Point(251, 0);
this.ToolsDragPanel.Name = "ToolsDragPanel";
this.ToolsDragPanel.Size = new System.Drawing.Size(4, 559);
this.ToolsDragPanel.TabIndex = 17;
@ -1046,9 +1061,9 @@
private System.Windows.Forms.Label label19;
private System.Windows.Forms.TrackBar TimeOfDayTrackBar;
private System.Windows.Forms.CheckBox SkeletonsCheckBox;
private System.Windows.Forms.Button TextureEditorButton;
private System.Windows.Forms.Button SaveSharedTexturesButton;
private System.Windows.Forms.CheckBox HDTexturesCheckBox;
private System.Windows.Forms.Button MaterialEditorButton;
private System.Windows.Forms.Button SaveAllTexturesButton;
private System.Windows.Forms.Panel MainToolbarPanel;
private System.Windows.Forms.ToolStrip MainToolbar;
private System.Windows.Forms.ToolStripSplitButton SaveButton;
@ -1066,7 +1081,6 @@
private System.Windows.Forms.TabPage OptionsLightingTabPage;
private System.Windows.Forms.CheckBox HDLightsCheckBox;
private System.Windows.Forms.CheckBox DeferredShadingCheckBox;
private System.Windows.Forms.Button LightEditorButton;
private System.Windows.Forms.ToolStripButton ToolbarMaterialEditorButton;
private System.Windows.Forms.ToolStripButton ToolbarTextureEditorButton;
private System.Windows.Forms.ToolStripButton ToolbarLightEditorButton;
@ -1075,5 +1089,9 @@
private System.Windows.Forms.ToolStripButton ToolbarRotateButton;
private System.Windows.Forms.ToolStripButton ToolbarScaleButton;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripMenuItem SaveAllTexturesMenuButton;
private System.Windows.Forms.ToolStripMenuItem SaveSharedTexturesMenuButton;
private System.Windows.Forms.FolderBrowserDialog FolderBrowserDialog;
}
}

View File

@ -1,6 +1,7 @@
using CodeWalker.GameFiles;
using CodeWalker.Properties;
using CodeWalker.Rendering;
using CodeWalker.Utils;
using CodeWalker.World;
using SharpDX;
using SharpDX.Direct3D11;
@ -1458,6 +1459,145 @@ namespace CodeWalker.Forms
private void ShowMaterialEditor()
{
DrawableBase drawable = null;
Dictionary<uint, Drawable> dict = null;
if ((Ydr != null) && (Ydr.Loaded))
{
drawable = Ydr.Drawable;
}
else if ((Ydd != null) && (Ydd.Loaded))
{
dict = Ydd.Dict;
}
else if ((Yft != null) && (Yft.Loaded))
{
drawable = Yft.Fragment?.Drawable;
}
else if ((Ypt != null) && (Ypt.Loaded))
{
//dict = Ypt.DrawableDict;
}
else
{
MessageBox.Show("Material editor not supported for the current file.");
return;
}
if (materialForm == null)
{
materialForm = new ModelMatForm(this);
if (drawable != null)
{
materialForm.LoadModel(drawable);
}
else if (dict != null)
{
materialForm.LoadModels(dict);
}
materialForm.Show(this);
}
else
{
if (materialForm.WindowState == FormWindowState.Minimized)
{
materialForm.WindowState = FormWindowState.Normal;
}
materialForm.Focus();
}
}
private void ShowTextureEditor()
{
TextureDictionary td = null;
if ((Ydr != null) && (Ydr.Loaded))
{
td = Ydr.Drawable?.ShaderGroup?.TextureDictionary;
}
else if ((Yft != null) && (Yft.Loaded))
{
td = Yft.Fragment?.Drawable?.ShaderGroup?.TextureDictionary;
}
else if ((Ypt != null) && (Ypt.Loaded))
{
td = Ypt?.PtfxList?.TextureDictionary;
}
if (td != null)
{
YtdForm f = new YtdForm(null, this);
f.Show(this);
f.LoadTexDict(td, fileName);
}
else
{
MessageBox.Show("Couldn't find embedded texture dict.");
}
}
private void ShowLightEditor()
{
DrawableBase drawable = null;
Dictionary<uint, Drawable> dict = null;
if ((Ydr != null) && (Ydr.Loaded))
{
drawable = Ydr.Drawable;
}
else if ((Ydd != null) && (Ydd.Loaded))
{
dict = Ydd.Dict;
}
else if ((Yft != null) && (Yft.Loaded))
{
drawable = Yft.Fragment?.Drawable;
}
else if ((Ypt != null) && (Ypt.Loaded))
{
//dict = Ypt.DrawableDict;
}
else
{
MessageBox.Show("Light editor not supported for the current file.");
}
if (lightForm == null)
{
lightForm = new ModelLightForm(this);
if (drawable != null)
{
lightForm.LoadModel(drawable);
}
else if (dict != null)
{
lightForm.LoadModels(dict);
}
editingLights = true;
Widget.Visible = true;
lightForm.Show(this);
}
else
{
if (lightForm.WindowState == FormWindowState.Minimized)
{
lightForm.WindowState = FormWindowState.Normal;
}
lightForm.Focus();
}
DeferredShadingCheckBox.Checked = true; //make sure we can see the lights we're editing (maybe this is bad for potatoes but meh)
}
public void OnLightFormClosed()
{
lightForm = null;
@ -1634,6 +1774,236 @@ namespace CodeWalker.Forms
private void SaveAllTextures(bool includeEmbedded)
{
if (gameFileCache == null)
{
MessageBox.Show("This operation requires GameFileCache to continue. This shouldn't happen!");
return;
}
if (FolderBrowserDialog.ShowDialogNew() != DialogResult.OK) return;
string folderpath = FolderBrowserDialog.SelectedPath;
if (!folderpath.EndsWith("\\")) folderpath += "\\";
var tryGetTextureFromYtd = new Func<uint, YtdFile, Texture>((texHash, ytd) =>
{
if (ytd == null) return null;
int tries = 0;
while (!ytd.Loaded && (tries < 500)) //wait upto ~5 sec
{
Thread.Sleep(10);
tries++;
}
if (ytd.Loaded)
{
return ytd.TextureDict?.Lookup(texHash);
}
return null;
});
var tryGetTexture = new Func<uint, uint, Texture>((texHash, txdHash) =>
{
if (txdHash != 0)
{
var ytd = gameFileCache.GetYtd(txdHash);
var tex = tryGetTextureFromYtd(texHash, ytd);
return tex;
}
return null;
});
var textures = new HashSet<Texture>();
var texturesMissing = new HashSet<string>();
var collectTextures = new Action<DrawableBase>((d) =>
{
if (includeEmbedded)
{
if (d?.ShaderGroup?.TextureDictionary?.Textures?.data_items != null)
{
foreach (var tex in d.ShaderGroup.TextureDictionary.Textures.data_items)
{
textures.Add(tex);
}
}
if ((d?.Owner is YptFile ypt) && (ypt.PtfxList?.TextureDictionary?.Textures?.data_items != null))
{
foreach (var tex in ypt.PtfxList.TextureDictionary.Textures.data_items)
{
textures.Add(tex);
}
return; //ypt's apparently only use embedded textures...
}
}
if (d?.ShaderGroup?.Shaders?.data_items == null) return;
var archhash = 0u;
if (d is Drawable dwbl)
{
var dname = dwbl.Name.ToLowerInvariant();
dname = dname.Replace(".#dr", "").Replace(".#dd", "");
archhash = JenkHash.GenHash(dname);
}
else if (d is FragDrawable fdbl)
{
var yft = fdbl.Owner as YftFile;
var fraghash = (MetaHash)(yft?.RpfFileEntry?.ShortNameHash ?? 0);
archhash = fraghash;
}
var arch = gameFileCache.GetArchetype(archhash);
if (arch == null)
{
arch = currentArchetype;
}
var txdHash = (arch != null) ? arch.TextureDict.Hash : archhash;
if ((txdHash == 0) && (archhash == 0))
{ }
foreach (var s in d.ShaderGroup.Shaders.data_items)
{
if (s?.ParametersList?.Parameters == null) continue;
foreach (var p in s.ParametersList.Parameters)
{
var t = p.Data as TextureBase;
if (t == null) continue;
var tex = t as Texture;
if (tex != null)
{
if (includeEmbedded)
{
textures.Add(tex);//probably redundant
}
}
else
{
var texhash = t.NameHash;
tex = tryGetTexture(texhash, txdHash);
if (tex == null)
{
var ptxdhash = gameFileCache.TryGetParentYtdHash(txdHash);
while ((ptxdhash != 0) && (tex == null))
{
tex = tryGetTexture(texhash, ptxdhash);
if (tex == null)
{
ptxdhash = gameFileCache.TryGetParentYtdHash(ptxdhash);
}
}
if (tex == null)
{
var ytd = gameFileCache.TryGetTextureDictForTexture(texhash);
tex = tryGetTextureFromYtd(texhash, ytd);
}
if (tex == null)
{
texturesMissing.Add(t.Name);
}
}
if (tex != null)
{
textures.Add(tex);
}
}
}
}
});
if (Ydr != null)
{
collectTextures(Ydr.Drawable);
}
if (Ydd?.Drawables != null)
{
foreach (var d in Ydd.Drawables)
{
collectTextures(d);
}
}
if (Yft?.Fragment != null)
{
var f = Yft.Fragment;
collectTextures(f.Drawable);
collectTextures(f.DrawableCloth);
if (f.DrawableArray?.data_items != null)
{
foreach (var d in f.DrawableArray.data_items)
{
collectTextures(d);
}
}
if (f.Cloths?.data_items != null)
{
foreach (var c in f.Cloths.data_items)
{
collectTextures(c.Drawable);
}
}
var fc = f.PhysicsLODGroup?.PhysicsLOD1?.Children?.data_items;
if (fc != null)
{
foreach (var fcc in fc)
{
collectTextures(fcc.Drawable1);
collectTextures(fcc.Drawable2);
}
}
}
if (Ypt?.DrawableDict != null)
{
foreach (var d in Ypt.DrawableDict.Values)
{
collectTextures(d);
}
}
var errordds = new List<string>();
var successcount = 0;
foreach (var tex in textures)
{
try
{
string fpath = folderpath + tex.Name + ".dds";
byte[] dds = DDSIO.GetDDSFile(tex);
File.WriteAllBytes(fpath, dds);
successcount++;
}
catch
{
errordds.Add(tex.Name ?? "???");
}
}
var sb = new StringBuilder();
if (successcount > 0)
{
sb.AppendLine(successcount.ToString() + " textures successfully exported.");
}
if (texturesMissing.Count > 0)
{
sb.AppendLine(texturesMissing.Count.ToString() + " textures weren't found!");
}
if (errordds.Count > 0)
{
sb.AppendLine(errordds.Count.ToString() + " textures couldn't be converted to .dds!");
}
if (sb.Length > 0)
{
MessageBox.Show(sb.ToString());
}
else
{
MessageBox.Show("No textures were found to export.");
}
}
@ -2167,142 +2537,14 @@ namespace CodeWalker.Forms
StatusStrip.Visible = StatusBarCheckBox.Checked;
}
private void TextureEditorButton_Click(object sender, EventArgs e)
private void SaveAllTexturesButton_Click(object sender, EventArgs e)
{
TextureDictionary td = null;
if ((Ydr != null) && (Ydr.Loaded))
{
td = Ydr.Drawable?.ShaderGroup?.TextureDictionary;
}
else if ((Yft != null) && (Yft.Loaded))
{
td = Yft.Fragment?.Drawable?.ShaderGroup?.TextureDictionary;
}
else if ((Ypt != null) && (Ypt.Loaded))
{
td = Ypt?.PtfxList?.TextureDictionary;
SaveAllTextures(true);
}
if (td != null)
private void SaveSharedTexturesButton_Click(object sender, EventArgs e)
{
YtdForm f = new YtdForm(null, this);
f.Show(this);
f.LoadTexDict(td, fileName);
}
else
{
MessageBox.Show("Couldn't find embedded texture dict.");
}
}
private void MaterialEditorButton_Click(object sender, EventArgs e)
{
DrawableBase drawable = null;
Dictionary<uint, Drawable> dict = null;
if ((Ydr != null) && (Ydr.Loaded))
{
drawable = Ydr.Drawable;
}
else if ((Ydd != null) && (Ydd.Loaded))
{
dict = Ydd.Dict;
}
else if ((Yft != null) && (Yft.Loaded))
{
drawable = Yft.Fragment?.Drawable;
}
else if ((Ypt != null) && (Ypt.Loaded))
{
//dict = Ypt.DrawableDict;
}
else
{
MessageBox.Show("Material editor not supported for the current file.");
return;
}
if (materialForm == null)
{
materialForm = new ModelMatForm(this);
if (drawable != null)
{
materialForm.LoadModel(drawable);
}
else if (dict != null)
{
materialForm.LoadModels(dict);
}
materialForm.Show(this);
}
else
{
if (materialForm.WindowState == FormWindowState.Minimized)
{
materialForm.WindowState = FormWindowState.Normal;
}
materialForm.Focus();
}
}
private void LightEditorButton_Click(object sender, EventArgs e)
{
DrawableBase drawable = null;
Dictionary<uint, Drawable> dict = null;
if ((Ydr != null) && (Ydr.Loaded))
{
drawable = Ydr.Drawable;
}
else if ((Ydd != null) && (Ydd.Loaded))
{
dict = Ydd.Dict;
}
else if ((Yft != null) && (Yft.Loaded))
{
drawable = Yft.Fragment?.Drawable;
}
else if ((Ypt != null) && (Ypt.Loaded))
{
//dict = Ypt.DrawableDict;
}
else
{
MessageBox.Show("Light editor not supported for the current file.");
}
if (lightForm == null)
{
lightForm = new ModelLightForm(this);
if (drawable != null)
{
lightForm.LoadModel(drawable);
}
else if (dict != null)
{
lightForm.LoadModels(dict);
}
editingLights = true;
Widget.Visible = true;
lightForm.Show(this);
}
else
{
if (lightForm.WindowState == FormWindowState.Minimized)
{
lightForm.WindowState = FormWindowState.Normal;
}
lightForm.Focus();
}
DeferredShadingCheckBox.Checked = true; //make sure we can see the lights we're editing (maybe this is bad for potatoes but meh)
SaveAllTextures(false);
}
private void SaveButton_ButtonClick(object sender, EventArgs e)
@ -2320,6 +2562,16 @@ namespace CodeWalker.Forms
Save(true);
}
private void SaveAllTexturesMenuButton_Click(object sender, EventArgs e)
{
SaveAllTextures(true);
}
private void SaveSharedTexturesMenuButton_Click(object sender, EventArgs e)
{
SaveAllTextures(false);
}
private void ClipDictComboBox_TextChanged(object sender, EventArgs e)
{
LoadClipDict(ClipDictComboBox.Text);
@ -2347,17 +2599,17 @@ namespace CodeWalker.Forms
private void ToolbarMaterialEditorButton_Click(object sender, EventArgs e)
{
MaterialEditorButton_Click(sender, e);
ShowMaterialEditor();
}
private void ToolbarTextureEditorButton_Click(object sender, EventArgs e)
{
TextureEditorButton_Click(sender, e);
ShowTextureEditor();
}
private void ToolbarLightEditorButton_Click(object sender, EventArgs e)
{
LightEditorButton_Click(sender, e);
ShowLightEditor();
}
private void ToolbarMoveButton_Click(object sender, EventArgs e)

View File

@ -130,19 +130,19 @@
<data name="ToolbarMaterialEditorButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAKmSURBVDhPjVPbTlpREOUL+jn8gIn3xHiPEW8YNHIIKiJq
rKAiQUtVij2aoqA0Ira1SSWRi1a8Ja0WqtZL40MrDaXxwfqoDz64emZA09Y+dJLJSfaZWbPWmr1lf8fl
5aX86urKKX3jUl6nM54+k6fL7sfNzc0DqcB78fMC0WgUS0sBzPvmMT09A8+MB8FgCGdnZ6Aaqk23pYIO
pAk7Jycn3Ph2ZRWrqxEEAyEsLLyGy+XGyMgo+vv7sbW5Bar9A4RQj48/w7/ox+bGFvZ29/Fp/wDb2zsI
h8LwSUzGxycwMGCBXq9HJBJhJrfN8vPzc6YbCoYRi8YQP/2GZPIHDg+PsL6+wSycz5wYtA7CYDBAUAvS
/ySByGVkzlpkDd5ZLwNEP8Tw9cspvieSODyQANbW7wCsVisDNKga4Ha7SYqTGMRJ44xk1uIbP0/8GNvF
3t4+3r/bZtC5OR9EcZwltLXpUV9fD41GQwziBHA9NDTEGokF+bC8vMJGBiRDX71cgGvKheHhEfT0GKHV
alFTU4OSkhICuGYAk6kXtkc2TEggHs9zNm3e9wKzEuDk5BTs9icwm81obzegsbERFRUVKCgouAOIWywW
GI1GNsk+aof4VGTKY44x2GyPpfWZ0dHRCUEQUF1djaKiItTW1qYkkBGksaWlBV2dXTAZTTyNsq+3D93d
D3l1arWam0pLS5GXlweHw3FnopxWQtSamprQrG1Ga6sOOp2OQQVBA5VKxZOpOT8/Hzk5OUgkEqk1pu+C
NxwOo7Kykg2qq1NCqVTyxCpFFcrLy1FYWIjc3FxkZGTA7/dTc+oiUdxe5UAggLKyMhQXF3OSVjKLKGdm
ZiI7O5ubqfaf74FQiZooijydGrKysqBQKFhzmvb9x/R7kC4yR/r+x3OWyX4BFI2EuwQc/DwAAAAASUVO
RK5CYII=
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAKwSURBVDhPbVPbTlpREOUL+jn+gIn3xHiPEW8YNHIIKiJq
rKAiQUtVij2aoqA0Ira1SSWRi1a8Ja0Wqla08aHVhtL4YH3R6EMfXD0zYG92kp3s7D1rzZo1e8v+jaur
q7Tr62vH5eXlycXFxQ9atKczukul3Y2bm5t7UoLn/Ps5IpEIFhf9mPPOYWpqGu5pNwKBIE5PT0E5lJuC
JYMOpArbR0dHDHy9vIKVlTAC/iDm51/C6XRheHgEfX192NzYBOX+RUKsh4cf4VvwYWN9E7s7e/iwt4+t
rW2EgiF4JSVjY+Po7zdDp9MhHA6zkltw2tnZGcsNBkKIRqI4Of6CROIbYrEDrK2tswrHEwcGLAPQ6/UQ
VIJ0nyCSNBmZsxpehWfGwwSRd1F8/nSMr/EEYvsSweraLwKLxcIE9cp6uFwuasUhI4epx2nJrIVXPq74
PrqD3d09vH2zxaSzs16I4hi30NqqQ11dHdRqNQgrozENDg5yj6SCfFhaWmYj/ZKhL57PwznpxNDQMLq7
DdBoNKiurkZxcTEIywRGYw+sD6wYl0jc7qds2pz3GWYkwomJSdhsj2AymdDWpkdDQwPKy8uRn5+fJCAZ
ZrMZBoOBTbKN2CA+FlnyqH0UVutDaXwmtLd3QBAEVFVVobCwEDU1NckWyAjqsbm5GZ0dnTAajFyNVm9P
L7q67vPoVCoVg0pKSpCbmwu73Z40kUZBIyFpjY2NaNI0oaVFC61Wy6SCoIZSqeTKBM7Ly0N2djbi8Xhy
jKm34AmFQqioqGCDamsVUCgUXLFSXomysjIUFBQgJycH6enp8Pl8vx8Sxe1T9vv9KC0tRVFRES/qlcwi
yRkZGcjKymIw5f73PxArSRNFkasTIDMzE3K5nHtOyb77mf4M6ovMIYdpTLRoT2d0l0pLhUz2EyCChEMn
c3MnAAAAAElFTkSuQmCC
</value>
</data>
<data name="ToolbarTextureEditorButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
@ -157,12 +157,12 @@
<data name="ToolbarLightEditorButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEcSURBVDhPnZI7boQwEIY5wh4hR8gRcpQcJQV9aqocJUdI
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEdSURBVDhPnZI7boQwEIY5wh4hR8gRcpQcJQV9aqocJUdI
w0NAESGEEAhwwav0+iO2Fzksq+SXRtY8/n/GY3suhBCXeZ7flmURwzDIruskp/IlcV12DMiq8KttW5kk
iQzD0FoURbKua0Q+dPlv0AHynuiaFjmehLHdzq4xCXWacsM0Tc/c1RT2fS/VlazhQybHXtZ1fdHUHxDY
C0Aqy1JmWSaLongsANi0KYrjeBNJ03Q78YmTH8eR2EXTblAC7yxpP4URMLHTl0BVJT+rqrLFCDRNs/nE
eebD7gZa5DvPc9sV43XY/inZQC3o1f0Pp+/vgi4s1LXDzd8DBN/3rf1LwLW/CoggCLbunFrgSacfg6+t
fp/gJ6qd3OnueVecFABPrjJDigAAAABJRU5ErkJggg==
eebD7gYk1YjfeZ7brhivw/ZPyQZqQa/ufzh9fxd0YaGuHW7+HiD4vm/tXwKu/VVABEGwdefUAk86/Rh8
bbVIwU9UO7nT3fOukLMAQJKEVWEAAAAASUVORK5CYII=
</value>
</data>
<data name="ToolbarMoveButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
@ -213,6 +213,9 @@
<metadata name="SaveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>397, 17</value>
</metadata>
<metadata name="FolderBrowserDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>528, 17</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAMAICAAAAAAGACoDAAANgAAABAQAAAAABgAaAMAAN4MAABAQAAAAAAYACgyAABGEAAAKAAAACAA