mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-26 13:50:21 -04:00
improve QuaternionToEuler
This commit is contained in:
parent
9e4be3e082
commit
bc2469e11a
@ -580,13 +580,21 @@ namespace AssetStudio
|
|||||||
track.Name = boneName;
|
track.Name = boneName;
|
||||||
iAnim.TrackList.Add(track);
|
iAnim.TrackList.Add(track);
|
||||||
}
|
}
|
||||||
|
Vector3 prevKey = new Vector3();
|
||||||
foreach (var m_Curve in m_RotationCurve.curve.m_Curve)
|
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,
|
m_Curve.time,
|
||||||
new Quaternion(m_Curve.value.X, -m_Curve.value.Y, -m_Curve.value.Z, m_Curve.value.W),
|
value,
|
||||||
new Quaternion(m_Curve.inSlope.X, -m_Curve.inSlope.Y, -m_Curve.inSlope.Z, m_Curve.inSlope.W),
|
inSlope,
|
||||||
new Quaternion(m_Curve.outSlope.X, -m_Curve.outSlope.Y, -m_Curve.outSlope.Z, m_Curve.outSlope.W)));
|
outSlope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var m_PositionCurve in clip.m_PositionCurves)
|
foreach (var m_PositionCurve in clip.m_PositionCurves)
|
||||||
@ -862,5 +870,43 @@ namespace AssetStudio
|
|||||||
CreateBonePathHash(child);
|
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);
|
lTime.SetSecondDouble(Rotation->time);
|
||||||
|
|
||||||
Vector3 rotation = Fbx::QuaternionToEuler(Rotation->value);
|
lCurveRX->KeySet(lCurveRX->KeyAdd(lTime), lTime, Rotation->value.X);
|
||||||
Vector3 inSlope = Fbx::QuaternionToEuler(Rotation->inSlope);
|
lCurveRY->KeySet(lCurveRY->KeyAdd(lTime), lTime, Rotation->value.Y);
|
||||||
Vector3 outSlope = Fbx::QuaternionToEuler(Rotation->outSlope);
|
lCurveRZ->KeySet(lCurveRZ->KeyAdd(lTime), lTime, Rotation->value.Z);
|
||||||
lCurveRX->KeySet(lCurveRX->KeyAdd(lTime), lTime, rotation.X);
|
|
||||||
lCurveRY->KeySet(lCurveRY->KeyAdd(lTime), lTime, rotation.Y);
|
|
||||||
lCurveRZ->KeySet(lCurveRZ->KeyAdd(lTime), lTime, rotation.Z);
|
|
||||||
}
|
}
|
||||||
for each (auto Translation in keyframeList->Translations)
|
for each (auto Translation in keyframeList->Translations)
|
||||||
{
|
{
|
||||||
|
@ -140,7 +140,7 @@ namespace AssetStudio
|
|||||||
public class ImportedAnimationKeyframedTrack : ImportedAnimationTrack
|
public class ImportedAnimationKeyframedTrack : ImportedAnimationTrack
|
||||||
{
|
{
|
||||||
public List<ImportedKeyframe<Vector3>> Scalings = new List<ImportedKeyframe<Vector3>>();
|
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>>();
|
public List<ImportedKeyframe<Vector3>> Translations = new List<ImportedKeyframe<Vector3>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user