Skip to content

Commit

Permalink
Implement skeletal animation logic (#17)
Browse files Browse the repository at this point in the history
Properly implements SkeletalModelRenderer + SkeletalAnimationActorActionController
  • Loading branch information
0x7c13 authored Jul 28, 2023
1 parent a1801f5 commit 5fab0d8
Show file tree
Hide file tree
Showing 17 changed files with 739 additions and 300 deletions.
12 changes: 6 additions & 6 deletions Assets/Scripts/Core/DataReader/Cvd/CvdFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,18 @@ private static (List<int> triangles, List<int> indexBuffer) CalculateTriangles(
var triangles = new List<int>();
var index = 0;

for (var j = 0; j < allIndices.Length; j++)
for (var i = 0; i < allIndices.Length; i++)
{
var indices = new[]
{
allIndices[j].x,
allIndices[j].y,
allIndices[j].z
allIndices[i].x,
allIndices[i].y,
allIndices[i].z
};

for (var k = 0; k < 3; k++)
for (var j = 0; j < 3; j++)
{
indexBuffer.Add(indices[k]);
indexBuffer.Add(indices[j]);
triangles.Add(index++);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Core/DataReader/Mov/MovFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static MovAnimationEvent ReadAnimationEvent(BinaryReader reader, int cod
{
return new MovAnimationEvent()
{
Tick = GameBoxInterpreter.GameBoxSecondsToTick(reader.ReadSingle()),
Tick = GameBoxInterpreter.SecondsToTick(reader.ReadSingle()),
Name = reader.ReadString(16, codepage)
};
}
Expand All @@ -110,7 +110,7 @@ private static MovBoneAnimationTrack ReadBoneAnimationTrack(BinaryReader reader,
{
animationKeyFrames[i] = new MovAnimationKeyFrame()
{
Tick = GameBoxInterpreter.GameBoxSecondsToTick(reader.ReadSingle()),
Tick = GameBoxInterpreter.SecondsToTick(reader.ReadSingle()),
Translation = GameBoxInterpreter.ToUnityPosition(reader.ReadVector3()),
Rotation = GameBoxInterpreter.MovQuaternionToUnityQuaternion(new GameBoxQuaternion()
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Core/GameBox/GameBoxInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ public static Matrix4x4 ToUnityMatrix4x4(GameBoxMatrix4X4 matrix)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint GameBoxSecondsToTick(float seconds)
public static uint SecondsToTick(float seconds)
{
return (uint)(seconds * GameBoxTicksPerSecond);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float TickToGameBoxSeconds(uint tick)
public static float TickToSeconds(uint tick)
{
return (float)tick / GameBoxTicksPerSecond;
}
Expand Down
13 changes: 3 additions & 10 deletions Assets/Scripts/Core/Utils/UnitySupportedVideoFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,11 @@ public static HashSet<string> GetSupportedVideoFormats(RuntimePlatform platform)
{
return platform switch
{
RuntimePlatform.WindowsPlayer => WindowsSupportedVideoFormats,
RuntimePlatform.WindowsEditor => WindowsSupportedVideoFormats,

RuntimePlatform.OSXPlayer => MacOSSupportedVideoFormats,
RuntimePlatform.OSXEditor => MacOSSupportedVideoFormats,

RuntimePlatform.LinuxPlayer => LinuxSupportedVideoFormats,
RuntimePlatform.LinuxEditor => LinuxSupportedVideoFormats,

RuntimePlatform.WindowsPlayer or RuntimePlatform.WindowsEditor => WindowsSupportedVideoFormats,
RuntimePlatform.OSXPlayer or RuntimePlatform.OSXEditor => MacOSSupportedVideoFormats,
RuntimePlatform.LinuxPlayer or RuntimePlatform.LinuxEditor => LinuxSupportedVideoFormats,
RuntimePlatform.IPhonePlayer => iOSSupportedVideoFormats,
RuntimePlatform.Android => AndroidSupportedVideoFormats,

_ => new HashSet<string> {".mp4" }
};
}
Expand Down
14 changes: 7 additions & 7 deletions Assets/Scripts/Pal3/Actor/ActorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Pal3.Actor

public enum ActorAnimationType
{
Mv3 = 0,
Mov
Vertex = 0, // .mv3 animation
Skeletal = 1, // .msh + .mov animation
}

public abstract class ActorBase
Expand Down Expand Up @@ -50,7 +50,7 @@ private void InitActorConfig(string name)
if (defaultConfig is Mv3ActionConfig mv3Config)
{
AddActorConfig(mv3Config);
AnimationType = ActorAnimationType.Mv3;
AnimationType = ActorAnimationType.Vertex;
return;
}

Expand All @@ -71,7 +71,7 @@ private void InitActorConfig(string name)
}
}

AnimationType = ActorAnimationType.Mov;
AnimationType = ActorAnimationType.Skeletal;
}

private void AddActorConfig(ActorActionConfig config)
Expand Down Expand Up @@ -118,14 +118,14 @@ public string GetActionFilePath(string actionName)

public string GetMeshFilePath(string actionName)
{
if (AnimationType != ActorAnimationType.Mov)
if (AnimationType != ActorAnimationType.Skeletal)
{
throw new InvalidOperationException("Mesh file path is only available for MOV animation type.");
throw new InvalidOperationException("Msh file path is only available for skeletal animation type.");
}

if (!_actionNameToMeshFileNameMap.TryGetValue(actionName, out var meshFileName))
{
throw new ArgumentException($"Mesh file name not found for action name {actionName}");
throw new ArgumentException($"Msh file name not found for action name {actionName}");
}

char separator = CpkConstants.DirectorySeparator;
Expand Down
29 changes: 19 additions & 10 deletions Assets/Scripts/Pal3/Actor/ActorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,26 @@ public static GameObject CreateActorGameObject(GameResourceProvider resourceProv
#endif

ActorActionController actionController;
if (actor.AnimationType == ActorAnimationType.Mv3)
switch (actor.AnimationType)
{
Mv3ActorActionController mv3ActionController = actorGameObject.AddComponent<Mv3ActorActionController>();
mv3ActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = mv3ActionController;
}
else
{
MovActorActionController movActionController = actorGameObject.AddComponent<MovActorActionController>();
movActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = movActionController;
case ActorAnimationType.Vertex:
{
VertexAnimationActorActionController vertexActionController =
actorGameObject.AddComponent<VertexAnimationActorActionController>();
vertexActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = vertexActionController;
break;
}
case ActorAnimationType.Skeletal:
{
SkeletalAnimationActorActionController skeletalActionController =
actorGameObject.AddComponent<SkeletalAnimationActorActionController>();
skeletalActionController.Init(resourceProvider, actor, hasColliderAndRigidBody, isDropShadowEnabled, tintColor);
actionController = skeletalActionController;
break;
}
default:
throw new NotSupportedException($"Unsupported actor animation type: {actor.AnimationType}");
}

var movementController = actorGameObject.AddComponent<ActorMovementController>();
Expand Down
224 changes: 0 additions & 224 deletions Assets/Scripts/Pal3/Actor/MovActorActionController.cs

This file was deleted.

Loading

0 comments on commit 5fab0d8

Please sign in to comment.