mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-25 05:40:21 -04:00
improve QuaternionToEuler
This commit is contained in:
parent
9e4be3e082
commit
bc2469e11a
@ -580,13 +580,21 @@ namespace AssetStudio
|
||||
track.Name = boneName;
|
||||
iAnim.TrackList.Add(track);
|
||||
}
|
||||
Vector3 prevKey = new Vector3();
|
||||
foreach (var m_Curve in m_RotationCurve.curve.m_Curve)
|
||||
{
|
||||
track.Rotations.Add(new ImportedKeyframe<Quaternion>(
|
||||
var value = Fbx.QuaternionToEuler(new Quaternion(m_Curve.value.X, -m_Curve.value.Y, -m_Curve.value.Z, m_Curve.value.W));
|
||||
var inSlope = Fbx.QuaternionToEuler(new Quaternion(m_Curve.inSlope.X, -m_Curve.inSlope.Y, -m_Curve.inSlope.Z, m_Curve.inSlope.W));
|
||||
var outSlope = Fbx.QuaternionToEuler(new Quaternion(m_Curve.outSlope.X, -m_Curve.outSlope.Y, -m_Curve.outSlope.Z, m_Curve.outSlope.W));
|
||||
|
||||
ReplaceOutOfBound(ref prevKey, ref value);
|
||||
prevKey = value;
|
||||
|
||||
track.Rotations.Add(new ImportedKeyframe<Vector3>(
|
||||
m_Curve.time,
|
||||
new Quaternion(m_Curve.value.X, -m_Curve.value.Y, -m_Curve.value.Z, m_Curve.value.W),
|
||||
new Quaternion(m_Curve.inSlope.X, -m_Curve.inSlope.Y, -m_Curve.inSlope.Z, m_Curve.inSlope.W),
|
||||
new Quaternion(m_Curve.outSlope.X, -m_Curve.outSlope.Y, -m_Curve.outSlope.Z, m_Curve.outSlope.W)));
|
||||
value,
|
||||
inSlope,
|
||||
outSlope));
|
||||
}
|
||||
}
|
||||
foreach (var m_PositionCurve in clip.m_PositionCurves)
|
||||
@ -862,5 +870,43 @@ namespace AssetStudio
|
||||
CreateBonePathHash(child);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReplaceOutOfBound(ref Vector3 prevKey, ref Vector3 curKey)
|
||||
{
|
||||
curKey.X = ReplaceOutOfBound(prevKey.X, curKey.X);
|
||||
curKey.Y = ReplaceOutOfBound(prevKey.Y, curKey.Y);
|
||||
curKey.Z = ReplaceOutOfBound(prevKey.Z, curKey.Z);
|
||||
}
|
||||
|
||||
private float ReplaceOutOfBound(float prevValue, float curValue)
|
||||
{
|
||||
double prev = prevValue;
|
||||
double cur = curValue;
|
||||
|
||||
double prevAbs = Math.Abs(prev);
|
||||
double prevSign = Math.Sign(prev);
|
||||
|
||||
double prevShift = 180.0 + prevAbs;
|
||||
double count = Math.Floor(prevShift / 360.0) * prevSign;
|
||||
double prevRemain = 180.0 + (prev - count * 360.0);
|
||||
|
||||
double curShift = 180.0 + cur;
|
||||
|
||||
if (prevRemain - curShift > 180)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
else if (prevRemain - curShift < -180)
|
||||
{
|
||||
count--;
|
||||
}
|
||||
|
||||
double newValue = count * 360.0 + cur;
|
||||
if (newValue != cur)
|
||||
{
|
||||
|
||||
}
|
||||
return (float)newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -796,12 +796,9 @@ namespace AssetStudio
|
||||
{
|
||||
lTime.SetSecondDouble(Rotation->time);
|
||||
|
||||
Vector3 rotation = Fbx::QuaternionToEuler(Rotation->value);
|
||||
Vector3 inSlope = Fbx::QuaternionToEuler(Rotation->inSlope);
|
||||
Vector3 outSlope = Fbx::QuaternionToEuler(Rotation->outSlope);
|
||||
lCurveRX->KeySet(lCurveRX->KeyAdd(lTime), lTime, rotation.X);
|
||||
lCurveRY->KeySet(lCurveRY->KeyAdd(lTime), lTime, rotation.Y);
|
||||
lCurveRZ->KeySet(lCurveRZ->KeyAdd(lTime), lTime, rotation.Z);
|
||||
lCurveRX->KeySet(lCurveRX->KeyAdd(lTime), lTime, Rotation->value.X);
|
||||
lCurveRY->KeySet(lCurveRY->KeyAdd(lTime), lTime, Rotation->value.Y);
|
||||
lCurveRZ->KeySet(lCurveRZ->KeyAdd(lTime), lTime, Rotation->value.Z);
|
||||
}
|
||||
for each (auto Translation in keyframeList->Translations)
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ namespace AssetStudio
|
||||
public class ImportedAnimationKeyframedTrack : ImportedAnimationTrack
|
||||
{
|
||||
public List<ImportedKeyframe<Vector3>> Scalings = new List<ImportedKeyframe<Vector3>>();
|
||||
public List<ImportedKeyframe<Quaternion>> Rotations = new List<ImportedKeyframe<Quaternion>>();
|
||||
public List<ImportedKeyframe<Vector3>> Rotations = new List<ImportedKeyframe<Vector3>>();
|
||||
public List<ImportedKeyframe<Vector3>> Translations = new List<ImportedKeyframe<Vector3>>();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user