From 6ff6f95ecb3b348be2fc1a28c0b0a015db93919f Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Fri, 3 Feb 2023 10:28:41 -0500 Subject: [PATCH] FIXED: MDL 44-59 - Some animation SMD files have NaN due to not correctly handling the "STUDIO_FRAME_CONST_POS2" flag. --- .../AniFile/AniFile49/BoneConstantInfo49.vb | 3 ++- .../AniFile/AniFile49/SourceAniFrameAnim49.vb | 4 ++++ .../GameModel/SourceModel49/SourceMdlFile49.vb | 14 ++++++++------ .../GameModel/SourceModel49/SourceSmdFile49.vb | 8 +++++++- .../GameModel/SourceModel52/SourceSmdFile52.vb | 8 +++++++- .../GameModel/SourceModel53/SourceMdlFile53.vb | 10 ++++++++-- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/BoneConstantInfo49.vb b/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/BoneConstantInfo49.vb index 940e4736..c8266b22 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/BoneConstantInfo49.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/BoneConstantInfo49.vb @@ -2,6 +2,7 @@ Public Class BoneConstantInfo49 Public theConstantRawPos As SourceVector48bits Public theConstantRawRot As SourceQuaternion48bits - Public theConstantRotationUnknown As SourceQuaternion48bitsViaBytes + Public theConstantPosition2 As SourceVector + Public theConstantRotation2 As SourceQuaternion48bitsViaBytes End Class diff --git a/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/SourceAniFrameAnim49.vb b/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/SourceAniFrameAnim49.vb index 440a0c79..4d9e2c9c 100644 --- a/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/SourceAniFrameAnim49.vb +++ b/Crowbar/Core/GameModel/CompiledFiles/AniFile/AniFile49/SourceAniFrameAnim49.vb @@ -43,6 +43,10 @@ Public Class SourceAniFrameAnim49 Public Const STUDIO_FRAME_ANIMROT As Integer = &H8 Public Const STUDIO_FRAME_FULLANIMPOS As Integer = &H10 + 'FROM: CSGO public\studio.h + '#define STUDIO_FRAME_CONST_POS2 0x20 // Vector in constants + Public Const STUDIO_FRAME_CONST_POS2 As Integer = &H20 + 'Public Const STUDIO_FRAME_UNKNOWN01 As Integer = &H40 ' Seems to be 6 rotation bytes in constants based on tests. New format that is not Quaternion48. Maybe Quaternion48Smallest3? 'Public Const STUDIO_FRAME_UNKNOWN02 As Integer = &H80 ' Seems to be 6 rotation bytes in framedata based on tests. New format that is not Quaternion48. Maybe Quaternion48Smallest3? 'FROM: Kerry at Valve via Splinks on 24-Apr-2017 diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb index 7b1b42c3..0b0b14d6 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb @@ -1304,8 +1304,14 @@ Public Class SourceMdlFile49 boneFlag = aSectionOfAnimation.theBoneFlags(boneIndex) If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_ROT2) > 0 Then - aBoneConstantInfo.theConstantRotationUnknown = New SourceQuaternion48bitsViaBytes() - aBoneConstantInfo.theConstantRotationUnknown.theBytes = Me.theInputFileReader.ReadBytes(6) + aBoneConstantInfo.theConstantRotation2 = New SourceQuaternion48bitsViaBytes() + aBoneConstantInfo.theConstantRotation2.theBytes = Me.theInputFileReader.ReadBytes(6) + End If + If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_POS2) > 0 Then + aBoneConstantInfo.theConstantPosition2 = New SourceVector() + aBoneConstantInfo.theConstantPosition2.x = Me.theInputFileReader.ReadSingle() + aBoneConstantInfo.theConstantPosition2.y = Me.theInputFileReader.ReadSingle() + aBoneConstantInfo.theConstantPosition2.z = Me.theInputFileReader.ReadSingle() End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWROT) > 0 Then aBoneConstantInfo.theConstantRawRot = New SourceQuaternion48bits() @@ -1319,10 +1325,6 @@ Public Class SourceMdlFile49 aBoneConstantInfo.theConstantRawPos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() aBoneConstantInfo.theConstantRawPos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() End If - 'If (boneFlag And SourceAniFrameAnim.STUDIO_FRAME_CONST_ROT2) > 0 Then - ' aBoneConstantInfo.theConstantRotationUnknown = New SourceQuaternion48bitsViaBytes() - ' aBoneConstantInfo.theConstantRotationUnknown.theBytes = Me.theInputFileReader.ReadBytes(6) - 'End If Next If Me.theInputFileReader.BaseStream.Position > fileOffsetStart Then diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb index d3faf66c..0395f2e4 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb @@ -570,8 +570,14 @@ Public Class SourceSmdFile49 aFrameLine.position.z = aBoneConstantInfo.theConstantRawPos.z aFrameLine.position.debug_text = "RAWPOS" End If + If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_POS2) > 0 Then + aFrameLine.position.x = aBoneConstantInfo.theConstantPosition2.x + aFrameLine.position.y = aBoneConstantInfo.theConstantPosition2.y + aFrameLine.position.z = aBoneConstantInfo.theConstantPosition2.z + aFrameLine.position.debug_text = "FRAME_CONST_POS2" + End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_ROT2) > 0 Then - aFrameLine.rotation = MathModule.ToEulerAngles(aBoneConstantInfo.theConstantRotationUnknown.quaternion) + aFrameLine.rotation = MathModule.ToEulerAngles(aBoneConstantInfo.theConstantRotation2.quaternion) aFrameLine.rotation.debug_text = "FRAME_CONST_ROT2" End If End If diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb index e0588b7f..03858544 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb @@ -419,8 +419,14 @@ Public Class SourceSmdFile52 aFrameLine.position.z = aBoneConstantInfo.theConstantRawPos.z aFrameLine.position.debug_text = "RAWPOS" End If + If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_POS2) > 0 Then + aFrameLine.position.x = aBoneConstantInfo.theConstantPosition2.x + aFrameLine.position.y = aBoneConstantInfo.theConstantPosition2.y + aFrameLine.position.z = aBoneConstantInfo.theConstantPosition2.z + aFrameLine.position.debug_text = "FRAME_CONST_POS2" + End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_ROT2) > 0 Then - aFrameLine.rotation = MathModule.ToEulerAngles(aBoneConstantInfo.theConstantRotationUnknown.quaternion) + aFrameLine.rotation = MathModule.ToEulerAngles(aBoneConstantInfo.theConstantRotation2.quaternion) aFrameLine.rotation.debug_text = "FRAME_CONST_ROT2" End If End If diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 5163b81c..d1a8ba54 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1256,8 +1256,14 @@ Public Class SourceMdlFile53 boneFlag = aSectionOfAnimation.theBoneFlags(boneIndex) If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_ROT2) > 0 Then - aBoneConstantInfo.theConstantRotationUnknown = New SourceQuaternion48bitsViaBytes() - aBoneConstantInfo.theConstantRotationUnknown.theBytes = Me.theInputFileReader.ReadBytes(6) + aBoneConstantInfo.theConstantRotation2 = New SourceQuaternion48bitsViaBytes() + aBoneConstantInfo.theConstantRotation2.theBytes = Me.theInputFileReader.ReadBytes(6) + End If + If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_POS2) > 0 Then + aBoneConstantInfo.theConstantPosition2 = New SourceVector() + aBoneConstantInfo.theConstantPosition2.x = Me.theInputFileReader.ReadSingle() + aBoneConstantInfo.theConstantPosition2.y = Me.theInputFileReader.ReadSingle() + aBoneConstantInfo.theConstantPosition2.z = Me.theInputFileReader.ReadSingle() End If If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWROT) > 0 Then aBoneConstantInfo.theConstantRawRot = New SourceQuaternion48bits()