Browse Source
Further mesh research: create an individual mesh for each animation sequence, with a single blend shape animation per mesh. Added an AliasModel class to manage meshes and find the correct animations. With this we can smoothly animate looped animation cycles.
console
Further mesh research: create an individual mesh for each animation sequence, with a single blend shape animation per mesh. Added an AliasModel class to manage meshes and find the correct animations. With this we can smoothly animate looped animation cycles.
console
4 changed files with 120 additions and 22 deletions
-
53Assets/Scripts/Modules/AliasModel.cs
-
3Assets/Scripts/Modules/AliasModel.cs.meta
-
10Assets/Scripts/Modules/AliasModelAnimator.cs
-
72Assets/Scripts/Modules/RenderModule.cs
@ -0,0 +1,53 @@ |
|||
using System.Collections.Generic; |
|||
using System.Text.RegularExpressions; |
|||
using UnityEngine; |
|||
|
|||
public class AliasModel |
|||
{ |
|||
public static readonly Regex AnimationRegex = new Regex(@"^[a-zA-Z]+"); |
|||
|
|||
private readonly List<(int, Mesh)> animationMeshes = new List<(int, Mesh)>(); // TODO: make this a fixed array after initialization
|
|||
|
|||
public void AddAnimation(int startFrame, Mesh mesh) |
|||
{ |
|||
animationMeshes.Add((startFrame, mesh)); |
|||
} |
|||
|
|||
public int GetAnimationFrameCount(float frameNum) |
|||
{ |
|||
if (!FindAnimation((int)frameNum, out Mesh mesh, out int startFrame)) |
|||
return 0; |
|||
|
|||
return mesh.GetBlendShapeFrameCount(0); |
|||
} |
|||
|
|||
public void Animate(float frameNum, out Mesh mesh, out float blendWeight) |
|||
{ |
|||
blendWeight = 0; |
|||
|
|||
int frameIndex = (int)frameNum; |
|||
if (!FindAnimation(frameIndex, out mesh, out int startFrame)) |
|||
return; |
|||
|
|||
int numFrames = mesh.GetBlendShapeFrameCount(0); |
|||
blendWeight = ((frameNum - startFrame) / numFrames) % 1; |
|||
} |
|||
|
|||
private bool FindAnimation(int frameIndex, out Mesh mesh, out int startFrame) |
|||
{ |
|||
mesh = null; |
|||
startFrame = 0; |
|||
|
|||
for (int i = 0; i < animationMeshes.Count; ++i) |
|||
{ |
|||
startFrame = animationMeshes[i].Item1; |
|||
if (frameIndex >= startFrame) |
|||
{ |
|||
mesh = animationMeshes[i].Item2; |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; // Shouldn't happen
|
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 74fb95086b6c4400bc3696481e4679e6 |
|||
timeCreated: 1618650253 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue