From c5cefca10dfbac6a283c866f7eab853983e42503 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 18 Jul 2021 13:26:15 +0200 Subject: [PATCH] Minor fixes for compatibility issues with QRally: - Handle null frame names when matching with animation regex - Default to skin 0 when the provided skin number is out of range - Convert polygon vertices directly to Unity coordinate positions --- Assets/Scripts/Game/Entity.cs | 5 ++--- Assets/Scripts/Support/AliasModel.cs | 2 +- Assets/Scripts/Support/BrushModel.cs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Game/Entity.cs b/Assets/Scripts/Game/Entity.cs index a72f7f7..78d68a8 100644 --- a/Assets/Scripts/Game/Entity.cs +++ b/Assets/Scripts/Game/Entity.cs @@ -1,5 +1,4 @@ using UnityEngine; -using UnityEngine.Rendering; public class Entity { @@ -142,9 +141,9 @@ public class Entity return; var skins = aliasModel.Textures.Skins; - if (skinNumber >= 0 && skinNumber < skins.Count) + if (skins.Count > 0) { - var skin = skins[skinNumber]; + var skin = skins[skinNumber >= 0 && skinNumber < skins.Count ? skinNumber : 0]; if (skin.Frames.Count > 0) visualStyle.SetAliasModelTextures(material, skin.Frames[0].MainTexture, skin.Frames[0].FullBrightTexture); } diff --git a/Assets/Scripts/Support/AliasModel.cs b/Assets/Scripts/Support/AliasModel.cs index 1cbe976..caa18e2 100644 --- a/Assets/Scripts/Support/AliasModel.cs +++ b/Assets/Scripts/Support/AliasModel.cs @@ -105,7 +105,7 @@ public class AliasModel for (int frameIdx = 0; frameIdx < header.numFrames; ++frameIdx) { // Individual sequences are identified by their prefix - string frameName = AnimationRegex.Match(header.frames[frameIdx].name).Value; + string frameName = AnimationRegex.Match(header.frames[frameIdx].name ?? "").Value; if (animName == null) { animName = frameName; diff --git a/Assets/Scripts/Support/BrushModel.cs b/Assets/Scripts/Support/BrushModel.cs index cc508f0..e2e13be 100644 --- a/Assets/Scripts/Support/BrushModel.cs +++ b/Assets/Scripts/Support/BrushModel.cs @@ -104,7 +104,7 @@ public class BrushModel { for (int vertIdx = 0; vertIdx < polyVerts.Length; ++vertIdx) { - tempVertices.Add(polyVerts[vertIdx].position.ToVector3().ToUnity()); + tempVertices.Add(polyVerts[vertIdx].position.ToUnityPosition()); tempTextureUVs.Add(polyVerts[vertIdx].textureUV.ToVector2()); tempLightmapUVs.Add(polyVerts[vertIdx].lightmapUV.ToVector2()); }