Skip to content

Commit

Permalink
working ik chain for v53
Browse files Browse the repository at this point in the history
limited by crowbar itself only writing one link.
  • Loading branch information
IJARika committed Aug 11, 2022
1 parent f417463 commit bd2ffa9
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Public Class SourceMdlBone52
'NOTE: Changed to Double, so that the values will be properly written to file with 6 decimal digits.
' RadianEuler rot;
Public rotation As SourceVector

' Vector
Public unkVector As SourceVector
' Vector rotscale;
Public rotationScale As SourceVector
Expand All @@ -80,12 +80,11 @@ Public Class SourceMdlBone52
Public surfacePropNameOffset As Integer
' int contents; // See BSPFlags.h for the contents flags
Public contents As Integer

' int surfacepropLookup; (this is in normal V49s)
Public unk As Integer

' Vector posscale;
Public positionScale As SourceVector

' Vector
Public unkVector1 As SourceVector

' int unused[8]; // remove as appropriate
Expand Down
35 changes: 20 additions & 15 deletions Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Public Class SourceMdlFile53
Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte()

' In v52 and v53 this is actually used for something, as a float.
Me.theMdlFileData.unkfloat = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.unkfloat = Me.theInputFileReader.ReadSingle()

Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32()
Me.theMdlFileData.flexControllerUiOffset = Me.theInputFileReader.ReadInt32()
Expand Down Expand Up @@ -344,7 +344,7 @@ Public Class SourceMdlFile53
aBone.parentBoneIndex = Me.theInputFileReader.ReadInt32()

'' Skip some fields.
'Me.theInputFileReader.ReadBytes(208)
'Me.theInputFileReader.ReadBytes(244)
'------
For j As Integer = 0 To aBone.boneControllerIndex.Length - 1
aBone.boneControllerIndex(j) = Me.theInputFileReader.ReadInt32()
Expand Down Expand Up @@ -422,11 +422,6 @@ Public Class SourceMdlFile53
aBone.unused(k) = Me.theInputFileReader.ReadInt32()
Next

'TODO: Add to data structure.
'For x As Integer = 1 To 7
' Me.theInputFileReader.ReadInt32()
'Next

Me.theMdlFileData.theBones.Add(aBone)

inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position
Expand Down Expand Up @@ -3217,14 +3212,22 @@ Public Class SourceMdlFile53
Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.ikChainOffset, SeekOrigin.Begin)
fileOffsetStart = Me.theInputFileReader.BaseStream.Position

Me.theMdlFileData.theIkChains = New List(Of SourceMdlIkChain)(Me.theMdlFileData.ikChainCount)
Me.theMdlFileData.theIkChains = New List(Of SourceMdlIkChain53)(Me.theMdlFileData.ikChainCount)
For i As Integer = 0 To Me.theMdlFileData.ikChainCount - 1
ikChainInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position
Dim anIkChain As New SourceMdlIkChain()
Dim anIkChain As New SourceMdlIkChain53()
anIkChain.nameOffset = Me.theInputFileReader.ReadInt32()
anIkChain.linkType = Me.theInputFileReader.ReadInt32()
anIkChain.linkCount = Me.theInputFileReader.ReadInt32()
anIkChain.linkOffset = Me.theInputFileReader.ReadInt32()

anIkChain.idealBendingDirection = New SourceVector
anIkChain.idealBendingDirection.x = Me.theInputFileReader.ReadSingle()
anIkChain.idealBendingDirection.y = Me.theInputFileReader.ReadSingle()
anIkChain.idealBendingDirection.z = Me.theInputFileReader.ReadSingle()

anIkChain.unk = Me.theInputFileReader.ReadInt32()

Me.theMdlFileData.theIkChains.Add(anIkChain)

inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position
Expand Down Expand Up @@ -3252,7 +3255,7 @@ Public Class SourceMdlFile53
End If
End Sub

Private Sub ReadIkLinks(ByVal ikChainInputFileStreamPosition As Long, ByVal anIkChain As SourceMdlIkChain)
Private Sub ReadIkLinks(ByVal ikChainInputFileStreamPosition As Long, ByVal anIkChain As SourceMdlIkChain53)
If anIkChain.linkCount > 0 Then
'Dim ikLinkInputFileStreamPosition As Long
'Dim inputFileStreamPosition As Long
Expand All @@ -3264,14 +3267,15 @@ Public Class SourceMdlFile53
Me.theInputFileReader.BaseStream.Seek(ikChainInputFileStreamPosition + anIkChain.linkOffset, SeekOrigin.Begin)
fileOffsetStart = Me.theInputFileReader.BaseStream.Position

anIkChain.theLinks = New List(Of SourceMdlIkLink)(anIkChain.linkCount)
anIkChain.theLinks = New List(Of SourceMdlIkLink53)(anIkChain.linkCount)

For j As Integer = 0 To anIkChain.linkCount - 1
'ikLinkInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position
Dim anIkLink As New SourceMdlIkLink()
Dim anIkLink As New SourceMdlIkLink53()
anIkLink.boneIndex = Me.theInputFileReader.ReadInt32()
anIkLink.idealBendingDirection.x = Me.theInputFileReader.ReadSingle()
anIkLink.idealBendingDirection.y = Me.theInputFileReader.ReadSingle()
anIkLink.idealBendingDirection.z = Me.theInputFileReader.ReadSingle()
anIkLink.unkVector.x = Me.theInputFileReader.ReadSingle()
anIkLink.unkVector.y = Me.theInputFileReader.ReadSingle()
anIkLink.unkVector.z = Me.theInputFileReader.ReadSingle()
anIkLink.unused0.x = Me.theInputFileReader.ReadSingle()
anIkLink.unused0.y = Me.theInputFileReader.ReadSingle()
anIkLink.unused0.z = Me.theInputFileReader.ReadSingle()
Expand All @@ -3284,6 +3288,7 @@ Public Class SourceMdlFile53

fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1
Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anIkChain.theLinks " + anIkChain.theLinks.Count.ToString())

End If
End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ Public Class SourceMdlBone53
Public surfacePropNameOffset As Integer
' int contents; // See BSPFlags.h for the contents flags
Public contents As Integer

' int surfacepropLookup; (this is in normal V49s)
Public unk As Integer
' int unknown offset for something.
Public unk1 As Integer

' int unused[8]; // remove as appropriate
' int unused[7]; // remove as appropriate
Public unused(6) As Integer

'54 words = 54 * 4 bytes = 216 (0xD8) bytes
'61 words = 61 * 4 bytes = 244 (0xF4) bytes

Public theName As String
Public theAxisInterpBone As SourceMdlAxisInterpBone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@
Public theFlexControllerUis As List(Of SourceMdlFlexControllerUi)
Public theFlexRules As List(Of SourceMdlFlexRule)
Public theHitboxSets As List(Of SourceMdlHitboxSet)
Public theIkChains As List(Of SourceMdlIkChain)
Public theIkChains As List(Of SourceMdlIkChain53)
Public theIkLocks As List(Of SourceMdlIkLock)
Public theKeyValuesText As String
Public theLocalNodeNames As List(Of String)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Public Class SourceMdlIkChain53

'struct mstudioikchain_t
'{
' DECLARE_BYTESWAP_DATADESC();
' int sznameindex;
' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; }
' int linktype;
' int numlinks;
' int linkindex;
' inline mstudioiklink_t *pLink( int i ) const { return (mstudioiklink_t *)(((byte *)this) + linkindex) + i; };
' // FIXME: add unused entries
'};


' int sznameindex;
Public nameOffset As Integer
' int linktype;
Public linkType As Integer
' int numlinks;
Public linkCount As Integer
' int linkindex;
Public linkOffset As Integer
' Vector kneeDir; // ideal bending direction (per link, if applicable)
Public idealBendingDirection As New SourceVector()
' int
Public unk As New Integer

' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; }
Public theName As String
Public theLinks As List(Of SourceMdlIkLink53)

End Class
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Public Class SourceMdlIkLink53

'// ikinfo
'struct mstudioiklink_t
'{
' DECLARE_BYTESWAP_DATADESC();
' int bone;
' Vector kneeDir; // ideal bending direction (per link, if applicable)
' Vector unused0; // unused

' mstudioiklink_t(){}
'private:
' // No copy constructors allowed
' mstudioiklink_t(const mstudioiklink_t& vOther);
'};


' int bone;
Public boneIndex As Integer
' Vector
Public unkVector As New SourceVector()
' Vector unused0; // unused
Public unused0 As New SourceVector()

End Class
6 changes: 3 additions & 3 deletions Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Public Class SourceModel53
mdlFile.ReadFlexControllers()
'NOTE: This must be after flex descs are read so that flex desc usage can be saved in flex desc.
mdlFile.ReadFlexRules()
'mdlFile.ReadIkChains()
mdlFile.ReadIkChains()
'mdlFile.ReadIkLocks()
'mdlFile.ReadMouths()
mdlFile.ReadPoseParamDescs()
Expand Down Expand Up @@ -432,7 +432,7 @@ Public Class SourceModel53
Me.thePhyFileDataGeneric = New SourcePhyFileData()
End If

Dim phyFile As New SourcePhyFile(Me.theInputFileReader, Me.thePhyFileDataGeneric, Me.theMdlFileData.phyOffset)
Dim phyFile As New SourcePhyFile(Me.theInputFileReader, Me.thePhyFileDataGeneric, Me.theMdlFileData.phyOffset + Me.theMdlFileData.phySize)

phyFile.ReadSourcePhyHeader()
If Me.thePhyFileDataGeneric.solidCount > 0 Then
Expand Down Expand Up @@ -495,7 +495,7 @@ Public Class SourceModel53
'End If
qcFile.WriteBodyGroupCommand()
'TODO: LOD option "replacebone" is wrong because bone.flags is read-in incorrectly.
'qcFile.WriteGroup("lod", AddressOf qcFile.WriteGroupLod, False, False)
qcFile.WriteGroup("lod", AddressOf qcFile.WriteGroupLod, False, False)

qcFile.WriteSurfacePropCommand()
qcFile.WriteJointSurfacePropCommand()
Expand Down
6 changes: 3 additions & 3 deletions Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2820,9 +2820,9 @@ Public Class SourceQcFile53

For i As Integer = 0 To Me.theMdlFileData.theIkChains.Count - 1
Dim boneIndex As Integer = Me.theMdlFileData.theIkChains(i).theLinks(Me.theMdlFileData.theIkChains(i).theLinks.Count - 1).boneIndex
offsetX = Math.Round(Me.theMdlFileData.theIkChains(i).theLinks(0).idealBendingDirection.x, 3)
offsetY = Math.Round(Me.theMdlFileData.theIkChains(i).theLinks(0).idealBendingDirection.y, 3)
offsetZ = Math.Round(Me.theMdlFileData.theIkChains(i).theLinks(0).idealBendingDirection.z, 3)
offsetX = Math.Round(Me.theMdlFileData.theIkChains(i).idealBendingDirection.x, 3)
offsetY = Math.Round(Me.theMdlFileData.theIkChains(i).idealBendingDirection.y, 3)
offsetZ = Math.Round(Me.theMdlFileData.theIkChains(i).idealBendingDirection.z, 3)

If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then
line = "$IKChain """
Expand Down
2 changes: 2 additions & 0 deletions Crowbar/Crowbar.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
<Compile Include="Core\GameModel\SourceGlobal\SourceTextureCoordinates.vb" />
<Compile Include="Core\GameModel\SourceModel52\SourceMdlFileData\SourceMdlBone52.vb" />
<Compile Include="Core\GameModel\SourceModel53\SourceMdlFileData\SourceMdlBone53.vb" />
<Compile Include="Core\GameModel\SourceModel53\SourceMdlFileData\SourceMdlIkChain53.vb" />
<Compile Include="Core\GameModel\SourceModel53\SourceMdlFileData\SourceMdlIkLink53.vb" />
<Compile Include="Core\GamePackage\- Base\SourcePackage.vb" />
<Compile Include="Core\GamePackage\ApkFile\ApkDirectoryEntry.vb" />
<Compile Include="Core\GamePackage\ApkFile\ApkFile.vb" />
Expand Down

1 comment on commit bd2ffa9

@IJARika
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also enables LOD since they work now.

Please sign in to comment.