Browse Source

Squashed a bunch of bugs in the alias model animation system and integrated transform/animation updates into the alias model lerping system. Entities are now correctly animated, yay!

console
Nico de Poel 5 years ago
parent
commit
66c62001d0
  1. 2
      Assets/Scripts/Data/QExtensions.cs
  2. 4
      Assets/Scripts/Game/Entity.cs
  3. 2
      Assets/Scripts/Game/GameState.cs
  4. 11
      Assets/Scripts/Modules/GameModule.Interop.cs
  5. 5
      Assets/Scripts/Modules/GameModule.cs
  6. 2
      Assets/Scripts/Modules/RenderModule.cs
  7. 11
      Assets/Scripts/Support/AliasModel.cs
  8. 8
      engine/Quake/cl_main.c
  9. 1
      engine/Quake/client.h
  10. 5
      engine/Quake/r_alias.c
  11. 1
      engine/Quake/render.h
  12. 6
      engine/UniQuake/game_uniquake.c

2
Assets/Scripts/Data/QExtensions.cs

@ -58,6 +58,6 @@ public static class QExtensions
public static Quaternion ToUnityRotation(this QVec3 angles)
{
return Quaternion.Euler(angles.x, 90 - angles.y, -angles.z);
return Quaternion.Euler(angles.x, -angles.y, -angles.z);
}
}

4
Assets/Scripts/Game/Entity.cs

@ -48,14 +48,14 @@ public class Entity
UpdateAnimation(0);
}
public void UpdateAnimation(int frameNum)
public void UpdateAnimation(float frameNum)
{
if (aliasModel != null)
{
aliasModel.Animate(frameNum, out Mesh mesh, out float blendWeight);
meshRenderer.sharedMesh = mesh;
if (mesh.blendShapeCount > 0)
if (mesh != null && mesh.blendShapeCount > 0)
meshRenderer.SetBlendShapeWeight(0, blendWeight);
}
}

2
Assets/Scripts/Game/GameState.cs

@ -99,7 +99,7 @@ public class GameState
// TODO: obtain Mesh from brush submodel and assign it to MeshRenderer
}
public void UpdateEntityAnimation(int entityNum, int frameNum)
public void UpdateEntityAnimation(int entityNum, float frameNum)
{
if (entities.TryGetValue(entityNum, out var entity))
{

11
Assets/Scripts/Modules/GameModule.Interop.cs

@ -16,6 +16,7 @@ public partial class GameModule : CallbackHandler<GameModule>
SetEntityModel = CreateCallback<GameSetEntityModelCallback>(Callback_GameSetEntityModel),
SetEntityTransform = CreateCallback<GameSetEntityTransformCallback>(Callback_GameSetEntityTransform),
RemoveEntity = CreateCallback<GameRemoveEntityCallback>(Callback_GameRemoveEntity),
UpdateEntityAnimation = CreateCallback<GameUpdateEntityAnimationCallback>(Callback_GameUpdateEntityAnimation),
};
RegisterCallbacks(callbacks);
@ -32,6 +33,7 @@ public partial class GameModule : CallbackHandler<GameModule>
public IntPtr SetEntityModel;
public IntPtr SetEntityTransform;
public IntPtr RemoveEntity;
public IntPtr UpdateEntityAnimation;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -60,4 +62,13 @@ public partial class GameModule : CallbackHandler<GameModule>
{
GetSelf(target).RemoveEntity(entityNum);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void GameUpdateEntityAnimationCallback(IntPtr target, int entityNum, float frameNum);
[MonoPInvokeCallback(typeof(GameUpdateEntityAnimationCallback))]
private static void Callback_GameUpdateEntityAnimation(IntPtr target, int entityNum, float frameNum)
{
GetSelf(target).UpdateEntityAnimation(entityNum, frameNum);
}
}

5
Assets/Scripts/Modules/GameModule.cs

@ -58,4 +58,9 @@ public partial class GameModule
{
uq.GameState.RemoveEntity(entityNum);
}
private void UpdateEntityAnimation(int entityNum, float frameNum)
{
uq.GameState.UpdateEntityAnimation(entityNum, frameNum);
}
}

2
Assets/Scripts/Modules/RenderModule.cs

@ -138,6 +138,8 @@ public partial class RenderModule
if (cam == null)
return;
angles.y -= 90; // Don't know why this correction is necessary
cam.transform.position = origin.ToUnityPosition();
cam.transform.rotation = angles.ToUnityRotation();
}

11
Assets/Scripts/Support/AliasModel.cs

@ -38,7 +38,7 @@ public class AliasModel
if (!FindAnimation(frameIndex, out mesh, out int startFrame))
return;
if (mesh.blendShapeCount == 0)
if (mesh == null || mesh.blendShapeCount == 0)
return;
int numFrames = mesh.GetBlendShapeFrameCount(0);
@ -52,15 +52,14 @@ public class AliasModel
for (int i = 0; i < animationMeshes.Count; ++i)
{
if (animationMeshes[i].Item1 > frameIndex)
return true;
startFrame = animationMeshes[i].Item1;
if (frameIndex >= startFrame)
{
mesh = animationMeshes[i].Item2;
return true;
}
}
return false; // Shouldn't happen
return true;
}
public void Dispose()

8
engine/Quake/cl_main.c

@ -71,6 +71,8 @@ CL_ClearState
*/
void CL_ClearState (void)
{
int num;
if (!sv.active)
Host_ClearMemory ();
@ -88,6 +90,10 @@ void CL_ClearState (void)
//johnfitz -- cl_entities is now dynamically allocated
cl_max_edicts = CLAMP (MIN_EDICTS,(int)max_edicts.value,MAX_EDICTS);
cl_entities = (entity_t *) Hunk_AllocName (cl_max_edicts*sizeof(entity_t), "cl_entities");
for (num = 0; num < cl_max_edicts; num++)
{
cl_entities[num].num = num;
}
//johnfitz
}
@ -582,7 +588,7 @@ void CL_RelinkEntities (void)
cl_numvisedicts++;
}
UQ_Game_SetEntityTransform(i, ent->origin, ent->angles);
//UQ_Game_SetEntityTransform(i, ent->origin, ent->angles);
}
}

1
engine/Quake/client.h

@ -375,6 +375,7 @@ void Chase_UpdateForDrawing (void); //johnfitz
void UQ_Game_SetEntityModel(int entityNum, const char *modelName);
void UQ_Game_SetEntityTransform(int entityNum, vec3_t origin, vec3_t angles);
void UQ_Game_RemoveEntity(int entityNum);
void UQ_Game_UpdateEntityAnimation(int entityNum, float frameNum);
#endif /* _CLIENT_H_ */

5
engine/Quake/r_alias.c

@ -470,7 +470,7 @@ void R_SetupAliasFrame (aliashdr_t *paliashdr, int frame, lerpdata_t *lerpdata)
}
else //don't lerp
{
lerpdata->blend = 1;
lerpdata->blend = 0;
lerpdata->pose1 = posenum;
lerpdata->pose2 = posenum;
}
@ -641,6 +641,9 @@ void R_DrawAliasModel (entity_t *e)
R_SetupAliasFrame (paliashdr, e->frame, &lerpdata);
R_SetupEntityTransform (e, &lerpdata);
UQ_Game_SetEntityTransform(e->num, lerpdata.origin, lerpdata.angles);
UQ_Game_UpdateEntityAnimation(e->num, (float)lerpdata.pose1 + lerpdata.blend);
//
// cull it
//

1
engine/Quake/render.h

@ -48,6 +48,7 @@ typedef struct efrag_s
typedef struct entity_s
{
int num; // cache entity number in the entity itself
qboolean forcelink; // model changed
int update_type;

6
engine/UniQuake/game_uniquake.c

@ -9,6 +9,7 @@ typedef struct unity_gamecalls_s
void(*SetEntityModel)(void *target, int entityNum, const char *modelName);
void(*SetEntityTransform)(void *target, int entityNum, vec3_t origin, vec3_t angles);
void(*RemoveEntity)(void *target, int entityNum);
void(*UpdateEntityAnimation)(void *target, int entityNum, float frameNum);
} unity_gamecalls_t;
const unity_gamecalls_t *unity_gamecalls;
@ -27,3 +28,8 @@ void UQ_Game_RemoveEntity(int entityNum)
{
unity_gamecalls->RemoveEntity(unity_gamecalls->target, entityNum);
}
void UQ_Game_UpdateEntityAnimation(int entityNum, float frameNum)
{
unity_gamecalls->UpdateEntityAnimation(unity_gamecalls->target, entityNum, frameNum);
}
Loading…
Cancel
Save