mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
fix skin indexes
This commit is contained in:
parent
b2ecc65885
commit
1f69f476f9
@ -1076,8 +1076,7 @@ namespace Unity_Studio
|
||||
m_BoneIndices.m_BitSize = a_Stream.ReadByte();
|
||||
a_Stream.Position += 3; //4 byte alignment
|
||||
|
||||
//how the hell does this work??
|
||||
if (m_BoneIndices.m_NumItems > 0 && m_BoneIndices.m_NumItems == m_Weights.m_NumItems && (bool)Properties.Settings.Default["exportDeformers"])
|
||||
if (m_BoneIndices.m_NumItems > 0 && (bool)Properties.Settings.Default["exportDeformers"])
|
||||
{
|
||||
uint[] m_Weights_Unpacked = UnpackBitVector(m_Weights);
|
||||
int bitmax = 0;
|
||||
@ -1085,18 +1084,73 @@ namespace Unity_Studio
|
||||
|
||||
uint[] m_BoneIndices_Unpacked = UnpackBitVector(m_BoneIndices);
|
||||
|
||||
m_Skin = new List<BoneInfluence>[m_BoneIndices.m_NumItems / 4];
|
||||
m_Skin = new List<BoneInfluence>[m_VertexCount];
|
||||
for (int s = 0; s < m_Skin.Length; s++)
|
||||
{
|
||||
m_Skin[s] = new List<BoneInfluence>();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
m_Skin[s].Add(new BoneInfluence()
|
||||
{
|
||||
weight = (float)((double)m_Weights_Unpacked[s * 4 + i] / bitmax),
|
||||
boneIndex = (int)m_BoneIndices_Unpacked[s * 4 + i]
|
||||
});
|
||||
m_Skin[s] = new List<BoneInfluence>(4);
|
||||
}
|
||||
|
||||
int inflCount = m_Weights.m_NumItems;
|
||||
int vertIndex = 0;
|
||||
int weightIndex = 0;
|
||||
int bonesIndex = 0;
|
||||
for(weightIndex = 0; weightIndex < inflCount; vertIndex++)
|
||||
{
|
||||
int inflSum = 0;
|
||||
int j;
|
||||
for(j = 0; j < 4; j++)
|
||||
{
|
||||
int curWeight = 0;
|
||||
if(j == 3)
|
||||
{
|
||||
curWeight = 31 - inflSum;
|
||||
}
|
||||
else
|
||||
{
|
||||
curWeight = (int)m_Weights_Unpacked[weightIndex];
|
||||
weightIndex++;
|
||||
inflSum += curWeight;
|
||||
}
|
||||
double curWeightDouble = (double)curWeight;
|
||||
float realCurWeight = (float)(curWeightDouble / bitmax);
|
||||
|
||||
int boneIndex = (int)m_BoneIndices_Unpacked[bonesIndex];
|
||||
bonesIndex++;
|
||||
if (boneIndex < 0)
|
||||
{
|
||||
throw new Exception($"Invalid bone index {boneIndex}");
|
||||
}
|
||||
BoneInfluence boneInfl = new BoneInfluence()
|
||||
{
|
||||
weight = realCurWeight,
|
||||
boneIndex = boneIndex,
|
||||
};
|
||||
m_Skin[vertIndex].Add(boneInfl);
|
||||
|
||||
if(inflSum == 31)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (inflSum > 31)
|
||||
{
|
||||
throw new Exception("Influence sum " + inflSum + " greater than 31");
|
||||
}
|
||||
}
|
||||
for(; j < 4; j++)
|
||||
{
|
||||
BoneInfluence boneInfl = new BoneInfluence()
|
||||
{
|
||||
weight = 0.0f,
|
||||
boneIndex = 0,
|
||||
};
|
||||
m_Skin[vertIndex].Add(boneInfl);
|
||||
}
|
||||
}
|
||||
|
||||
bool isFine = vertIndex == m_VertexCount;
|
||||
if (!isFine)
|
||||
{
|
||||
throw new Exception("Vertecies aint equals");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
Loading…
Reference in New Issue
Block a user