Skip to content

Commit

Permalink
FIXED: MDL 44-59 - Some animation SMD files have NaN due to not corre…
Browse files Browse the repository at this point in the history
…ctly handling the "STUDIO_FRAME_CONST_POS2" flag.
  • Loading branch information
ZeqMacaw committed Feb 3, 2023
1 parent c2286ce commit 6ff6f95
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions Crowbar/Core/GameModel/SourceModel49/SourceMdlFile49.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Crowbar/Core/GameModel/SourceModel49/SourceSmdFile49.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6ff6f95

Please sign in to comment.