diff --git a/AssetStudio/Classes/VideoClip.cs b/AssetStudio/Classes/VideoClip.cs index 504ff47..dbefcd2 100644 --- a/AssetStudio/Classes/VideoClip.cs +++ b/AssetStudio/Classes/VideoClip.cs @@ -20,7 +20,7 @@ namespace AssetStudio var m_ProxyHeight = reader.ReadUInt32(); var Width = reader.ReadUInt32(); var Height = reader.ReadUInt32(); - if (version[0] >= 2017) //2017.x and up + if (version[0] > 2017 || (version[0] == 2017 && version[1] >= 2)) //2017.2 and up { var m_PixelAspecRatioNum = reader.ReadUInt32(); var m_PixelAspecRatioDen = reader.ReadUInt32(); diff --git a/AssetStudio/Math/Matrix4x4f.cs b/AssetStudio/Math/Matrix4x4f.cs index 40c2e35..429afc7 100644 --- a/AssetStudio/Math/Matrix4x4f.cs +++ b/AssetStudio/Math/Matrix4x4f.cs @@ -83,7 +83,7 @@ namespace AssetStudio case 13: return M13; case 14: return M23; case 15: return M33; - default: throw new IndexOutOfRangeException("Invalid matrix index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Matrix4x4 index!"); } } @@ -107,7 +107,7 @@ namespace AssetStudio case 13: M13 = value; break; case 14: M23 = value; break; case 15: M33 = value; break; - default: throw new IndexOutOfRangeException("Invalid matrix index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Matrix4x4 index!"); } } } diff --git a/AssetStudio/Math/Quaternion.cs b/AssetStudio/Math/Quaternion.cs index 063d1f2..ca129f5 100644 --- a/AssetStudio/Math/Quaternion.cs +++ b/AssetStudio/Math/Quaternion.cs @@ -29,7 +29,7 @@ namespace AssetStudio case 1: return Y; case 2: return Z; case 3: return W; - default: throw new IndexOutOfRangeException("Invalid Quaternion index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Quaternion index!"); } } @@ -41,7 +41,7 @@ namespace AssetStudio case 1: Y = value; break; case 2: Z = value; break; case 3: W = value; break; - default: throw new IndexOutOfRangeException("Invalid Quaternion index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Quaternion index!"); } } } @@ -62,5 +62,27 @@ namespace AssetStudio { return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && W.Equals(other.W); } + + public static float Dot(Quaternion a, Quaternion b) + { + return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W; + } + + private static bool IsEqualUsingDot(float dot) + { + return dot > 1.0f - kEpsilon; + } + + public static bool operator ==(Quaternion lhs, Quaternion rhs) + { + return IsEqualUsingDot(Dot(lhs, rhs)); + } + + public static bool operator !=(Quaternion lhs, Quaternion rhs) + { + return !(lhs == rhs); + } + + private const float kEpsilon = 0.000001F; } } diff --git a/AssetStudio/Math/Vector2.cs b/AssetStudio/Math/Vector2.cs index 18e9268..bfcfa0d 100644 --- a/AssetStudio/Math/Vector2.cs +++ b/AssetStudio/Math/Vector2.cs @@ -23,8 +23,7 @@ namespace AssetStudio { case 0: return X; case 1: return Y; - default: - throw new IndexOutOfRangeException("Invalid Vector2 index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Vector2 index!"); } } @@ -34,8 +33,7 @@ namespace AssetStudio { case 0: X = value; break; case 1: Y = value; break; - default: - throw new IndexOutOfRangeException("Invalid Vector2 index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Vector2 index!"); } } } diff --git a/AssetStudio/Math/Vector3.cs b/AssetStudio/Math/Vector3.cs index 9bd5c4b..31402e4 100644 --- a/AssetStudio/Math/Vector3.cs +++ b/AssetStudio/Math/Vector3.cs @@ -26,8 +26,7 @@ namespace AssetStudio case 0: return X; case 1: return Y; case 2: return Z; - default: - throw new IndexOutOfRangeException("Invalid Vector3 index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Vector3 index!"); } } @@ -38,8 +37,7 @@ namespace AssetStudio case 0: X = value; break; case 1: Y = value; break; case 2: Z = value; break; - default: - throw new IndexOutOfRangeException("Invalid Vector3 index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Vector3 index!"); } } } diff --git a/AssetStudio/Math/Vector4.cs b/AssetStudio/Math/Vector4.cs index ed4dc7a..fdac8fd 100644 --- a/AssetStudio/Math/Vector4.cs +++ b/AssetStudio/Math/Vector4.cs @@ -37,7 +37,7 @@ namespace AssetStudio case 1: return Y; case 2: return Z; case 3: return W; - default: throw new IndexOutOfRangeException("Invalid Vector4 index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Vector4 index!"); } } @@ -49,7 +49,7 @@ namespace AssetStudio case 1: Y = value; break; case 2: Z = value; break; case 3: W = value; break; - default: throw new IndexOutOfRangeException("Invalid Vector4 index!"); + default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid Vector4 index!"); } } } diff --git a/AssetStudioUtility/ModelConverter.cs b/AssetStudioUtility/ModelConverter.cs index 165d1fc..fcc0d1c 100644 --- a/AssetStudioUtility/ModelConverter.cs +++ b/AssetStudioUtility/ModelConverter.cs @@ -380,10 +380,11 @@ namespace AssetStudio } } } - else if (mesh.m_BindPose.Length > 0 && mesh.m_BoneNameHashes?.Length > 0 && mesh.m_BindPose.Length == mesh.m_BoneNameHashes.Length) + else if (mesh.m_BindPose.Length > 0 && mesh.m_BoneNameHashes?.Length > 0) { - iMesh.BoneList = new List(mesh.m_BoneNameHashes.Length); - for (int i = 0; i < mesh.m_BoneNameHashes.Length; i++) + var boneMax = Math.Min(mesh.m_BindPose.Length, mesh.m_BoneNameHashes.Length); + iMesh.BoneList = new List(boneMax); + for (int i = 0; i < boneMax; i++) { var bone = new ImportedBone(); var boneHash = mesh.m_BoneNameHashes[i];