1
0
mirror of synced 2024-11-28 09:20:57 +01:00

Improvements to layout material editing.

Tev stages can be added/removed for bclyt and brlyt.
Fixed adding new textures to brlyt.
Fixed setting material colors for window panes for bclyt/brlyt.
Fixed alpha op enum for brlyt tev stages.
This commit is contained in:
KillzXGaming 2020-02-15 13:54:52 -05:00
parent 69ab4e0eaf
commit efd98b3bac
12 changed files with 274 additions and 70 deletions

View File

@ -153,6 +153,30 @@ namespace LayoutBXLYT
// private List<SectionCommon> Sections;
// public List<PAN1> Panes = new List<PAN1>();
public override int AddFont(string name)
{
if (!FontList.Fonts.Contains(name))
FontList.Fonts.Add(name);
return FontList.Fonts.IndexOf(name);
}
public override int AddTexture(string name)
{
if (!TextureList.Textures.Contains(name))
TextureList.Textures.Add(name);
return TextureList.Textures.IndexOf(name);
}
public override void RemoveTexture(string name)
{
if (TextureList.Textures.Contains(name))
TextureList.Textures.Remove(name);
RemoveTextureReferences(name);
}
public int TotalPaneCount()
{
int panes = GetPanes().Count;

View File

@ -70,7 +70,7 @@ namespace LayoutBXLYT.Revolution
public TevSwapModeTable TevSwapModeTable { get; set; } = new TevSwapModeTable();
public List<BxlytTextureTransform> IndirectTexTransforms { get; set; }
public List<IndirectTextureOrderEntry> IndirectTextureOrderEntries { get; set; }
public List<IndirectStage> IndirectStages { get; set; }
private uint flags;
@ -106,7 +106,7 @@ namespace LayoutBXLYT.Revolution
TextureTransforms = new BxlytTextureTransform[0];
TexCoordGens = new List<TexCoordGenEntry>();
IndirectTexTransforms = new List<BxlytTextureTransform>();
IndirectTextureOrderEntries = new List<IndirectTextureOrderEntry>();
IndirectStages = new List<IndirectStage>();
TevSwapModeTable = new TevSwapModeTable();
ChanControl = new ChanCtrl();
BlackColor = new STColor8(0, 0, 0, 0);
@ -144,7 +144,7 @@ namespace LayoutBXLYT.Revolution
AlphaCompare = new AlphaCompare();
TexCoordGens = new List<TexCoordGenEntry>();
IndirectTexTransforms = new List<BxlytTextureTransform>();
IndirectTextureOrderEntries = new List<IndirectTextureOrderEntry>();
IndirectStages = new List<IndirectStage>();
Name = reader.ReadString(0x14, true);
@ -197,7 +197,7 @@ namespace LayoutBXLYT.Revolution
IndirectTexTransforms.Add(new BxlytTextureTransform(reader));
for (int i = 0; i < indTexOrderCount; i++)
IndirectTextureOrderEntries.Add(new IndirectTextureOrderEntry(reader));
IndirectStages.Add(new IndirectStage(reader));
for (int i = 0; i < tevStagesCount; i++)
TevStages[i] = new TevStage(reader, header);
@ -234,7 +234,7 @@ namespace LayoutBXLYT.Revolution
flags |= (1 << 23);
flags |= (uint)((TevStages.Length & 31) << 18);
flags |= (uint)((IndirectTextureOrderEntries.Count & 0x7) << 15);
flags |= (uint)((IndirectStages.Count & 0x7) << 15);
flags |= (uint)((IndirectTexTransforms.Count & 0x3) << 13);
if (HasTevSwapTable)
flags |= (1 << 12);
@ -273,8 +273,8 @@ namespace LayoutBXLYT.Revolution
for (int i = 0; i < IndirectTexTransforms.Count; i++)
IndirectTexTransforms[i].Write(writer);
for (int i = 0; i < IndirectTextureOrderEntries.Count; i++)
IndirectTextureOrderEntries[i].Write(writer);
for (int i = 0; i < IndirectStages.Count; i++)
IndirectStages[i].Write(writer);
for (int i = 0; i < TevStages.Length; i++)
((TevStage)TevStages[i]).Write(writer);

View File

@ -84,10 +84,17 @@ namespace LayoutBXLYT.Revolution
public enum TevAlphaOp
{
And,//ALPHAOP_AND = 0,
Or,//ALPHAOP_OR,
ExclusiveOr,//ALPHAOP_XOR,
InverseExclusiveOr//ALPHAOP_XNOR
Add = 0,
Subtract = 1,
CompR8Greater = 8,
CompR8Equal = 9,
CompGR16Greater = 10,
CompGR16Equal = 11,
CompBGR24Greater = 12,
CompBGR24Equal = 13,
CompA8Greater = 14,
CompA8Equal = 15,
}
public enum TevScale

View File

@ -7,14 +7,14 @@ using Toolbox.Library.IO;
namespace LayoutBXLYT.Revolution
{
public class IndirectTextureOrderEntry
public class IndirectStage
{
public byte TexCoord { get; set; }
public byte TexMap { get; set; }
public byte ScaleS { get; set; }
public byte ScaleT { get; set; }
public IndirectTextureOrderEntry(FileReader reader)
public IndirectStage(FileReader reader)
{
TexCoord = reader.ReadByte();
TexMap = reader.ReadByte();

View File

@ -80,7 +80,48 @@ namespace LayoutBXLYT.Revolution
[Category("Indirect Texturing")]
public IndTexAlphaSel Alpha { get; set; }
public TevStage(FileReader reader, BxlytHeader header)
public TevStage()
{
TexCoord = TexCoordID.TexCoord0;
Color = 255;
TexMap = TexMapID.TexMap0;
RasSel = TevSwapSel.Swap0;
TexSel = TevSwapSel.Swap0;
ColorA = ColorArg.Zero;
ColorB = ColorArg.Zero;
ColorC = ColorArg.Zero;
ColorD = ColorArg.Zero;
ColorOp = TevColorOp.Add;
ColorBias = Bias.Zero;
ColorScale = TevScale.MultiplyBy1;
ColorClamp = true;
ColorRegID = TevColorRegID.OutputColor;
ColorConstantSel = TevKColorSel.Constant1_1;
AlphaA = AlphaArg.Zero;
AlphaB = AlphaArg.Zero;
AlphaC = AlphaArg.Zero;
AlphaD = AlphaArg.Zero;
AlphaOp = TevAlphaOp.Add;
AlphaBias = Bias.Zero;
AlphaScale = TevScale.MultiplyBy1;
AlphaClamp = true;
AlphaRegID = TevAlphaRegID.OutputAlpha;
AlphaConstantSel = TevKAlphaSel.Constant1_1;
TexID = 0;
Format = IndTexFormat.F_8_Bit_Offsets;
IndBias = Bias.Zero;
Matrix = IndTexMtxID.Matrix0;
WrapS = IndTexWrap.NoWrap;
WrapT = IndTexWrap.NoWrap;
UsePreviousStage = 0;
UnmodifiedLOD = 0;
Alpha = IndTexAlphaSel.Off;
}
public TevStage(FileReader reader, BxlytHeader header)
{
TexCoord = (TexCoordID)reader.ReadByte();
Color = reader.ReadByte();

View File

@ -291,7 +291,7 @@
<Compile Include="FileFormats\Layout\Rev\Materials\AlphaCompare.cs" />
<Compile Include="FileFormats\Layout\Rev\Materials\ChanCtrl.cs" />
<Compile Include="FileFormats\Layout\Rev\Materials\Enums.cs" />
<Compile Include="FileFormats\Layout\Rev\Materials\IndirectTextureOrderEntry.cs" />
<Compile Include="FileFormats\Layout\Rev\Materials\IndirectStage.cs" />
<Compile Include="FileFormats\Layout\Rev\Materials\TevSwapModeTable.cs" />
<Compile Include="FileFormats\Layout\Rev\Materials\TexCoordGenEntry.cs" />
<Compile Include="FileFormats\Layout\Rev\Materials\TextureRef.cs" />

View File

@ -31,6 +31,8 @@
this.stPropertyGrid1 = new Toolbox.Library.Forms.STPropertyGrid();
this.tevStageCB = new Toolbox.Library.Forms.STComboBox();
this.stageCounterLbl = new Toolbox.Library.Forms.STLabel();
this.btnRemove = new Toolbox.Library.Forms.STButton();
this.btnAdd = new Toolbox.Library.Forms.STButton();
this.SuspendLayout();
//
// stPropertyGrid1
@ -68,12 +70,36 @@
this.stageCounterLbl.TabIndex = 2;
this.stageCounterLbl.Text = "Stage 0 of 5";
//
// PaneMatRevTevEditor
// btnRemove
//
this.btnRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnRemove.Location = new System.Drawing.Point(286, 11);
this.btnRemove.Name = "btnRemove";
this.btnRemove.Size = new System.Drawing.Size(31, 23);
this.btnRemove.TabIndex = 6;
this.btnRemove.Text = "-";
this.btnRemove.UseVisualStyleBackColor = false;
this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
//
// btnAdd
//
this.btnAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnAdd.Location = new System.Drawing.Point(249, 11);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(31, 23);
this.btnAdd.TabIndex = 5;
this.btnAdd.Text = "+";
this.btnAdd.UseVisualStyleBackColor = false;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// PaneMatCTRTevEditor
//
this.Controls.Add(this.btnRemove);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.stageCounterLbl);
this.Controls.Add(this.tevStageCB);
this.Controls.Add(this.stPropertyGrid1);
this.Name = "PaneMatRevTevEditor";
this.Name = "PaneMatCTRTevEditor";
this.Size = new System.Drawing.Size(421, 391);
this.ResumeLayout(false);
this.PerformLayout();
@ -85,5 +111,7 @@
private Toolbox.Library.Forms.STPropertyGrid stPropertyGrid1;
private Toolbox.Library.Forms.STComboBox tevStageCB;
private Toolbox.Library.Forms.STLabel stageCounterLbl;
private Toolbox.Library.Forms.STButton btnRemove;
private Toolbox.Library.Forms.STButton btnAdd;
}
}

View File

@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LayoutBXLYT.Revolution;
using Toolbox.Library.IO;
namespace LayoutBXLYT.CTR
{
@ -16,8 +17,6 @@ namespace LayoutBXLYT.CTR
private PaneEditor ParentEditor;
private Material ActiveMaterial;
private bool loaded = false;
public PaneMatCTRTevEditor()
{
InitializeComponent();
@ -28,18 +27,24 @@ namespace LayoutBXLYT.CTR
ParentEditor = paneEditor;
ActiveMaterial = material;
tevStageCB.Items.Clear();
stPropertyGrid1.LoadProperty(null);
stageCounterLbl.Text = $"Stage 0 of {material.TevStages.Length}";
for (int i = 0; i < material.TevStages.Length; i++)
tevStageCB.Items.Add($"Stage[[{i}]");
if (tevStageCB.Items.Count > 0)
tevStageCB.SelectedIndex = 0;
UpdateMaterial(0);
}
private void tevStageCB_SelectedIndexChanged(object sender, EventArgs e) {
private void UpdateMaterial(int stageIndex)
{
tevStageCB.Items.Clear();
stageCounterLbl.Text = $"Stage 0 of {ActiveMaterial.TevStages.Length}";
for (int i = 0; i < ActiveMaterial.TevStages.Length; i++)
tevStageCB.Items.Add($"Stage[[{i}]");
if (tevStageCB.Items.Count > stageIndex)
tevStageCB.SelectedIndex = stageIndex;
}
private void tevStageCB_SelectedIndexChanged(object sender, EventArgs e)
{
if (tevStageCB.SelectedIndex == -1)
return;
@ -49,12 +54,40 @@ namespace LayoutBXLYT.CTR
LoadTevStage((TevStage)ActiveMaterial.TevStages[index]);
}
private void LoadTevStage(TevStage stage) {
private void LoadTevStage(TevStage stage)
{
stPropertyGrid1.LoadProperty(stage, OnPropertyChanged);
}
private void OnPropertyChanged() {
private void OnPropertyChanged()
{
ParentEditor.PropertyChanged?.Invoke(EventArgs.Empty, null);
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (ActiveMaterial.TevStages.Length < 3)
{
ActiveMaterial.TevStages = ActiveMaterial.TevStages.AddToArray(new TevStage());
UpdateMaterial(ActiveMaterial.TevStages.Length - 1);
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
int index = tevStageCB.SelectedIndex;
if (index != -1)
{
ActiveMaterial.TevStages = ActiveMaterial.TevStages.RemoveAt(index);
UpdateMaterial(ActiveMaterial.TevStages.Length - 1);
if (ActiveMaterial.TevStages.Length == 0)
{
tevStageCB.Items.Clear();
tevStageCB.SelectedIndex = -1;
stPropertyGrid1.LoadProperty(null);
}
}
}
}
}

View File

@ -60,30 +60,35 @@ namespace LayoutBXLYT.CTR
{
((ColorAlphaBox)sender).Color = colorDlg.NewColor;
ApplyColors(ActiveMaterial, sender);
//Apply to all selected panes
foreach (BasePane pane in ParentEditor.SelectedPanes)
{
var mat = pane.TryGetActiveMaterial() as CTR.Material;
if (mat != null)
{
if (sender == whiteColorPB)
mat.WhiteColor.Color = colorDlg.NewColor;
else if (sender == blackColorBP)
mat.BlackColor.Color = colorDlg.NewColor;
else if (sender == tevColor1PB)
mat.TevConstantColors[0].Color = colorDlg.NewColor;
else if (sender == tevColor2PB)
mat.TevConstantColors[1].Color = colorDlg.NewColor;
else if (sender == tevColor3PB)
mat.TevConstantColors[2].Color = colorDlg.NewColor;
else if (sender == tevColor4PB)
mat.TevConstantColors[3].Color = colorDlg.NewColor;
}
ApplyColors(mat, sender);
}
ParentEditor.PropertyChanged?.Invoke(sender, e);
};
colorDlg.Show();
}
private void ApplyColors(Material mat, object sender)
{
if (sender == whiteColorPB)
mat.WhiteColor.Color = colorDlg.NewColor;
else if (sender == blackColorBP)
mat.BlackColor.Color = colorDlg.NewColor;
else if (sender == tevColor1PB)
mat.TevConstantColors[0].Color = colorDlg.NewColor;
else if (sender == tevColor2PB)
mat.TevConstantColors[1].Color = colorDlg.NewColor;
else if (sender == tevColor3PB)
mat.TevConstantColors[2].Color = colorDlg.NewColor;
else if (sender == tevColor4PB)
mat.TevConstantColors[3].Color = colorDlg.NewColor;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Toolbox.Library;
using Toolbox.Library.Forms;
using LayoutBXLYT.Revolution;
@ -63,28 +63,14 @@ namespace LayoutBXLYT
{
((ColorAlphaBox)sender).Color = colorDlg.NewColor;
ApplyColors(ActiveMaterial, sender);
//Apply to all selected panes
foreach (BasePane pane in ParentEditor.SelectedPanes)
{
var mat = pane.TryGetActiveMaterial() as Revolution.Material;
if (mat != null)
{
if (sender == whiteColorPB)
mat.WhiteColor.Color = colorDlg.NewColor;
else if (sender == blackColorBP)
mat.BlackColor.Color = colorDlg.NewColor;
else if (sender == materialColorPB)
mat.MatColor.Color = colorDlg.NewColor;
else if (sender == colorReg3PB)
mat.ColorRegister3.Color = colorDlg.NewColor;
else if (sender == tevColor1PB)
mat.TevColor1.Color = colorDlg.NewColor;
else if (sender == tevColor2PB)
mat.TevColor2.Color = colorDlg.NewColor;
else if (sender == tevColor3PB)
mat.TevColor3.Color = colorDlg.NewColor;
else if (sender == tevColor4PB)
mat.TevColor4.Color = colorDlg.NewColor;
if (mat != null) {
ApplyColors(mat, sender);
}
}
@ -92,5 +78,31 @@ namespace LayoutBXLYT
};
colorDlg.Show();
}
private void ApplyColors(Material mat, object sender)
{
if (sender == whiteColorPB)
mat.WhiteColor.Color = colorDlg.NewColor;
else if (sender == blackColorBP)
mat.BlackColor.Color = colorDlg.NewColor;
else if (sender == materialColorPB)
mat.MatColor.Color = colorDlg.NewColor;
else if (sender == colorReg3PB)
mat.ColorRegister3.Color = colorDlg.NewColor;
else if (sender == tevColor1PB)
mat.TevColor1.Color = colorDlg.NewColor;
else if (sender == tevColor2PB)
mat.TevColor2.Color = colorDlg.NewColor;
else if (sender == tevColor3PB)
mat.TevColor3.Color = colorDlg.NewColor;
else if (sender == tevColor4PB)
mat.TevColor4.Color = colorDlg.NewColor;
if (!mat.HasMaterialColor && mat.MatColor != STColor8.White) {
mat.HasMaterialColor = true;
mat.Shader.Compile();
}
}
}
}

View File

@ -31,6 +31,8 @@
this.stPropertyGrid1 = new Toolbox.Library.Forms.STPropertyGrid();
this.tevStageCB = new Toolbox.Library.Forms.STComboBox();
this.stageCounterLbl = new Toolbox.Library.Forms.STLabel();
this.btnAdd = new Toolbox.Library.Forms.STButton();
this.btnRemove = new Toolbox.Library.Forms.STButton();
this.SuspendLayout();
//
// stPropertyGrid1
@ -68,8 +70,32 @@
this.stageCounterLbl.TabIndex = 2;
this.stageCounterLbl.Text = "Stage 0 of 5";
//
// btnAdd
//
this.btnAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnAdd.Location = new System.Drawing.Point(244, 10);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(31, 23);
this.btnAdd.TabIndex = 3;
this.btnAdd.Text = "+";
this.btnAdd.UseVisualStyleBackColor = false;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnRemove
//
this.btnRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnRemove.Location = new System.Drawing.Point(281, 10);
this.btnRemove.Name = "btnRemove";
this.btnRemove.Size = new System.Drawing.Size(31, 23);
this.btnRemove.TabIndex = 4;
this.btnRemove.Text = "-";
this.btnRemove.UseVisualStyleBackColor = false;
this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
//
// PaneMatRevTevEditor
//
this.Controls.Add(this.btnRemove);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.stageCounterLbl);
this.Controls.Add(this.tevStageCB);
this.Controls.Add(this.stPropertyGrid1);
@ -85,5 +111,7 @@
private Toolbox.Library.Forms.STPropertyGrid stPropertyGrid1;
private Toolbox.Library.Forms.STComboBox tevStageCB;
private Toolbox.Library.Forms.STLabel stageCounterLbl;
private Toolbox.Library.Forms.STButton btnAdd;
private Toolbox.Library.Forms.STButton btnRemove;
}
}

View File

@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LayoutBXLYT.Revolution;
using Toolbox.Library.IO;
namespace LayoutBXLYT.Revolution
{
@ -16,8 +17,6 @@ namespace LayoutBXLYT.Revolution
private PaneEditor ParentEditor;
private Material ActiveMaterial;
private bool loaded = false;
public PaneMatRevTevEditor()
{
InitializeComponent();
@ -28,15 +27,20 @@ namespace LayoutBXLYT.Revolution
ParentEditor = paneEditor;
ActiveMaterial = material;
tevStageCB.Items.Clear();
stPropertyGrid1.LoadProperty(null);
UpdateMaterial(0);
}
stageCounterLbl.Text = $"Stage 0 of {material.TevStages.Length}";
for (int i = 0; i < material.TevStages.Length; i++)
private void UpdateMaterial(int stageIndex)
{
tevStageCB.Items.Clear();
stageCounterLbl.Text = $"Stage 0 of {ActiveMaterial.TevStages.Length}";
for (int i = 0; i < ActiveMaterial.TevStages.Length; i++)
tevStageCB.Items.Add($"Stage[[{i}]");
if (tevStageCB.Items.Count > 0)
tevStageCB.SelectedIndex = 0;
if (tevStageCB.Items.Count > stageIndex)
tevStageCB.SelectedIndex = stageIndex;
}
private void tevStageCB_SelectedIndexChanged(object sender, EventArgs e) {
@ -57,5 +61,27 @@ namespace LayoutBXLYT.Revolution
ActiveMaterial.Shader.Compile();
ParentEditor.PropertyChanged?.Invoke(EventArgs.Empty, null);
}
private void btnAdd_Click(object sender, EventArgs e) {
if (ActiveMaterial.TevStages.Length < 3) {
ActiveMaterial.TevStages = ActiveMaterial.TevStages.AddToArray(new TevStage());
UpdateMaterial(ActiveMaterial.TevStages.Length - 1);
}
}
private void btnRemove_Click(object sender, EventArgs e)
{
int index = tevStageCB.SelectedIndex;
if (index != -1) {
ActiveMaterial.TevStages = ActiveMaterial.TevStages.RemoveAt(index);
UpdateMaterial(ActiveMaterial.TevStages.Length - 1);
if (ActiveMaterial.TevStages.Length == 0) {
tevStageCB.Items.Clear();
tevStageCB.SelectedIndex = -1;
stPropertyGrid1.LoadProperty(null);
}
}
}
}
}