Add option for importing scale tracking to animation asset

This commit is contained in:
Wojtek Figat
2023-02-07 09:39:31 +01:00
parent e02c4b6f98
commit 7a2023ead6
6 changed files with 23 additions and 5 deletions

View File

@@ -260,6 +260,13 @@ namespace FlaxEditor.Content.Import
[EditorOrder(1050), DefaultValue(true)] [EditorOrder(1050), DefaultValue(true)]
public bool OptimizeKeyframes { get; set; } = true; public bool OptimizeKeyframes { get; set; } = true;
/// <summary>
/// If checked, the importer will import scale animation tracks (otherwise scale animation will be ignored).
/// </summary>
[EditorDisplay("Animation"), VisibleIf(nameof(ShowAnimation))]
[EditorOrder(1055), DefaultValue(false)]
public bool ImportScaleTracks { get; set; } = false;
/// <summary> /// <summary>
/// Enables root motion extraction support from this animation. /// Enables root motion extraction support from this animation.
/// </summary> /// </summary>
@@ -387,6 +394,7 @@ namespace FlaxEditor.Content.Import
public float SamplingRate; public float SamplingRate;
public byte SkipEmptyCurves; public byte SkipEmptyCurves;
public byte OptimizeKeyframes; public byte OptimizeKeyframes;
public byte ImportScaleTracks;
public byte EnableRootMotion; public byte EnableRootMotion;
public string RootNodeName; public string RootNodeName;
@@ -438,6 +446,7 @@ namespace FlaxEditor.Content.Import
SamplingRate = SamplingRate, SamplingRate = SamplingRate,
SkipEmptyCurves = (byte)(SkipEmptyCurves ? 1 : 0), SkipEmptyCurves = (byte)(SkipEmptyCurves ? 1 : 0),
OptimizeKeyframes = (byte)(OptimizeKeyframes ? 1 : 0), OptimizeKeyframes = (byte)(OptimizeKeyframes ? 1 : 0),
ImportScaleTracks = (byte)(ImportScaleTracks ? 1 : 0),
EnableRootMotion = (byte)(EnableRootMotion ? 1 : 0), EnableRootMotion = (byte)(EnableRootMotion ? 1 : 0),
RootNodeName = RootNodeName, RootNodeName = RootNodeName,
GenerateLODs = (byte)(GenerateLODs ? 1 : 0), GenerateLODs = (byte)(GenerateLODs ? 1 : 0),
@@ -479,6 +488,7 @@ namespace FlaxEditor.Content.Import
SamplingRate = options.SamplingRate; SamplingRate = options.SamplingRate;
SkipEmptyCurves = options.SkipEmptyCurves != 0; SkipEmptyCurves = options.SkipEmptyCurves != 0;
OptimizeKeyframes = options.OptimizeKeyframes != 0; OptimizeKeyframes = options.OptimizeKeyframes != 0;
ImportScaleTracks = options.ImportScaleTracks != 0;
EnableRootMotion = options.EnableRootMotion != 0; EnableRootMotion = options.EnableRootMotion != 0;
RootNodeName = options.RootNodeName; RootNodeName = options.RootNodeName;
GenerateLODs = options.GenerateLODs != 0; GenerateLODs = options.GenerateLODs != 0;

View File

@@ -183,6 +183,7 @@ struct InternalModelOptions
float SamplingRate; float SamplingRate;
byte SkipEmptyCurves; byte SkipEmptyCurves;
byte OptimizeKeyframes; byte OptimizeKeyframes;
byte ImportScaleTracks;
byte EnableRootMotion; byte EnableRootMotion;
MonoString* RootNodeName; MonoString* RootNodeName;
@@ -231,6 +232,7 @@ struct InternalModelOptions
to->SamplingRate = from->SamplingRate; to->SamplingRate = from->SamplingRate;
to->SkipEmptyCurves = from->SkipEmptyCurves; to->SkipEmptyCurves = from->SkipEmptyCurves;
to->OptimizeKeyframes = from->OptimizeKeyframes; to->OptimizeKeyframes = from->OptimizeKeyframes;
to->ImportScaleTracks = from->ImportScaleTracks;
to->EnableRootMotion = from->EnableRootMotion; to->EnableRootMotion = from->EnableRootMotion;
to->RootNodeName = MUtils::ToString(from->RootNodeName); to->RootNodeName = MUtils::ToString(from->RootNodeName);
to->GenerateLODs = from->GenerateLODs; to->GenerateLODs = from->GenerateLODs;
@@ -272,6 +274,7 @@ struct InternalModelOptions
to->SamplingRate = from->SamplingRate; to->SamplingRate = from->SamplingRate;
to->SkipEmptyCurves = from->SkipEmptyCurves; to->SkipEmptyCurves = from->SkipEmptyCurves;
to->OptimizeKeyframes = from->OptimizeKeyframes; to->OptimizeKeyframes = from->OptimizeKeyframes;
to->ImportScaleTracks = from->ImportScaleTracks;
to->EnableRootMotion = from->EnableRootMotion; to->EnableRootMotion = from->EnableRootMotion;
to->RootNodeName = MUtils::ToString(from->RootNodeName); to->RootNodeName = MUtils::ToString(from->RootNodeName);
to->GenerateLODs = from->GenerateLODs; to->GenerateLODs = from->GenerateLODs;

View File

@@ -819,6 +819,7 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
ImportCurve(aAnim->mPositionKeys, aAnim->mNumPositionKeys, anim.Position); ImportCurve(aAnim->mPositionKeys, aAnim->mNumPositionKeys, anim.Position);
ImportCurve(aAnim->mRotationKeys, aAnim->mNumRotationKeys, anim.Rotation); ImportCurve(aAnim->mRotationKeys, aAnim->mNumRotationKeys, anim.Rotation);
if (options.ImportScaleTracks)
ImportCurve(aAnim->mScalingKeys, aAnim->mNumScalingKeys, anim.Scale); ImportCurve(aAnim->mScalingKeys, aAnim->mNumScalingKeys, anim.Scale);
} }
} }

View File

@@ -1051,9 +1051,9 @@ bool ImportAnimation(int32 index, ImportedModelData& data, OpenFbxImporterData&
const ofbx::AnimationCurveNode* translationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Translation"); const ofbx::AnimationCurveNode* translationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Translation");
const ofbx::AnimationCurveNode* rotationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Rotation"); const ofbx::AnimationCurveNode* rotationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Rotation");
const ofbx::AnimationCurveNode* scalingNode = nullptr; //layer->getCurveNode(*aNode.FbxObj, "Lcl Scaling"); const ofbx::AnimationCurveNode* scalingNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Scaling");
if (translationNode || rotationNode || scalingNode) if (translationNode || rotationNode || (scalingNode && importerData.Options.ImportScaleTracks))
animatedNodes.Add(nodeIndex); animatedNodes.Add(nodeIndex);
} }
if (animatedNodes.IsEmpty()) if (animatedNodes.IsEmpty())
@@ -1069,13 +1069,14 @@ bool ImportAnimation(int32 index, ImportedModelData& data, OpenFbxImporterData&
const ofbx::AnimationCurveNode* translationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Translation"); const ofbx::AnimationCurveNode* translationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Translation");
const ofbx::AnimationCurveNode* rotationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Rotation"); const ofbx::AnimationCurveNode* rotationNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Rotation");
//const ofbx::AnimationCurveNode* scalingNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Scaling"); const ofbx::AnimationCurveNode* scalingNode = layer->getCurveNode(*aNode.FbxObj, "Lcl Scaling");
anim.NodeName = aNode.Name; anim.NodeName = aNode.Name;
ImportCurve(translationNode, anim.Position, info, ExtractKeyframePosition); ImportCurve(translationNode, anim.Position, info, ExtractKeyframePosition);
ImportCurve(rotationNode, anim.Rotation, info, ExtractKeyframeRotation); ImportCurve(rotationNode, anim.Rotation, info, ExtractKeyframeRotation);
//ImportCurve(scalingNode, anim.Scale, info, ExtractKeyframeScale); if (importerData.Options.ImportScaleTracks)
ImportCurve(scalingNode, anim.Scale, info, ExtractKeyframeScale);
} }
if (importerData.ConvertRH) if (importerData.ConvertRH)

View File

@@ -53,6 +53,7 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj
SERIALIZE(SamplingRate); SERIALIZE(SamplingRate);
SERIALIZE(SkipEmptyCurves); SERIALIZE(SkipEmptyCurves);
SERIALIZE(OptimizeKeyframes); SERIALIZE(OptimizeKeyframes);
SERIALIZE(ImportScaleTracks);
SERIALIZE(EnableRootMotion); SERIALIZE(EnableRootMotion);
SERIALIZE(RootNodeName); SERIALIZE(RootNodeName);
SERIALIZE(GenerateLODs); SERIALIZE(GenerateLODs);
@@ -93,6 +94,7 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi
DESERIALIZE(SamplingRate); DESERIALIZE(SamplingRate);
DESERIALIZE(SkipEmptyCurves); DESERIALIZE(SkipEmptyCurves);
DESERIALIZE(OptimizeKeyframes); DESERIALIZE(OptimizeKeyframes);
DESERIALIZE(ImportScaleTracks);
DESERIALIZE(EnableRootMotion); DESERIALIZE(EnableRootMotion);
DESERIALIZE(RootNodeName); DESERIALIZE(RootNodeName);
DESERIALIZE(GenerateLODs); DESERIALIZE(GenerateLODs);

View File

@@ -235,6 +235,7 @@ public:
float SamplingRate = 0.0f; float SamplingRate = 0.0f;
bool SkipEmptyCurves = true; bool SkipEmptyCurves = true;
bool OptimizeKeyframes = true; bool OptimizeKeyframes = true;
bool ImportScaleTracks = false;
bool EnableRootMotion = false; bool EnableRootMotion = false;
String RootNodeName; String RootNodeName;