mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-26 22:40:27 +00:00
Fix Format_8 encoding for weights
This commit is contained in:
parent
030f9effc2
commit
857e34fce7
3 changed files with 52 additions and 23 deletions
|
@ -461,6 +461,17 @@ namespace Bfres.Structs
|
||||||
return uvMaps;
|
return uvMaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VertexAttribute GetWeightAttribute(int index)
|
||||||
|
{
|
||||||
|
foreach (var attribute in vertexAttributes)
|
||||||
|
{
|
||||||
|
if (attribute.Name == $"_w{index}")
|
||||||
|
return attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void Rename(object sender, EventArgs args)
|
private void Rename(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
RenameDialog dialog = new RenameDialog();
|
RenameDialog dialog = new RenameDialog();
|
||||||
|
@ -1644,6 +1655,7 @@ namespace Bfres.Structs
|
||||||
float[] weightsA = new float[4];
|
float[] weightsA = new float[4];
|
||||||
int[] indicesA = new int[4];
|
int[] indicesA = new int[4];
|
||||||
|
|
||||||
|
|
||||||
if (vtx.boneWeights.Count >= 1)
|
if (vtx.boneWeights.Count >= 1)
|
||||||
weightsA[0] = vtx.boneWeights[0];
|
weightsA[0] = vtx.boneWeights[0];
|
||||||
if (vtx.boneWeights.Count >= 2)
|
if (vtx.boneWeights.Count >= 2)
|
||||||
|
@ -1653,6 +1665,44 @@ namespace Bfres.Structs
|
||||||
if (vtx.boneWeights.Count >= 4)
|
if (vtx.boneWeights.Count >= 4)
|
||||||
weightsA[3] = vtx.boneWeights[3];
|
weightsA[3] = vtx.boneWeights[3];
|
||||||
|
|
||||||
|
var WeightAttribute = GetWeightAttribute(0);
|
||||||
|
|
||||||
|
if (WeightAttribute != null)
|
||||||
|
{
|
||||||
|
if (WeightAttribute.Format == ResGFX.AttribFormat.Format_8_UNorm ||
|
||||||
|
WeightAttribute.Format == ResGFX.AttribFormat.Format_8_8_UNorm ||
|
||||||
|
WeightAttribute.Format == ResGFX.AttribFormat.Format_8_8_8_8_UNorm)
|
||||||
|
{
|
||||||
|
//Produce identical results for the weight output as BFRES_Vertex.py
|
||||||
|
//This should prevent encoding back and exploding
|
||||||
|
int MaxWeight = 255;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (vtx.boneWeights.Count < i + 1)
|
||||||
|
{
|
||||||
|
weightsA[i] = 0;
|
||||||
|
MaxWeight = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int weight = (int)(vtx.boneWeights[i] * 255);
|
||||||
|
if (vtx.boneWeights.Count == i + 1)
|
||||||
|
weight = MaxWeight;
|
||||||
|
|
||||||
|
if (weight >= MaxWeight)
|
||||||
|
{
|
||||||
|
weight = MaxWeight;
|
||||||
|
MaxWeight = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
MaxWeight -= weight;
|
||||||
|
|
||||||
|
weightsA[i] = weight / 255f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (vtx.boneIds.Count >= 1)
|
if (vtx.boneIds.Count >= 1)
|
||||||
indicesA[0] = vtx.boneIds[0];
|
indicesA[0] = vtx.boneIds[0];
|
||||||
if (vtx.boneIds.Count >= 2)
|
if (vtx.boneIds.Count >= 2)
|
||||||
|
|
|
@ -274,29 +274,8 @@ namespace FirstPlugin
|
||||||
{
|
{
|
||||||
foreach (string bn in obj.bones[v])
|
foreach (string bn in obj.bones[v])
|
||||||
obj.vertices[v].boneNames.Add(bn);
|
obj.vertices[v].boneNames.Add(bn);
|
||||||
|
|
||||||
//Produce identical results for the weight output as BFRES_Vertex.py
|
|
||||||
//This should prevent encoding back and exploding
|
|
||||||
float MaxWeight = 1.0f;
|
|
||||||
int i = 0;
|
|
||||||
foreach (float f in obj.weightsT[v])
|
foreach (float f in obj.weightsT[v])
|
||||||
{
|
obj.vertices[v].boneWeights.Add(f);
|
||||||
float weight = f;
|
|
||||||
if (i + 1 == obj.weightsT.Count)
|
|
||||||
weight = MaxWeight;
|
|
||||||
|
|
||||||
if (weight >= MaxWeight)
|
|
||||||
{
|
|
||||||
weight = MaxWeight;
|
|
||||||
MaxWeight = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
MaxWeight -= weight;
|
|
||||||
|
|
||||||
obj.vertices[v].boneWeights.Add(weight);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int vID = 0;
|
int vID = 0;
|
||||||
|
|
|
@ -312,7 +312,7 @@ namespace FirstPlugin
|
||||||
comboBoxFormatWeights.Items.Add(AttribFormat.Format_16_16_UNorm);
|
comboBoxFormatWeights.Items.Add(AttribFormat.Format_16_16_UNorm);
|
||||||
comboBoxFormatWeights.Items.Add(AttribFormat.Format_8_8_UNorm);
|
comboBoxFormatWeights.Items.Add(AttribFormat.Format_8_8_UNorm);
|
||||||
comboBoxFormatWeights.Items.Add(AttribFormat.Format_8_UNorm);
|
comboBoxFormatWeights.Items.Add(AttribFormat.Format_8_UNorm);
|
||||||
comboBoxFormatWeights.SelectedIndex = 0;
|
comboBoxFormatWeights.SelectedIndex = 2;
|
||||||
|
|
||||||
comboBoxFormatTangents.Items.Add(AttribFormat.Format_32_32_32_32_Single);
|
comboBoxFormatTangents.Items.Add(AttribFormat.Format_32_32_32_32_Single);
|
||||||
comboBoxFormatTangents.Items.Add(AttribFormat.Format_16_16_16_16_Single);
|
comboBoxFormatTangents.Items.Add(AttribFormat.Format_16_16_16_16_Single);
|
||||||
|
|
Loading…
Reference in a new issue