1
0
mirror of synced 2025-02-26 14:51:47 +01:00

Animation fixes for playing last frame

This commit is contained in:
KillzXGaming 2019-06-03 20:04:15 -04:00
parent 47cd45b4e0
commit 8a22275cd5
13 changed files with 35 additions and 44 deletions

Binary file not shown.

View File

@ -81,6 +81,8 @@ namespace Bfres.Structs
Value = (int)animCurve.Offset + (int)animCurve.Keys[i, 0] * animCurve.Scale, Value = (int)animCurve.Offset + (int)animCurve.Keys[i, 0] * animCurve.Scale,
Value1 = (int)animCurve.Offset + (int)animCurve.Keys[i, 0] * animCurve.Scale, Value1 = (int)animCurve.Offset + (int)animCurve.Keys[i, 0] * animCurve.Scale,
}); });
Console.WriteLine($"Frame {animCurve.Frames[i]} Offset " + (int)animCurve.Offset + " " + ((int)animCurve.Offset + (int)animCurve.Keys[i, 0] * animCurve.Scale));
break; break;
default: default:
throw new Exception("Unsupported anim type!"); throw new Exception("Unsupported anim type!");

View File

@ -466,12 +466,6 @@ namespace Bfres.Structs
Text = Name; Text = Name;
} }
public override string GetActiveTextureName(int frame)
{
uint val = (uint)GetValue(frame);
return MatAnimWrapper.Textures[(int)val];
}
public void AddKeyFrame(string TextureName, float Frame = -1, bool IsConstant = false) public void AddKeyFrame(string TextureName, float Frame = -1, bool IsConstant = false)
{ {
Constant = IsConstant; Constant = IsConstant;
@ -518,22 +512,20 @@ namespace Bfres.Structs
return curve; return curve;
} }
public override STGenericTexture GetActiveTexture(int frame) public override STGenericTexture GetActiveTexture(int index)
{ {
uint val = (uint)GetValue(frame);
foreach (var bntx in PluginRuntime.bntxContainers) foreach (var bntx in PluginRuntime.bntxContainers)
{ {
try try
{ {
string name = MatAnimWrapper.Textures[(int)val]; string name = MatAnimWrapper.Textures[(int)index];
if (bntx.Textures.ContainsKey(name)) if (bntx.Textures.ContainsKey(name))
return bntx.Textures[name]; return bntx.Textures[name];
} }
catch catch
{ {
throw new Exception("Index out of range " + val); throw new Exception("Index out of range " + index);
} }
} }
return null; return null;
@ -542,7 +534,7 @@ namespace Bfres.Structs
public override void NextFrame(Viewport viewport) public override void NextFrame(Viewport viewport)
{ {
if (Frame >= FrameCount) return; if (Frame > FrameCount) return;
//Loop through each drawable bfres in the active viewport to display the anim //Loop through each drawable bfres in the active viewport to display the anim
foreach (var drawable in viewport.scene.staticObjects) foreach (var drawable in viewport.scene.staticObjects)
@ -692,8 +684,9 @@ namespace Bfres.Structs
{ {
texture.textureState = STGenericMatTexture.TextureState.Animated; texture.textureState = STGenericMatTexture.TextureState.Animated;
uint index = (uint)samplerAnim.GetValue(Frame); Console.WriteLine($"Frame " + Frame);
texture.animatedTexName = Textures[(int)index];
texture.animatedTexName = samplerAnim.GetActiveTextureNameByFrame(Frame);
} }
} }
} }

View File

@ -146,36 +146,23 @@ namespace Bfres.Structs
AnimWrapper = ftxp; AnimWrapper = ftxp;
} }
public override string GetActiveTextureName(int frame) public override STGenericTexture GetActiveTexture(int index)
{ {
uint val = (uint)GetValue(frame);
return AnimWrapper.Textures[(int)val];
}
public override STGenericTexture GetActiveTexture(int frame)
{
uint val = (uint)GetValue(frame);
foreach (var ftexFolder in PluginRuntime.ftexContainers) foreach (var ftexFolder in PluginRuntime.ftexContainers)
{ {
try string name = GetActiveTextureNameByIndex(index);
{
string name = GetActiveTextureName(frame);
if (ftexFolder.ResourceNodes.ContainsKey(name)) if (ftexFolder.ResourceNodes.ContainsKey(name))
return (STGenericTexture)ftexFolder.ResourceNodes[name]; return (STGenericTexture)ftexFolder.ResourceNodes[name];
} }
catch
{
throw new Exception("Index out of range " + val);
}
}
return null; return null;
} }
} }
public override void NextFrame(Viewport viewport) public override void NextFrame(Viewport viewport)
{ {
if (Frame > FrameCount) return;
//Loop through each drawable bfres in the active viewport to display the anim //Loop through each drawable bfres in the active viewport to display the anim
foreach (var drawable in viewport.scene.staticObjects) foreach (var drawable in viewport.scene.staticObjects)
{ {
@ -212,8 +199,7 @@ namespace Bfres.Structs
{ {
texture.textureState = STGenericMatTexture.TextureState.Animated; texture.textureState = STGenericMatTexture.TextureState.Animated;
uint index = (uint)samplerAnim.GetValue(Frame); texture.animatedTexName = samplerAnim.GetActiveTextureNameByFrame(Frame);
texture.animatedTexName = Textures[(int)index];
} }
} }
} }

View File

@ -207,7 +207,9 @@ namespace FirstPlugin.Forms
if (keyFrame.IsKeyed || activeSampler.Constant) if (keyFrame.IsKeyed || activeSampler.Constant)
{ {
var tex = activeSampler.GetActiveTexture(Frame); string TextureKey = activeSampler.GetActiveTextureNameByIndex((int)keyFrame.Value);
var tex = activeSampler.GetActiveTexture((int)keyFrame.Value);
if (tex != null) if (tex != null)
{ {
@ -232,11 +234,11 @@ namespace FirstPlugin.Forms
if (listViewCustom1.InvokeRequired) if (listViewCustom1.InvokeRequired)
{ {
listViewCustom1.Invoke((MethodInvoker)delegate { listViewCustom1.Invoke((MethodInvoker)delegate {
listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + activeSampler.GetActiveTextureName(Frame), imageIndex++); listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + TextureKey, imageIndex++);
}); });
} }
else else
listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + activeSampler.GetActiveTextureName(Frame), imageIndex++); listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + TextureKey, imageIndex++);
} }
} }
} }

View File

@ -531,7 +531,7 @@ namespace Switch_Toolbox.Library.Animations
public void NextFrame(STSkeleton skeleton, bool isChild = false, bool AdancedNextFrame = false) public void NextFrame(STSkeleton skeleton, bool isChild = false, bool AdancedNextFrame = false)
{ {
if (Frame >= FrameCount) return; if (Frame > FrameCount) return;
if (Frame == 0 && !isChild) if (Frame == 0 && !isChild)
skeleton.reset(); skeleton.reset();

View File

@ -22,7 +22,7 @@ namespace Switch_Toolbox.Library.Animations
public virtual void NextFrame(Viewport viewport) public virtual void NextFrame(Viewport viewport)
{ {
if (Frame >= FrameCount) return; if (Frame > FrameCount) return;
} }
public List<string> Textures = new List<string>(); public List<string> Textures = new List<string>();
@ -68,12 +68,17 @@ namespace Switch_Toolbox.Library.Animations
MaterialAnimation = materialAnimation; MaterialAnimation = materialAnimation;
} }
public virtual string GetActiveTextureName(int frame) public virtual string GetActiveTextureNameByIndex(int index)
{ {
float index = GetValue(frame);
return MaterialAnimation.Textures[(int)index]; return MaterialAnimation.Textures[(int)index];
} }
public virtual string GetActiveTextureNameByFrame(float frame)
{
var KeyFrame = GetKeyFrame(frame);
return MaterialAnimation.Textures[(int)KeyFrame.Value];
}
public virtual void SetActiveTextureName(int Frame, string TextureName) public virtual void SetActiveTextureName(int Frame, string TextureName)
{ {
if (!MaterialAnimation.Textures.Contains(TextureName)) if (!MaterialAnimation.Textures.Contains(TextureName))

View File

@ -285,6 +285,9 @@ namespace Switch_Toolbox.Library
} }
private void animationTrackBar_ValueChanged(object sender, EventArgs e) { private void animationTrackBar_ValueChanged(object sender, EventArgs e) {
if (currentAnimation == null || totalFrame.Value <= 0)
return;
currentFrameUpDown.Value = animationTrackBar.CurrentFrame; currentFrameUpDown.Value = animationTrackBar.CurrentFrame;
} }