1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Seperate option to reset color params on import to prevent param data loss when being swapped

This commit is contained in:
KillzXGaming 2019-06-05 16:15:18 -04:00
parent 13b346ddde
commit 60e77f3dd1
13 changed files with 148 additions and 55 deletions

Binary file not shown.

View File

@ -1104,10 +1104,12 @@ namespace Bfres.Structs
if (IsEdited)
UpdateVertexData();
}
public FMAT GetMaterial(int index)
{
return materials.Values.ElementAt(index);
}
public void AddMaterials(string FileName, bool Replace = true)
{
string ext = System.IO.Path.GetExtension(FileName);
@ -1154,10 +1156,12 @@ namespace Bfres.Structs
break;
}
}
public override void OnClick(TreeView treeView)
{
UpdateEditor();
}
public void UpdateEditor(){
if (Parent != null)
((BFRES)Parent.Parent).LoadEditors(this);

View File

@ -239,6 +239,54 @@ namespace Bfres.Structs
((BFRES)Parent.Parent.Parent.Parent).LoadEditors(this);
}
public void TransformBindedBone(string BoneName)
{
if (Parent == null || VertexSkinCount > 1) return;
//Check if bone index obtains the right bone
if (VertexSkinCount == 0)
{
if (GetParentModel().Skeleton.bones[BoneIndex].Text != BoneName)
return;
}
TransformBindedBone();
}
//Transforms vertices given the bone
//Used when a bone is updated in the editor
public void TransformBindedBone()
{
if (Parent == null || VertexSkinCount > 1) return;
FMDL model = GetParentModel();
Matrix4 SingleBind = model.Skeleton.bones[BoneIndex].Transform;
for (int v = 0; v < vertices.Count; v++)
{
if (VertexSkinCount == 0)
{
vertices[v].pos = Vector3.TransformPosition(vertices[v].pos, SingleBind);
vertices[v].nrm = Vector3.TransformNormal(vertices[v].nrm, SingleBind);
}
else if (VertexSkinCount == 1)
{
int boneIndex = BoneIndex;
if (vertices[v].boneIds.Count > 0)
boneIndex = model.Skeleton.Node_Array[vertices[v].boneIds[0]];
Matrix4 SingleBindLocal = model.Skeleton.bones[boneIndex].Transform;
vertices[v].pos = Vector3.TransformPosition(vertices[v].pos, SingleBindLocal);
vertices[v].nrm = Vector3.TransformNormal(vertices[v].nrm, SingleBindLocal);
}
}
SaveVertexBuffer(GetResFileU() != null);
UpdateVertexData();
}
private void UVUnwrapPosition(object sender, EventArgs args)
{
Cursor.Current = Cursors.WaitCursor;
@ -307,6 +355,7 @@ namespace Bfres.Structs
UpdateVertexData();
Cursor.Current = Cursors.Default;
}
private void RecalculateNormals(object sender, EventArgs args)
{
Cursor.Current = Cursors.WaitCursor;
@ -315,6 +364,7 @@ namespace Bfres.Structs
UpdateVertexData();
Cursor.Current = Cursors.Default;
}
private void FillBitangentsAction(object sender, EventArgs args)
{
Cursor.Current = Cursors.WaitCursor;
@ -323,6 +373,7 @@ namespace Bfres.Structs
UpdateVertexData();
Cursor.Current = Cursors.Default;
}
private void FillTangentsAction(object sender, EventArgs args)
{
Cursor.Current = Cursors.WaitCursor;
@ -331,6 +382,7 @@ namespace Bfres.Structs
UpdateVertexData();
Cursor.Current = Cursors.Default;
}
private void CopyUVChannelAction(object sender, EventArgs args)
{
if (!vertexAttributes.Any(x => x.Name == "_u0"))
@ -531,7 +583,8 @@ namespace Bfres.Structs
STErrorDialog.Show($"Failed to generate tangents for mesh {Text}", "Tangent Calculation", ex.ToString());
}
}
if (settings.SetDefaultParamData)
if (settings.ResetColorParams)
{
foreach (var param in mat.matparam.Values)
{
@ -563,6 +616,20 @@ namespace Bfres.Structs
}
}
}
if (settings.ResetUVParams)
{
foreach (var param in mat.matparam.Values)
{
switch (param.Name)
{
case "gsys_bake_st0":
case "gsys_bake_st1":
param.ValueFloat = new float[] { 1, 1, 0, 0 };
break;
}
}
}
}
private void OpenMaterialEditor(object sender, EventArgs args)
{

View File

@ -709,42 +709,42 @@ namespace FirstPlugin
AlbedoCount++;
texture.Type = MatTexture.TextureType.Diffuse;
}
if (useSampler == "_a1")
else if (useSampler == "_a1")
{
m.HasDiffuseLayer = true;
texture.Type = MatTexture.TextureType.DiffuseLayer2;
}
if (useSampler == "_n0")
else if (useSampler == "_n0")
{
m.HasNormalMap = true;
texture.Type = MatTexture.TextureType.Normal;
}
if (useSampler == "_e0")
else if (useSampler == "_e0")
{
m.HasEmissionMap = true;
texture.Type = MatTexture.TextureType.Emission;
}
if (useSampler == "_s0")
else if (texture.SamplerName == "_s0" || useSampler == "_s0")
{
m.HasSpecularMap = true;
texture.Type = MatTexture.TextureType.Specular;
}
if (useSampler == "_x0")
else if (useSampler == "_x0")
{
m.HasSphereMap = true;
texture.Type = MatTexture.TextureType.SphereMap;
}
if (useSampler == "_b0")
else if (useSampler == "_b0")
{
m.HasShadowMap = true;
texture.Type = MatTexture.TextureType.Shadow;
}
if (useSampler == "_b1")
else if (useSampler == "_b1")
{
m.HasLightMap = true;
texture.Type = MatTexture.TextureType.Light;
}
if (texture.SamplerName == "bake0")
else if (texture.SamplerName == "bake0")
{
m.HasShadowMap = true;
texture.Type = MatTexture.TextureType.Shadow;

View File

@ -510,7 +510,7 @@ namespace FirstPlugin
m.HasEmissionMap = true;
texture.Type = MatTexture.TextureType.Emission;
}
else if (useSampler == "_s0")
else if (texture.SamplerName == "_s0" || useSampler == "_s0")
{
m.HasSpecularMap = true;
texture.Type = MatTexture.TextureType.Specular;

View File

@ -61,9 +61,11 @@
this.chkBoxFlipUvsY = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkBoxImportBones = new Switch_Toolbox.Library.Forms.STCheckBox();
this.panel8 = new Switch_Toolbox.Library.Forms.STPanel();
this.chkResetColorParams = new Switch_Toolbox.Library.Forms.STCheckBox();
this.ogSkinCountChkBox = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkPlaceHolderTextures = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkBoxImportMat = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkBoxParamDefaults = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkResetUVParams = new Switch_Toolbox.Library.Forms.STCheckBox();
this.chkBoxRotNegative90Y = new Switch_Toolbox.Library.Forms.STCheckBox();
this.textBoxMaterialPath = new Switch_Toolbox.Library.Forms.STTextBox();
this.chkBoxEnableWeightIndices = new Switch_Toolbox.Library.Forms.STCheckBox();
@ -87,7 +89,6 @@
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabPageAdvanced = new System.Windows.Forms.TabPage();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.ogSkinCountChkBox = new Switch_Toolbox.Library.Forms.STCheckBox();
this.contentContainer.SuspendLayout();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
@ -419,7 +420,7 @@
// chkBoxFlipUvsY
//
this.chkBoxFlipUvsY.AutoSize = true;
this.chkBoxFlipUvsY.Location = new System.Drawing.Point(3, 62);
this.chkBoxFlipUvsY.Location = new System.Drawing.Point(3, 39);
this.chkBoxFlipUvsY.Name = "chkBoxFlipUvsY";
this.chkBoxFlipUvsY.Size = new System.Drawing.Size(65, 17);
this.chkBoxFlipUvsY.TabIndex = 4;
@ -430,7 +431,7 @@
// chkBoxImportBones
//
this.chkBoxImportBones.AutoSize = true;
this.chkBoxImportBones.Location = new System.Drawing.Point(3, 85);
this.chkBoxImportBones.Location = new System.Drawing.Point(3, 62);
this.chkBoxImportBones.Name = "chkBoxImportBones";
this.chkBoxImportBones.Size = new System.Drawing.Size(88, 17);
this.chkBoxImportBones.TabIndex = 10;
@ -441,10 +442,11 @@
//
// panel8
//
this.panel8.Controls.Add(this.chkResetColorParams);
this.panel8.Controls.Add(this.ogSkinCountChkBox);
this.panel8.Controls.Add(this.chkPlaceHolderTextures);
this.panel8.Controls.Add(this.chkBoxImportMat);
this.panel8.Controls.Add(this.chkBoxParamDefaults);
this.panel8.Controls.Add(this.chkResetUVParams);
this.panel8.Controls.Add(this.chkBoxRotNegative90Y);
this.panel8.Controls.Add(this.textBoxMaterialPath);
this.panel8.Controls.Add(this.chkBoxEnableWeightIndices);
@ -468,10 +470,32 @@
this.panel8.Size = new System.Drawing.Size(524, 327);
this.panel8.TabIndex = 11;
//
// chkResetColorParams
//
this.chkResetColorParams.AutoSize = true;
this.chkResetColorParams.Location = new System.Drawing.Point(240, 204);
this.chkResetColorParams.Name = "chkResetColorParams";
this.chkResetColorParams.Size = new System.Drawing.Size(119, 17);
this.chkResetColorParams.TabIndex = 34;
this.chkResetColorParams.Text = "Reset Color Params";
this.chkResetColorParams.UseVisualStyleBackColor = true;
this.chkResetColorParams.CheckedChanged += new System.EventHandler(this.chkBoxSettings_CheckedChanged);
//
// ogSkinCountChkBox
//
this.ogSkinCountChkBox.AutoSize = true;
this.ogSkinCountChkBox.Location = new System.Drawing.Point(3, 16);
this.ogSkinCountChkBox.Name = "ogSkinCountChkBox";
this.ogSkinCountChkBox.Size = new System.Drawing.Size(234, 17);
this.ogSkinCountChkBox.TabIndex = 33;
this.ogSkinCountChkBox.Text = "Keep Original Skin Count (can help crashes)";
this.ogSkinCountChkBox.UseVisualStyleBackColor = true;
this.ogSkinCountChkBox.CheckedChanged += new System.EventHandler(this.ogSkinCountChkBox_CheckedChanged);
//
// chkPlaceHolderTextures
//
this.chkPlaceHolderTextures.AutoSize = true;
this.chkPlaceHolderTextures.Location = new System.Drawing.Point(3, 227);
this.chkPlaceHolderTextures.Location = new System.Drawing.Point(3, 204);
this.chkPlaceHolderTextures.Name = "chkPlaceHolderTextures";
this.chkPlaceHolderTextures.Size = new System.Drawing.Size(160, 17);
this.chkPlaceHolderTextures.TabIndex = 32;
@ -494,21 +518,21 @@
this.chkBoxImportMat.UseVisualStyleBackColor = true;
this.chkBoxImportMat.CheckedChanged += new System.EventHandler(this.chkBoxImportMat_CheckedChanged);
//
// chkBoxParamDefaults
// chkResetUVParams
//
this.chkBoxParamDefaults.AutoSize = true;
this.chkBoxParamDefaults.Location = new System.Drawing.Point(3, 39);
this.chkBoxParamDefaults.Name = "chkBoxParamDefaults";
this.chkBoxParamDefaults.Size = new System.Drawing.Size(117, 17);
this.chkBoxParamDefaults.TabIndex = 30;
this.chkBoxParamDefaults.Text = "Set Param Defaults";
this.chkBoxParamDefaults.UseVisualStyleBackColor = true;
this.chkBoxParamDefaults.CheckedChanged += new System.EventHandler(this.chkBoxSettings_CheckedChanged);
this.chkResetUVParams.AutoSize = true;
this.chkResetUVParams.Location = new System.Drawing.Point(240, 181);
this.chkResetUVParams.Name = "chkResetUVParams";
this.chkResetUVParams.Size = new System.Drawing.Size(110, 17);
this.chkResetUVParams.TabIndex = 30;
this.chkResetUVParams.Text = "Reset UV Params";
this.chkResetUVParams.UseVisualStyleBackColor = true;
this.chkResetUVParams.CheckedChanged += new System.EventHandler(this.chkBoxSettings_CheckedChanged);
//
// chkBoxRotNegative90Y
//
this.chkBoxRotNegative90Y.AutoSize = true;
this.chkBoxRotNegative90Y.Location = new System.Drawing.Point(3, 131);
this.chkBoxRotNegative90Y.Location = new System.Drawing.Point(3, 108);
this.chkBoxRotNegative90Y.Name = "chkBoxRotNegative90Y";
this.chkBoxRotNegative90Y.Size = new System.Drawing.Size(117, 17);
this.chkBoxRotNegative90Y.TabIndex = 29;
@ -608,7 +632,7 @@
// chkBoxRecalcNormals
//
this.chkBoxRecalcNormals.AutoSize = true;
this.chkBoxRecalcNormals.Location = new System.Drawing.Point(3, 177);
this.chkBoxRecalcNormals.Location = new System.Drawing.Point(3, 154);
this.chkBoxRecalcNormals.Name = "chkBoxRecalcNormals";
this.chkBoxRecalcNormals.Size = new System.Drawing.Size(124, 17);
this.chkBoxRecalcNormals.TabIndex = 18;
@ -635,7 +659,7 @@
this.chkBoxTransformMatrix.AutoSize = true;
this.chkBoxTransformMatrix.Checked = true;
this.chkBoxTransformMatrix.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkBoxTransformMatrix.Location = new System.Drawing.Point(3, 154);
this.chkBoxTransformMatrix.Location = new System.Drawing.Point(3, 131);
this.chkBoxTransformMatrix.Name = "chkBoxTransformMatrix";
this.chkBoxTransformMatrix.Size = new System.Drawing.Size(104, 17);
this.chkBoxTransformMatrix.TabIndex = 14;
@ -647,7 +671,7 @@
// chkBoxRot90Y
//
this.chkBoxRot90Y.AutoSize = true;
this.chkBoxRot90Y.Location = new System.Drawing.Point(3, 108);
this.chkBoxRot90Y.Location = new System.Drawing.Point(3, 85);
this.chkBoxRot90Y.Name = "chkBoxRot90Y";
this.chkBoxRot90Y.Size = new System.Drawing.Size(114, 17);
this.chkBoxRot90Y.TabIndex = 13;
@ -659,7 +683,7 @@
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.Location = new System.Drawing.Point(3, 203);
this.pictureBox1.Location = new System.Drawing.Point(3, 180);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(17, 17);
this.pictureBox1.TabIndex = 12;
@ -668,7 +692,7 @@
// checkBox9
//
this.checkBox9.AutoSize = true;
this.checkBox9.Location = new System.Drawing.Point(25, 204);
this.checkBox9.Location = new System.Drawing.Point(25, 181);
this.checkBox9.Name = "checkBox9";
this.checkBox9.Size = new System.Drawing.Size(130, 17);
this.checkBox9.TabIndex = 11;
@ -766,17 +790,6 @@
this.stPanel1.Size = new System.Drawing.Size(186, 65);
this.stPanel1.TabIndex = 17;
//
// ogSkinCountChkBox
//
this.ogSkinCountChkBox.AutoSize = true;
this.ogSkinCountChkBox.Location = new System.Drawing.Point(3, 16);
this.ogSkinCountChkBox.Name = "ogSkinCountChkBox";
this.ogSkinCountChkBox.Size = new System.Drawing.Size(234, 17);
this.ogSkinCountChkBox.TabIndex = 33;
this.ogSkinCountChkBox.Text = "Keep Original Skin Count (can help crashes)";
this.ogSkinCountChkBox.UseVisualStyleBackColor = true;
this.ogSkinCountChkBox.CheckedChanged += new System.EventHandler(this.ogSkinCountChkBox_CheckedChanged);
//
// BfresModelImportSettings
//
this.ClientSize = new System.Drawing.Size(547, 398);
@ -868,10 +881,11 @@
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxEnablePositions;
private Switch_Toolbox.Library.Forms.STTextBox textBoxMaterialPath;
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxRotNegative90Y;
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxParamDefaults;
private Switch_Toolbox.Library.Forms.STCheckBox chkResetUVParams;
private Switch_Toolbox.Library.Forms.STCheckBox chkBoxImportMat;
private Switch_Toolbox.Library.Forms.STPanel stPanel1;
private Switch_Toolbox.Library.Forms.STCheckBox chkPlaceHolderTextures;
private Switch_Toolbox.Library.Forms.STCheckBox ogSkinCountChkBox;
private Switch_Toolbox.Library.Forms.STCheckBox chkResetColorParams;
}
}

View File

@ -48,7 +48,9 @@ namespace FirstPlugin
public bool Rotate90DegreesNegativeX;
public bool RecalculateNormals;
public string ExternalMaterialPath;
public bool SetDefaultParamData;
public bool ResetUVParams;
public bool ResetColorParams;
public int SkinCountLimit;
public bool LimitSkinCount;
@ -75,7 +77,7 @@ namespace FirstPlugin
chkBoxEnableBitans.Checked = obj.HasUv0;
chkBoxEnableWeightIndices.Checked = obj.HasWeights;
chkBoxEnableVertColors.Checked = obj.HasVertColors;
chkBoxParamDefaults.Checked = true;
chkResetUVParams.Checked = true;
chkBoxTransformMatrix.Checked = true;
if (!obj.HasPos)
@ -298,7 +300,8 @@ namespace FirstPlugin
Rotate90DegreesY = chkBoxRot90Y.Checked;
Rotate90DegreesNegativeY = chkBoxRotNegative90Y.Checked;
RecalculateNormals = chkBoxRecalcNormals.Checked;
SetDefaultParamData = chkBoxParamDefaults.Checked;
ResetUVParams = chkResetUVParams.Checked;
ResetColorParams = chkResetColorParams.Checked;
ImportBones = chkBoxImportBones.Checked;
}

View File

@ -187,6 +187,12 @@ namespace FirstPlugin
activeBone.skeletonParent.reset();
activeBone.skeletonParent.update(true);
// var Model = ((FSKL)activeBone.skeletonParent).GetModelParent();
// GetBoneTransform(activeBone);
// for (int s = 0; s < Model.shapes.Count; s++)
// Model.shapes[s].TransformBindedBone(activeBone.Text);
LibraryGUI.Instance.UpdateViewport();
}
@ -211,7 +217,6 @@ namespace FirstPlugin
SetBoneTransform(activeBone);
}
GetBoneTransform(activeBone);
LibraryGUI.Instance.UpdateViewport();
}

View File

@ -93,14 +93,14 @@ namespace FirstPlugin
case Aampv1.ParamType.Uint: return $"{entry.HashString}: {(uint)entry.Value}";
case Aampv1.ParamType.Int: return $"{entry.HashString}: {(int)entry.Value}";
case Aampv1.ParamType.Float: return $"{entry.HashString}: {(float)entry.Value}";
case Aampv1.ParamType.String256: return $"{entry.HashString}: !str256 {(string)entry.Value}";
case Aampv1.ParamType.String32: return $"{entry.HashString}: !str32 {(string)entry.Value}";
case Aampv1.ParamType.String64: return $"{entry.HashString}: !str64 {(string)entry.Value}";
case Aampv1.ParamType.StringRef: return $"{entry.HashString}: !strRef {(string)entry.Value}";
case Aampv1.ParamType.Curve1: return $"{entry.HashString}: {WriteCurve((Aampv2.Curve[])entry.Value, 1)}";
case Aampv1.ParamType.Curve2: return $"{entry.HashString}: {WriteCurve((Aampv2.Curve[])entry.Value, 2)}";
case Aampv1.ParamType.Curve3: return $"{entry.HashString}: {WriteCurve((Aampv2.Curve[])entry.Value, 3)}";
case Aampv1.ParamType.Curve4: return $"{entry.HashString}: {WriteCurve((Aampv2.Curve[])entry.Value, 4)}";
case Aampv1.ParamType.String256: return $"{entry.HashString}: !str256 {((AampCommon.StringEntry)entry.Value).ToString()}";
case Aampv1.ParamType.String32: return $"{entry.HashString}: !str32 {((AampCommon.StringEntry)entry.Value).ToString()}";
case Aampv1.ParamType.String64: return $"{entry.HashString}: !str64 {((AampCommon.StringEntry)entry.Value).ToString()}";
case Aampv1.ParamType.StringRef: return $"{entry.HashString}: !strRef {((AampCommon.StringEntry)entry.Value).ToString()}";
case Aampv1.ParamType.Curve1: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 1)}";
case Aampv1.ParamType.Curve2: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 2)}";
case Aampv1.ParamType.Curve3: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 3)}";
case Aampv1.ParamType.Curve4: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 4)}";
default:
throw new Exception("Unsupported type! " + entry.ParamType);
}