From 2c59443ee26ce00e6fed540aa233d943c1f6e680 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Wed, 10 Aug 2022 20:53:28 -0400 Subject: [PATCH 01/39] fixes jiggle bones on v53 --- .../SourceModel53/SourceMdlFile53.vb | 303 ++++++++---------- .../SourceMdlFileData/SourceMdlBone53.vb | 235 ++++++++++++++ .../SourceMdlFileData/SourceMdlFileData53.vb | 67 ++-- .../GameModel/SourceModel53/SourceModel53.vb | 27 +- .../GameModel/SourceModel53/SourceQcFile53.vb | 132 ++++---- .../SourceModel53/SourceSmdFile53.vb | 16 +- .../SourceModel53/SourceVrdFile53.vb | 12 +- Crowbar/Crowbar.vbproj | 3 +- CrowbarLauncher/CrowbarLauncher.vbproj | 2 +- CrowbarSteamPipe/CrowbarSteamPipe.vbproj | 2 +- 10 files changed, 500 insertions(+), 299 deletions(-) create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 6de58e3..23beff4 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -56,11 +56,11 @@ Public Class SourceMdlFile53 End Sub Public Sub ReadMdlHeader01(ByVal logDescription As String) - Dim inputFileStreamPosition As Long + 'Dim inputFileStreamPosition As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long - Dim fileOffsetStart2 As Long - Dim fileOffsetEnd2 As Long + 'Dim fileOffsetStart2 As Long + 'Dim fileOffsetEnd2 As Long fileOffsetStart = Me.theInputFileReader.BaseStream.Position @@ -175,8 +175,9 @@ Public Class SourceMdlFile53 Me.theMdlFileData.ikChainOffset = Me.theInputFileReader.ReadInt32() ' Offsets: 0x0124 (), 0x0128 () - Me.theMdlFileData.mouthCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.mouthOffset = Me.theInputFileReader.ReadInt32() + ' This is used for rui (respawns vgui sidegrade) meshes. + Me.theMdlFileData.ruiCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.ruiOffset = Me.theInputFileReader.ReadInt32() ' Offsets: 0x012C (), 0x0130 () Me.theMdlFileData.localPoseParamaterCount = Me.theInputFileReader.ReadInt32() @@ -219,50 +220,48 @@ Public Class SourceMdlFile53 Me.theMdlFileData.virtualModelP = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.animBlockNameOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.animBlockCount = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.animBlockOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.animBlockModelP = Me.theInputFileReader.ReadInt32() - If Me.theMdlFileData.animBlockCount > 0 Then - If Me.theMdlFileData.animBlockNameOffset > 0 Then - inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.animBlockNameOffset, SeekOrigin.Begin) - fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position - - Me.theMdlFileData.theAnimBlockRelativePathFileName = FileManager.ReadNullTerminatedString(Me.theInputFileReader) - - fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 - If Not Me.theMdlFileData.theFileSeekLog.ContainsKey(fileOffsetStart2) Then - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart2, fileOffsetEnd2, "theAnimBlockRelativePathFileName = " + Me.theMdlFileData.theAnimBlockRelativePathFileName) - End If - Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - End If - If Me.theMdlFileData.animBlockOffset > 0 Then - inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.animBlockOffset, SeekOrigin.Begin) - fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position - - Me.theMdlFileData.theAnimBlocks = New List(Of SourceMdlAnimBlock)(Me.theMdlFileData.animBlockCount) - For offset As Integer = 0 To Me.theMdlFileData.animBlockCount - 1 - Dim anAnimBlock As New SourceMdlAnimBlock() - anAnimBlock.dataStart = Me.theInputFileReader.ReadInt32() - anAnimBlock.dataEnd = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.theAnimBlocks.Add(anAnimBlock) - Next - - fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 - If Not Me.theMdlFileData.theFileSeekLog.ContainsKey(fileOffsetStart2) Then - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart2, fileOffsetEnd2, "theAnimBlocks " + Me.theMdlFileData.theAnimBlocks.Count.ToString()) - End If - Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - End If - End If + ' Not present in V53 from what I have found. + 'Me.theMdlFileData.animBlockNameOffset = Me.theInputFileReader.ReadInt32() + 'Me.theMdlFileData.animBlockCount = Me.theInputFileReader.ReadInt32() + 'Me.theMdlFileData.animBlockOffset = Me.theInputFileReader.ReadInt32() + 'Me.theMdlFileData.animBlockModelP = Me.theInputFileReader.ReadInt32() + 'If Me.theMdlFileData.animBlockCount > 0 Then + ' If Me.theMdlFileData.animBlockNameOffset > 0 Then + ' inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + ' Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.animBlockNameOffset, SeekOrigin.Begin) + ' fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position + + ' Me.theMdlFileData.theAnimBlockRelativePathFileName = FileManager.ReadNullTerminatedString(Me.theInputFileReader) + + ' fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 + ' If Not Me.theMdlFileData.theFileSeekLog.ContainsKey(fileOffsetStart2) Then + ' Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart2, fileOffsetEnd2, "theAnimBlockRelativePathFileName = " + Me.theMdlFileData.theAnimBlockRelativePathFileName) + ' End If + ' Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + ' End If + ' If Me.theMdlFileData.animBlockOffset > 0 Then + ' inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + ' Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.animBlockOffset, SeekOrigin.Begin) + ' fileOffsetStart2 = Me.theInputFileReader.BaseStream.Position + + ' Me.theMdlFileData.theAnimBlocks = New List(Of SourceMdlAnimBlock)(Me.theMdlFileData.animBlockCount) + ' For offset As Integer = 0 To Me.theMdlFileData.animBlockCount - 1 + ' Dim anAnimBlock As New SourceMdlAnimBlock() + ' anAnimBlock.dataStart = Me.theInputFileReader.ReadInt32() + ' anAnimBlock.dataEnd = Me.theInputFileReader.ReadInt32() + ' Me.theMdlFileData.theAnimBlocks.Add(anAnimBlock) + ' Next + + ' fileOffsetEnd2 = Me.theInputFileReader.BaseStream.Position - 1 + ' If Not Me.theMdlFileData.theFileSeekLog.ContainsKey(fileOffsetStart2) Then + ' Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart2, fileOffsetEnd2, "theAnimBlocks " + Me.theMdlFileData.theAnimBlocks.Count.ToString()) + ' End If + ' Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + ' End If + 'End If Me.theMdlFileData.boneTableByNameOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.vertexBaseP = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.indexBaseP = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.directionalLightDot = Me.theInputFileReader.ReadByte() Me.theMdlFileData.rootLod = Me.theInputFileReader.ReadByte() @@ -271,50 +270,48 @@ Public Class SourceMdlFile53 Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte() - Me.theMdlFileData.unused4 = Me.theInputFileReader.ReadInt32() + ' In v52 and v53 this is actually used for something, as a float. + Me.theMdlFileData.unkfloat = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.flexControllerUiOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.vertAnimFixedPointScale = Me.theInputFileReader.ReadSingle() - Me.theMdlFileData.surfacePropLookup = Me.theInputFileReader.ReadInt32() - - Me.theMdlFileData.studioHeader2Offset = Me.theInputFileReader.ReadInt32() - - Me.theMdlFileData.unknownOffset01 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vertexBaseP = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.indexBaseP = Me.theInputFileReader.ReadInt32() - If Me.theMdlFileData.bodyPartCount = 0 AndAlso Me.theMdlFileData.localSequenceCount > 0 Then - Me.theMdlFileData.theMdlFileOnlyHasAnimations = True - End If + ' This offset is to their dumped maya strings. + Me.theMdlFileData.mayaOffset = Me.theInputFileReader.ReadInt32() - 'Me.theMdlFileData.sourceBoneTransformCount = Me.theInputFileReader.ReadInt32() - 'Me.theMdlFileData.sourceBoneTransformOffset = Me.theInputFileReader.ReadInt32() - 'Me.theMdlFileData.illumPositionAttachmentIndex = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.sourceBoneTransformCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.sourceBoneTransformOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.illumPositionAttachmentIndex = Me.theInputFileReader.ReadInt32() 'Me.theMdlFileData.maxEyeDeflection = Me.theInputFileReader.ReadSingle() - 'Me.theMdlFileData.linearBoneOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.linearBoneOffset = Me.theInputFileReader.ReadInt32() - 'Me.theMdlFileData.nameOffset = Me.theInputFileReader.ReadInt32() - 'Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32() - 'Me.theMdlFileData.boneFlexDriverOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.boneFlexDriverOffset = Me.theInputFileReader.ReadInt32() - 'For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1 - ' Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32() - 'Next - '====== + 'Me.theMdlFileData.vertAnimFixedPointScale = Me.theInputFileReader.ReadSingle() + 'Me.theMdlFileData.surfacePropLookup = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unknownOffset01 = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.unknown01 = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.unknown02 = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.unknown03 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown04 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unknownOffset02 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vtxOffset = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.vvdOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown05 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vvcOffset = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.phyOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown06 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown07 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown08 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown09 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknownOffset02 = Me.theInputFileReader.ReadInt32() + ' File sizes in order of: vtx, vvd, vvc, and vphy. + Me.theMdlFileData.vtxSize = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vvdSize = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.vvcSize = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.phySize = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unknownOffset03 = Me.theInputFileReader.ReadInt32() For x As Integer = 0 To Me.theMdlFileData.unknown.Length - 1 Me.theMdlFileData.unknown(x) = Me.theInputFileReader.ReadInt32() @@ -337,10 +334,10 @@ Public Class SourceMdlFile53 Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.boneOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position - Me.theMdlFileData.theBones = New List(Of SourceMdlBone)(Me.theMdlFileData.boneCount) + Me.theMdlFileData.theBones = New List(Of SourceMdlBone53)(Me.theMdlFileData.boneCount) For i As Integer = 0 To Me.theMdlFileData.boneCount - 1 boneInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim aBone As New SourceMdlBone() + Dim aBone As New SourceMdlBone53() aBone.nameOffset = Me.theInputFileReader.ReadInt32() @@ -367,6 +364,12 @@ Public Class SourceMdlFile53 aBone.rotation.x = Me.theInputFileReader.ReadSingle() aBone.rotation.y = Me.theInputFileReader.ReadSingle() aBone.rotation.z = Me.theInputFileReader.ReadSingle() + + aBone.unkVector = New SourceVector() + aBone.unkVector.x = Me.theInputFileReader.ReadSingle() + aBone.unkVector.y = Me.theInputFileReader.ReadSingle() + aBone.unkVector.z = Me.theInputFileReader.ReadSingle() + aBone.positionScale = New SourceVector() aBone.positionScale.x = Me.theInputFileReader.ReadSingle() aBone.positionScale.y = Me.theInputFileReader.ReadSingle() @@ -376,6 +379,11 @@ Public Class SourceMdlFile53 aBone.rotationScale.y = Me.theInputFileReader.ReadSingle() aBone.rotationScale.z = Me.theInputFileReader.ReadSingle() + aBone.unkVector1 = New SourceVector() + aBone.unkVector1.x = Me.theInputFileReader.ReadSingle() + aBone.unkVector1.y = Me.theInputFileReader.ReadSingle() + aBone.unkVector1.z = Me.theInputFileReader.ReadSingle() + aBone.poseToBoneColumn0 = New SourceVector() aBone.poseToBoneColumn1 = New SourceVector() aBone.poseToBoneColumn2 = New SourceVector() @@ -407,14 +415,17 @@ Public Class SourceMdlFile53 aBone.surfacePropNameOffset = Me.theInputFileReader.ReadInt32() aBone.contents = Me.theInputFileReader.ReadInt32() - For k As Integer = 0 To 7 + aBone.unk = Me.theInputFileReader.ReadInt32() + aBone.unk1 = Me.theInputFileReader.ReadInt32() + + For k As Integer = 0 To 6 aBone.unused(k) = Me.theInputFileReader.ReadInt32() Next 'TODO: Add to data structure. - For x As Integer = 1 To 7 - Me.theInputFileReader.ReadInt32() - Next + 'For x As Integer = 1 To 7 + ' Me.theInputFileReader.ReadInt32() + 'Next Me.theMdlFileData.theBones.Add(aBone) @@ -437,12 +448,12 @@ Public Class SourceMdlFile53 aBone.theName = Me.GetStringAtOffset(boneInputFileStreamPosition, aBone.nameOffset, "aBone.theName") If aBone.proceduralRuleOffset <> 0 Then - If aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_AXISINTERP Then + If aBone.proceduralRuleType = SourceMdlBone53.STUDIO_PROC_AXISINTERP Then Me.ReadAxisInterpBone(boneInputFileStreamPosition, aBone) - ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_QUATINTERP Then + ElseIf aBone.proceduralRuleType = SourceMdlBone53.STUDIO_PROC_QUATINTERP Then Me.theMdlFileData.theProceduralBonesCommandIsUsed = True Me.ReadQuatInterpBone(boneInputFileStreamPosition, aBone) - ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_JIGGLE Then + ElseIf aBone.proceduralRuleType = SourceMdlBone53.STUDIO_PROC_JIGGLE Then Me.ReadJiggleBone(boneInputFileStreamPosition, aBone) End If End If @@ -474,7 +485,7 @@ Public Class SourceMdlFile53 End Sub 'TODO: VERIFY ReadAxisInterpBone() - Private Sub ReadAxisInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone) + Private Sub ReadAxisInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone53) Dim axisInterpBoneInputFileStreamPosition As Long Dim inputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -513,7 +524,7 @@ Public Class SourceMdlFile53 End Try End Sub - Private Sub ReadQuatInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone) + Private Sub ReadQuatInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone53) Dim quatInterpBoneInputFileStreamPosition As Long Dim inputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -583,7 +594,7 @@ Public Class SourceMdlFile53 End Try End Sub - Private Sub ReadJiggleBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone) + Private Sub ReadJiggleBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone53) Dim fileOffsetStart As Long Dim fileOffsetEnd As Long @@ -857,19 +868,16 @@ Public Class SourceMdlFile53 aHitbox.boundingBoxMax.y = Me.theInputFileReader.ReadSingle() aHitbox.boundingBoxMax.z = Me.theInputFileReader.ReadSingle() aHitbox.nameOffset = Me.theInputFileReader.ReadInt32() - 'NOTE: Roll (z) is first. - aHitbox.boundingBoxPitchYawRoll.z = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxPitchYawRoll.x = Me.theInputFileReader.ReadSingle() - aHitbox.boundingBoxPitchYawRoll.y = Me.theInputFileReader.ReadSingle() - 'aHitbox.unknown = Me.theInputFileReader.ReadInt32() - 'For x As Integer = 0 To aHitbox.unused_VERSION49.Length - 1 - ' aHitbox.unused_VERSION49(x) = Me.theInputFileReader.ReadInt32() - 'Next + aHitbox.unused(0) = Me.theInputFileReader.ReadInt32() + ' This is actually an index into a KV if it has one, unsure how it works tbh. aHitbox.unused(1) = Me.theInputFileReader.ReadInt32() aHitbox.unused(2) = Me.theInputFileReader.ReadInt32() aHitbox.unused(3) = Me.theInputFileReader.ReadInt32() aHitbox.unused(4) = Me.theInputFileReader.ReadInt32() + aHitbox.unused(5) = Me.theInputFileReader.ReadInt32() + aHitbox.unused(6) = Me.theInputFileReader.ReadInt32() + aHitbox.unused(7) = Me.theInputFileReader.ReadInt32() aHitboxSet.theHitboxes.Add(aHitbox) @@ -1171,18 +1179,18 @@ Public Class SourceMdlFile53 'NOTE: This code is reached by DoI's doi_models_dir_vpk\models\weapons\v_g43.mdl and v_vickers.mdl. fileOffsetStart = animInputFileStreamPosition + anAnimationDesc.spanOffset fileOffsetEnd = animInputFileStreamPosition + anAnimationDesc.spanOffset - 1 - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 For boneIndex As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(boneIndex) - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_POS) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_HAS_SAVEFRAME_POS) > 0 Then 'SourceVector48bits (6 bytes) fileOffsetEnd += anAnimationDesc.spanCount * 6 End If - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_HAS_SAVEFRAME_ROT) > 0 Then 'SourceQuaternion64bits (8 bytes) fileOffsetEnd += anAnimationDesc.spanCount * 8 End If - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT32) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_HAS_SAVEFRAME_ROT32) > 0 Then 'SourceQuaternion32bits (4 bytes) fileOffsetEnd += anAnimationDesc.spanCount * 4 End If @@ -3314,45 +3322,6 @@ Public Class SourceMdlFile53 End If End Sub - Public Sub ReadMouths() - If Me.theMdlFileData.mouthCount > 0 Then - 'Dim mouthInputFileStreamPosition As Long - 'Dim inputFileStreamPosition As Long - Dim fileOffsetStart As Long - Dim fileOffsetEnd As Long - 'Dim fileOffsetStart2 As Long - 'Dim fileOffsetEnd2 As Long - - Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.mouthOffset, SeekOrigin.Begin) - fileOffsetStart = Me.theInputFileReader.BaseStream.Position - - Me.theMdlFileData.theMouths = New List(Of SourceMdlMouth)(Me.theMdlFileData.mouthCount) - For i As Integer = 0 To Me.theMdlFileData.mouthCount - 1 - 'mouthInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim aMouth As New SourceMdlMouth() - - aMouth.boneIndex = Me.theInputFileReader.ReadInt32() - aMouth.forward.x = Me.theInputFileReader.ReadSingle() - aMouth.forward.y = Me.theInputFileReader.ReadSingle() - aMouth.forward.z = Me.theInputFileReader.ReadSingle() - aMouth.flexDescIndex = Me.theInputFileReader.ReadInt32() - - Me.theMdlFileData.theMouths.Add(aMouth) - - 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - - 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - Next - - If Me.theMdlFileData.theMouths.Count > 0 Then - Me.theMdlFileData.theModelCommandIsUsed = True - End If - - fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theMouths " + Me.theMdlFileData.theMouths.Count.ToString()) - End If - End Sub - Public Sub ReadPoseParamDescs() If Me.theMdlFileData.localPoseParamaterCount > 0 Then Dim poseInputFileStreamPosition As Long @@ -3882,7 +3851,7 @@ Public Class SourceMdlFile53 'If Me.theMdlFileData.studioHeader2Offset_VERSION48 + Me.theMdlFileData.linearBoneOffset <> Me.theInputFileReader.BaseStream.Position Then ' Dim debug As Integer = 4242 'End If - Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.studioHeader2Offset + Me.theMdlFileData.linearBoneOffset, SeekOrigin.Begin) + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.linearBoneOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position boneTableInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -4272,35 +4241,35 @@ Public Class SourceMdlFile53 Me.theOutputFileWriter.Write(Convert.ToByte(0)) End Sub - Public Sub WriteInternalAniFileName(ByVal internalAniFileName As String) - If Me.theMdlFileData.animBlockCount > 0 Then - If Me.theMdlFileData.animBlockNameOffset > 0 Then - ' Set a new offset for the file name at end-of-file's second null byte. - Me.theOutputFileWriter.BaseStream.Seek(-2, SeekOrigin.End) - 'NOTE: Important that offset be an Integer (4 bytes) rather than a Long (8 bytes). - Dim offset As Integer - offset = CInt(Me.theOutputFileWriter.BaseStream.Position) - Me.theOutputFileWriter.BaseStream.Seek(&H15C, SeekOrigin.Begin) - Me.theOutputFileWriter.Write(offset) - - ' Write the new file name. - Me.theOutputFileWriter.BaseStream.Seek(offset, SeekOrigin.Begin) - Me.theOutputFileWriter.Write(internalAniFileName.ToCharArray()) - 'NOTE: Write the ending null byte. - Me.theOutputFileWriter.Write(Convert.ToByte(0)) - - ' Write the new end-of-file's null bytes. - Me.theOutputFileWriter.Write(Convert.ToByte(0)) - Me.theOutputFileWriter.Write(Convert.ToByte(0)) - - ' Write the new file size. - Me.theOutputFileWriter.BaseStream.Seek(0, SeekOrigin.End) - offset = CInt(Me.theOutputFileWriter.BaseStream.Position) - Me.theOutputFileWriter.BaseStream.Seek(&H4C, SeekOrigin.Begin) - Me.theOutputFileWriter.Write(offset) - End If - End If - End Sub + 'Public Sub WriteInternalAniFileName(ByVal internalAniFileName As String) + ' If Me.theMdlFileData.animBlockCount > 0 Then + ' If Me.theMdlFileData.animBlockNameOffset > 0 Then + ' ' Set a new offset for the file name at end-of-file's second null byte. + ' Me.theOutputFileWriter.BaseStream.Seek(-2, SeekOrigin.End) + 'NOTE: Important that offset be an Integer (4 bytes) rather than a Long (8 bytes). + ' Dim offset As Integer + ' offset = CInt(Me.theOutputFileWriter.BaseStream.Position) + ' Me.theOutputFileWriter.BaseStream.Seek(&H15C, SeekOrigin.Begin) + ' Me.theOutputFileWriter.Write(offset) + + ' Write the new file name. + ' Me.theOutputFileWriter.BaseStream.Seek(offset, SeekOrigin.Begin) + ' Me.theOutputFileWriter.Write(internalAniFileName.ToCharArray()) + 'NOTE: Write the ending null byte. + ' Me.theOutputFileWriter.Write(Convert.ToByte(0)) + + ' Write the new end-of-file's null bytes. + ' Me.theOutputFileWriter.Write(Convert.ToByte(0)) + ' Me.theOutputFileWriter.Write(Convert.ToByte(0)) + + ' Write the new file size. + ' Me.theOutputFileWriter.BaseStream.Seek(0, SeekOrigin.End) + ' offset = CInt(Me.theOutputFileWriter.BaseStream.Position) + ' Me.theOutputFileWriter.BaseStream.Seek(&H4C, SeekOrigin.Begin) + ' Me.theOutputFileWriter.Write(offset) + ' End If + ' End If + 'End Sub #End Region diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb new file mode 100644 index 0000000..577c8ed --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb @@ -0,0 +1,235 @@ +Public Class SourceMdlBone53 + + 'FROM: SourceEngineXXXX_source\public\studio.h + '// bones + 'struct mstudiobone_t + '{ + ' DECLARE_BYTESWAP_DATADESC(); + ' int sznameindex; + ' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; } + ' int parent; // parent bone + ' int bonecontroller[6]; // bone controller index, -1 == none + + ' // default values + ' Vector pos; + ' Quaternion quat; + ' RadianEuler rot; + ' // compression scale + ' Vector posscale; + ' Vector rotscale; + + ' matrix3x4_t poseToBone; + ' Quaternion qAlignment; + ' int flags; + ' int proctype; + ' int procindex; // procedural rule + ' mutable int physicsbone; // index into physically simulated bone + ' inline void *pProcedure( ) const { if (procindex == 0) return NULL; else return (void *)(((byte *)this) + procindex); }; + ' int surfacepropidx; // index into string tablefor property name + ' inline char * const pszSurfaceProp( void ) const { return ((char *)this) + surfacepropidx; } + ' int contents; // See BSPFlags.h for the contents flags + + ' int unused[8]; // remove as appropriate + + ' mstudiobone_t(){} + 'private: + ' // No copy constructors allowed + ' mstudiobone_t(const mstudiobone_t& vOther); + '}; + + ' int sznameindex; + Public nameOffset As Integer + + ' int parent; // parent bone + Public parentBoneIndex As Integer + ' int bonecontroller[6]; // bone controller index, -1 == none + Public boneControllerIndex(5) As Integer + + 'NOTE: Changed to Double, so that the values will be properly written to file with 6 decimal digits. + ' Vector pos; + Public position As SourceVector + + ' Quaternion quat; + Public quat As SourceQuaternion + + '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 posscale; + Public positionScale As SourceVector + ' Vector rotscale; + Public rotationScale As SourceVector + ' Vector + Public unkVector1 As SourceVector + + ' matrix3x4_t poseToBone; + Public poseToBoneColumn0 As SourceVector + Public poseToBoneColumn1 As SourceVector + Public poseToBoneColumn2 As SourceVector + Public poseToBoneColumn3 As SourceVector + ' Quaternion qAlignment; + Public qAlignment As SourceQuaternion + ' int flags; + Public flags As Integer + ' int proctype; + Public proceduralRuleType As Integer + ' int procindex; // procedural rule + ' inline void *pProcedure( ) const { if (procindex == 0) return NULL; else return (void *)(((byte *)this) + procindex); }; + Public proceduralRuleOffset As Integer + ' mutable int physicsbone; // index into physically simulated bone + Public physicsBoneIndex As Integer + ' int surfacepropidx; // index into string tablefor property name + ' inline char * const pszSurfaceProp( void ) const { return ((char *)this) + surfacepropidx; } + Public surfacePropNameOffset As Integer + ' int contents; // See BSPFlags.h for the contents flags + Public contents As Integer + + Public unk As Integer + Public unk1 As Integer + + ' int unused[8]; // remove as appropriate + Public unused(6) As Integer + + '54 words = 54 * 4 bytes = 216 (0xD8) bytes + + Public theName As String + Public theAxisInterpBone As SourceMdlAxisInterpBone + Public theQuatInterpBone As SourceMdlQuatInterpBone + Public theAimAtBone As SourceMdlAimAtBone + Public theJiggleBone As SourceMdlJiggleBone + Public theSurfacePropName As String + + + + ' flag values: + 'FROM: SourceEngine2006_source\public\studio.h + '#define BONE_SCREEN_ALIGN_SPHERE 0x08 // bone aligns to the screen, not constrained in motion. + '#define BONE_SCREEN_ALIGN_CYLINDER 0x10 // bone aligns to the screen, constrained by it's own axis. + ' + '#define BONE_USED_MASK 0x0007FF00 + '#define BONE_USED_BY_ANYTHING 0x0007FF00 + '#define BONE_USED_BY_HITBOX 0x00000100 // bone (or child) is used by a hit box + '#define BONE_USED_BY_ATTACHMENT 0x00000200 // bone (or child) is used by an attachment point + '#define BONE_USED_BY_VERTEX_MASK 0x0003FC00 + '#define BONE_USED_BY_VERTEX_LOD0 0x00000400 // bone (or child) is used by the toplevel model via skinned vertex + '#define BONE_USED_BY_VERTEX_LOD1 0x00000800 + '#define BONE_USED_BY_VERTEX_LOD2 0x00001000 + '#define BONE_USED_BY_VERTEX_LOD3 0x00002000 + '#define BONE_USED_BY_VERTEX_LOD4 0x00004000 + '#define BONE_USED_BY_VERTEX_LOD5 0x00008000 + '#define BONE_USED_BY_VERTEX_LOD6 0x00010000 + '#define BONE_USED_BY_VERTEX_LOD7 0x00020000 + '#define BONE_USED_BY_BONE_MERGE 0x00040000 // bone is available for bone merge to occur against it + ' + '#define BONE_USED_BY_VERTEX_AT_LOD(lod) ( BONE_USED_BY_VERTEX_LOD0 << (lod) ) + '#define BONE_USED_BY_ANYTHING_AT_LOD(lod) ( ( BONE_USED_BY_ANYTHING & ~BONE_USED_BY_VERTEX_MASK ) | BONE_USED_BY_VERTEX_AT_LOD(lod) ) + ' + '#define BONE_TYPE_MASK 0x00F00000 + '#define BONE_FIXED_ALIGNMENT 0x00100000 // bone can't spin 360 degrees, all interpolation is normalized around a fixed orientation + ' + '#define BONE_HAS_SAVEFRAME_POS 0x00200000 + '#define BONE_HAS_SAVEFRAME_ROT 0x00400000 + Public Const BONE_SCREEN_ALIGN_SPHERE As Integer = &H8 + Public Const BONE_SCREEN_ALIGN_CYLINDER As Integer = &H10 + Public Const BONE_USED_BY_VERTEX_LOD0 As Integer = &H400 + Public Const BONE_USED_BY_VERTEX_LOD1 As Integer = &H800 + Public Const BONE_USED_BY_VERTEX_LOD2 As Integer = &H1000 + Public Const BONE_USED_BY_VERTEX_LOD3 As Integer = &H2000 + Public Const BONE_USED_BY_VERTEX_LOD4 As Integer = &H4000 + Public Const BONE_USED_BY_VERTEX_LOD5 As Integer = &H8000 + Public Const BONE_USED_BY_VERTEX_LOD6 As Integer = &H10000 + Public Const BONE_USED_BY_VERTEX_LOD7 As Integer = &H20000 + Public Const BONE_USED_BY_BONE_MERGE As Integer = &H40000 + Public Const BONE_FIXED_ALIGNMENT As Integer = &H100000 + Public Const BONE_HAS_SAVEFRAME_POS As Integer = &H200000 + Public Const BONE_HAS_SAVEFRAME_ROT As Integer = &H400000 + ' MDL v49: + 'Public Const BONE_HAS_SAVEFRAME_ROT64 As Integer = &H400000 + Public Const BONE_HAS_SAVEFRAME_ROT32 As Integer = &H800000 + + + + ' proceduralRuleType values: + '#define STUDIO_PROC_AXISINTERP 1 + '#define STUDIO_PROC_QUATINTERP 2 + '#define STUDIO_PROC_AIMATBONE 3 + '#define STUDIO_PROC_AIMATATTACH 4 + '#define STUDIO_PROC_JIGGLE 5 + Public Const STUDIO_PROC_AXISINTERP As Integer = 1 + Public Const STUDIO_PROC_QUATINTERP As Integer = 2 + Public Const STUDIO_PROC_AIMATBONE As Integer = 3 + Public Const STUDIO_PROC_AIMATATTACH As Integer = 4 + Public Const STUDIO_PROC_JIGGLE As Integer = 5 + + + + ' contents values: + 'FROM: SourceEngine2006_source\public\bspflags.h + + '// contents flags are seperate bits + '// a given brush can contribute multiple content bits + '// multiple brushes can be in a single leaf + + '// lower bits are stronger, and will eat weaker brushes completely + '#define CONTENTS_EMPTY 0 // No contents + + '#define CONTENTS_SOLID 0x1 // an eye is never valid in a solid + '#define CONTENTS_WINDOW 0x2 // translucent, but not watery (glass) + '#define CONTENTS_AUX 0x4 + '#define CONTENTS_GRATE 0x8 // alpha-tested "grate" textures. Bullets/sight pass through, but solids don't + '#define CONTENTS_SLIME 0x10 + '#define CONTENTS_WATER 0x20 + '#define CONTENTS_MIST 0x40 + '#define CONTENTS_OPAQUE 0x80 // things that cannot be seen through (may be non-solid though) + '#define LAST_VISIBLE_CONTENTS 0x80 + + '#define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1)) + + '#define CONTENTS_TESTFOGVOLUME 0x100 + + '// unused + '// NOTE: If it's visible, grab from the top + update LAST_VISIBLE_CONTENTS + '// if not visible, then grab from the bottom. + '#define CONTENTS_UNUSED5 0x200 + '#define CONTENTS_UNUSED6 0x4000 + + '#define CONTENTS_TEAM1 0x800 // per team contents used to differentiate collisions + '#define CONTENTS_TEAM2 0x1000 // between players and objects on different teams + + '// ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW + '#define CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000 + + '// hits entities which are MOVETYPE_PUSH (doors, plats, etc.) + '#define CONTENTS_MOVEABLE 0x4000 + + '// remaining contents are non-visible, and don't eat brushes + '#define CONTENTS_AREAPORTAL 0x8000 + + '#define CONTENTS_PLAYERCLIP 0x10000 + '#define CONTENTS_MONSTERCLIP 0x20000 + + '// currents can be added to any other contents, and may be mixed + '#define CONTENTS_CURRENT_0 0x40000 + '#define CONTENTS_CURRENT_90 0x80000 + '#define CONTENTS_CURRENT_180 0x100000 + '#define CONTENTS_CURRENT_270 0x200000 + '#define CONTENTS_CURRENT_UP 0x400000 + '#define CONTENTS_CURRENT_DOWN 0x800000 + + '#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity + + '#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game + '#define CONTENTS_DEBRIS 0x4000000 + '#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs + '#define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans + '#define CONTENTS_LADDER 0x20000000 + '#define CONTENTS_HITBOX 0x40000000 // use accurate hitboxes on trace + + Public Const CONTENTS_SOLID As Integer = &H1 + Public Const CONTENTS_GRATE As Integer = &H8 + Public Const CONTENTS_MONSTER As Integer = &H2000000 + Public Const CONTENTS_LADDER As Integer = &H20000000 + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index 9626ccd..6f5d6f7 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -452,10 +452,10 @@ '0120 int ikchainindex; Public ikChainOffset As Integer - '0124 int nummouths; - Public mouthCount As Integer - '0128 int mouthindex; - Public mouthOffset As Integer + '0124 int numrui; + Public ruiCount As Integer + '0128 int ruiindex; + Public ruiOffset As Integer '012C int numlocalposeparameters; Public localPoseParamaterCount As Integer @@ -489,23 +489,18 @@ Public virtualModelP As Integer ' int szanimblocknameindex; - Public animBlockNameOffset As Integer + 'Public animBlockNameOffset As Integer ' int numanimblocks; - Public animBlockCount As Integer + 'Public animBlockCount As Integer ' int animblockindex; - Public animBlockOffset As Integer + 'Public animBlockOffset As Integer ' mutable void *animblockModel; - Public animBlockModelP As Integer + 'Public animBlockModelP As Integer 'NOTE: Probably not used or used for something else. ' int bonetablebynameindex; Public boneTableByNameOffset As Integer - ' void *pVertexBase; - Public vertexBaseP As Integer - ' void *pIndexBase; - Public indexBaseP As Integer - ' byte constdirectionallightdot; Public directionalLightDot As Byte @@ -518,55 +513,51 @@ ' byte unused[1]; Public unused As Byte ' int unused4; // zero out if version < 47 - Public unused4 As Integer + Public unkfloat As Single ' int numflexcontrollerui; Public flexControllerUiCount As Integer ' int flexcontrolleruiindex; Public flexControllerUiOffset As Integer - ' float flVertAnimFixedPointScale; - ' inline float VertAnimFixedPointScale() const { return ( flags & STUDIOHDR_FLAGS_VERT_ANIM_FIXED_POINT_SCALE ) ? flVertAnimFixedPointScale : 1.0f / 4096.0f; } - Public vertAnimFixedPointScale As Double - ' mutable int surfacepropLookup; // this index must be cached by the loader, not saved in the file - Public surfacePropLookup As Integer + ' void *pVertexBase; + Public vertexBaseP As Integer + ' void *pIndexBase; + Public indexBaseP As Integer ' // FIXME: Remove when we up the model version. Move all fields of studiohdr2_t into studiohdr_t. ' int studiohdr2index; - Public studioHeader2Offset As Integer - ' int unused2[1]; - Public unknownOffset01 As Integer + Public mayaOffset As Integer - ' sutdiohdr2: Public sourceBoneTransformCount As Integer Public sourceBoneTransformOffset As Integer Public illumPositionAttachmentIndex As Integer - Public maxEyeDeflection As Double + 'Public maxEyeDeflection As Double Public linearBoneOffset As Integer - Public nameOffset As Integer + 'Public nameOffset As Integer Public boneFlexDriverCount As Integer Public boneFlexDriverOffset As Integer - 'Public reserved(55) As Integer - '====== - 'Public studiohdr2(63) As Integer - '====== + Public unknownOffset01 As Integer Public unknown01 As Integer Public unknown02 As Integer Public unknown03 As Integer - Public unknown04 As Integer + Public unknownOffset02 As Integer Public vtxOffset As Integer Public vvdOffset As Integer - Public unknown05 As Integer + Public vvcOffset As Integer Public phyOffset As Integer - Public unknown06 As Integer - Public unknown07 As Integer - Public unknown08 As Integer - Public unknown09 As Integer - Public unknownOffset02 As Integer - Public unknown(58) As Integer + Public vtxSize As Integer + Public vvdSize As Integer + Public vvcSize As Integer + Public phySize As Integer + Public unknownOffset03 As Integer + Public unknown04 As Integer + Public unknown05 As Integer + Public unknownOffset06 As Integer + Public unknown(60) As Integer @@ -579,7 +570,7 @@ Public theAnimBlockRelativePathFileName As String Public theAttachments As List(Of SourceMdlAttachment) Public theBodyParts As List(Of SourceMdlBodyPart) - Public theBones As List(Of SourceMdlBone) + Public theBones As List(Of SourceMdlBone53) Public theBoneControllers As List(Of SourceMdlBoneController) Public theBoneTableByName As List(Of Integer) Public theFlexDescs As List(Of SourceMdlFlexDesc) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index 65b0add..a1dad34 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -360,7 +360,7 @@ Public Class SourceModel53 mdlFile.ReadHitboxSets() - 'mdlFile.ReadBoneTableByName() + mdlFile.ReadBoneTableByName() If Me.theMdlFileData.localAnimationCount > 0 Then Try @@ -385,7 +385,7 @@ Public Class SourceModel53 'mdlFile.ReadIkChains() 'mdlFile.ReadIkLocks() 'mdlFile.ReadMouths() - 'mdlFile.ReadPoseParamDescs() + mdlFile.ReadPoseParamDescs() mdlFile.ReadModelGroups() ''TODO: Me.ReadAnimBlocks() ''TODO: Me.ReadAnimBlockName() @@ -397,8 +397,8 @@ Public Class SourceModel53 mdlFile.ReadKeyValues() - 'mdlFile.ReadBoneTransforms() - 'mdlFile.ReadLinearBoneTable() + mdlFile.ReadBoneTransforms() + mdlFile.ReadLinearBoneTable() ''TODO: ReadLocalIkAutoPlayLocks() 'mdlFile.ReadFlexControllerUis() @@ -417,6 +417,11 @@ Public Class SourceModel53 Me.ReadVvdFile_Internal() End If + If Me.theMdlFileData.vvdOffset > 0 Then + mdlFile.SetReaderToVvdOffset() + Me.ReadVvdFile_Internal() + End If + mdlFile.ReadUnreadBytes() ' Post-processing. @@ -429,7 +434,7 @@ Public Class SourceModel53 Me.thePhyFileDataGeneric = New SourcePhyFileData() End If - Dim phyFile As New SourcePhyFile(Me.theInputFileReader, Me.thePhyFileDataGeneric, Me.theMdlFileData.vtxOffset) + Dim phyFile As New SourcePhyFile(Me.theInputFileReader, Me.thePhyFileDataGeneric, Me.theMdlFileData.phyOffset + Me.theMdlFileData.phySize) phyFile.ReadSourcePhyHeader() If Me.thePhyFileDataGeneric.solidCount > 0 Then @@ -441,7 +446,7 @@ Public Class SourceModel53 phyFile.ReadSourcePhyEditParamsSection() phyFile.ReadCollisionTextSection() End If - phyFile.ReadUnreadBytes() + 'phyFile.ReadUnreadBytes() End Sub Protected Overrides Sub ReadVtxFile_Internal() @@ -501,7 +506,7 @@ Public Class SourceModel53 qcFile.WriteIllumPositionCommand() qcFile.WriteEyePositionCommand() - qcFile.WriteMaxEyeDeflectionCommand() + 'qcFile.WriteMaxEyeDeflectionCommand() qcFile.WriteNoForcedFadeCommand() qcFile.WriteForcePhonemeCrossfadeCommand() @@ -769,11 +774,11 @@ Public Class SourceModel53 mdlFile.WriteInternalMdlFileName(internalMdlFileName) End Sub - Protected Overrides Sub WriteAniFileNameToMdlFile(ByVal internalAniFileName As String) - Dim mdlFile As New SourceMdlFile53(Me.theOutputFileBinaryWriter, Me.theMdlFileData) + 'Protected Overrides Sub WriteAniFileNameToMdlFile(ByVal internalAniFileName As String) + ' Dim mdlFile As New SourceMdlFile53(Me.theOutputFileBinaryWriter, Me.theMdlFileData) - mdlFile.WriteInternalAniFileName(internalAniFileName) - End Sub + 'mdlFile.WriteInternalAniFileName(internalAniFileName) + 'End Sub #End Region diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index e83940d..638f0bf 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -314,7 +314,7 @@ Public Class SourceQcFile53 'VectorITransform( tmp, pmodel->source->boneToPose[eyeball->bone], eyeball->org ); '------ ' WORKS! - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 aBone = Me.theMdlFileData.theBones(anEyeball.boneIndex) 'AngleMatrix(aBone.rotationX, aBone.rotationY, aBone.rotationZ, poseToBone0, poseToBone1, poseToBone2) 'poseToBone3.x = -aBone.positionX @@ -1231,15 +1231,15 @@ Public Class SourceQcFile53 Dim debug As Integer = 4242 End Try - For Each aBone As SourceMdlBone In Me.theMdlFileData.theBones + For Each aBone As SourceMdlBone53 In Me.theMdlFileData.theBones If aBone.parentBoneIndex >= 0 _ - AndAlso ((lodIndex = 1 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD1) = 0) _ - OrElse (lodIndex = 2 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD2) = 0) _ - OrElse (lodIndex = 3 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD3) = 0) _ - OrElse (lodIndex = 4 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD4) = 0) _ - OrElse (lodIndex = 5 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD5) = 0) _ - OrElse (lodIndex = 6 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD6) = 0) _ - OrElse (lodIndex = 7 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD7) = 0)) Then + AndAlso ((lodIndex = 1 AndAlso (aBone.flags And SourceMdlBone53.BONE_USED_BY_VERTEX_LOD1) = 0) _ + OrElse (lodIndex = 2 AndAlso (aBone.flags And SourceMdlBone53.BONE_USED_BY_VERTEX_LOD2) = 0) _ + OrElse (lodIndex = 3 AndAlso (aBone.flags And SourceMdlBone53.BONE_USED_BY_VERTEX_LOD3) = 0) _ + OrElse (lodIndex = 4 AndAlso (aBone.flags And SourceMdlBone53.BONE_USED_BY_VERTEX_LOD4) = 0) _ + OrElse (lodIndex = 5 AndAlso (aBone.flags And SourceMdlBone53.BONE_USED_BY_VERTEX_LOD5) = 0) _ + OrElse (lodIndex = 6 AndAlso (aBone.flags And SourceMdlBone53.BONE_USED_BY_VERTEX_LOD6) = 0) _ + OrElse (lodIndex = 7 AndAlso (aBone.flags And SourceMdlBone53.BONE_USED_BY_VERTEX_LOD7) = 0)) Then 'replacebone "ValveBiped.Bip01_Neck1" "ValveBiped.Bip01_Head1" line = vbTab line += "replacebone " @@ -1674,7 +1674,7 @@ Public Class SourceQcFile53 '$jointsurfaceprop '$jointsurfaceprop "ValveBiped.Bip01_L_Toe0" "flesh" If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False @@ -1729,7 +1729,7 @@ Public Class SourceQcFile53 '$jointcontents "" "" "" "" If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False @@ -1795,25 +1795,25 @@ Public Class SourceQcFile53 Private Function GetContentsFlags(ByVal contentsFlags As Integer) As String Dim flagNames As String = "" - If (contentsFlags And SourceMdlBone.CONTENTS_GRATE) > 0 Then + If (contentsFlags And SourceMdlBone53.CONTENTS_GRATE) > 0 Then flagNames += " " flagNames += """" flagNames += "grate" flagNames += """" End If - If (contentsFlags And SourceMdlBone.CONTENTS_MONSTER) > 0 Then + If (contentsFlags And SourceMdlBone53.CONTENTS_MONSTER) > 0 Then flagNames += " " flagNames += """" flagNames += "monster" flagNames += """" End If - If (contentsFlags And SourceMdlBone.CONTENTS_LADDER) > 0 Then + If (contentsFlags And SourceMdlBone53.CONTENTS_LADDER) > 0 Then flagNames += " " flagNames += """" flagNames += "ladder" flagNames += """" End If - If (contentsFlags And SourceMdlBone.CONTENTS_SOLID) > 0 Then + If (contentsFlags And SourceMdlBone53.CONTENTS_SOLID) > 0 Then flagNames += " " flagNames += """" flagNames += "solid" @@ -1866,27 +1866,27 @@ Public Class SourceQcFile53 Me.theOutputFileStreamWriter.WriteLine(line) End Sub - Public Sub WriteMaxEyeDeflectionCommand() - If Me.theMdlFileData.maxEyeDeflection < -0.0000001 OrElse Me.theMdlFileData.maxEyeDeflection > 0.0000001 Then - Dim line As String = "" - Dim deflection As Double - - deflection = Math.Acos(Me.theMdlFileData.maxEyeDeflection) - deflection = MathModule.RadiansToDegrees(deflection) - deflection = Math.Round(deflection, 3) - - line = "" - Me.theOutputFileStreamWriter.WriteLine(line) - - If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then - line = "$MaxEyeDeflection " - Else - line = "$maxeyedeflection " - End If - line += deflection.ToString("0.######", TheApp.InternalNumberFormat) - Me.theOutputFileStreamWriter.WriteLine(line) - End If - End Sub + 'Public Sub WriteMaxEyeDeflectionCommand() + ' If Me.theMdlFileData.maxEyeDeflection < -0.0000001 OrElse Me.theMdlFileData.maxEyeDeflection > 0.0000001 Then + ' Dim line As String = "" + ' Dim deflection As Double + + ' deflection = Math.Acos(Me.theMdlFileData.maxEyeDeflection) + ' deflection = MathModule.RadiansToDegrees(deflection) + ' deflection = Math.Round(deflection, 3) + + ' line = "" + ' Me.theOutputFileStreamWriter.WriteLine(line) + + ' If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + ' line = "$MaxEyeDeflection " + ' Else + ' line = "$maxeyedeflection " + ' End If + ' line += deflection.ToString("0.######", TheApp.InternalNumberFormat) + ' Me.theOutputFileStreamWriter.WriteLine(line) + ' End If + 'End Sub Public Sub WriteIllumPositionCommand() Dim line As String @@ -1916,7 +1916,7 @@ Public Class SourceQcFile53 End Sub Public Sub WriteGroupAnimation() - Me.WriteAnimBlockSizeCommand() + 'Me.WriteAnimBlockSizeCommand() Me.WriteBoneSaveFrameCommand() Me.WriteSectionFramesCommand() Me.WritePoseParameterCommand() @@ -1939,30 +1939,30 @@ Public Class SourceQcFile53 Me.WriteIncludeModelCommand() End Sub - Private Sub WriteAnimBlockSizeCommand() - Dim line As String = "" + 'Private Sub WriteAnimBlockSizeCommand() + ' Dim line As String = "" '$animblocksize 32 nostall highres - If Me.theMdlFileData.animBlockCount > 0 Then - Me.theOutputFileStreamWriter.WriteLine() + 'If Me.theMdlFileData.animBlockCount > 0 Then + ' Me.theOutputFileStreamWriter.WriteLine() - line = "// The 32 below is a guess until further is known about the format." - Me.theOutputFileStreamWriter.WriteLine(line) + ' line = "// The 32 below is a guess until further is known about the format." + ' Me.theOutputFileStreamWriter.WriteLine(line) - If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then - line = "$AnimBlockSize" - Else - line = "$animblocksize" - End If - line += " " - line += "32" + ' If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + ' line = "$AnimBlockSize" + ' Else + ' line = "$animblocksize" + ' End If + ' line += " " + ' line += "32" 'line += " " 'line += "nostall" 'line += " " 'line += "highres" - Me.theOutputFileStreamWriter.WriteLine(line) - End If - End Sub + ' Me.theOutputFileStreamWriter.WriteLine(line) + 'End If + 'End Sub Private Sub WriteSectionFramesCommand() Dim line As String = "" @@ -2888,14 +2888,14 @@ Public Class SourceQcFile53 '$BoneSaveFrame "Dog_Model.Leg1_L" rotation Try If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(i) - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_POS) > 0 OrElse (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_HAS_SAVEFRAME_POS) > 0 OrElse (aBone.flags And SourceMdlBone53.BONE_HAS_SAVEFRAME_ROT) > 0 Then If Not emptyLineIsAlreadyWritten Then line = "" Me.theOutputFileStreamWriter.WriteLine(line) @@ -2910,11 +2910,11 @@ Public Class SourceQcFile53 line += """" line += aBone.theName line += """" - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_POS) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_HAS_SAVEFRAME_POS) > 0 Then line += " " line += "position" End If - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_HAS_SAVEFRAME_ROT) > 0 Then line += " " line += "rotation" End If @@ -3327,7 +3327,7 @@ Public Class SourceQcFile53 '$definebone "ValveBiped.root" "" 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim aParentBoneName As String Dim aFixupPosition As New SourceVector() Dim aFixupRotation As New SourceVector() @@ -3455,14 +3455,14 @@ Public Class SourceQcFile53 '$bonemerge "ValveBiped.Bip01_R_Hand" If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(i) - If (aBone.flags And SourceMdlBone.BONE_USED_BY_BONE_MERGE) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_USED_BY_BONE_MERGE) > 0 Then If Not emptyLineIsAlreadyWritten Then Me.theOutputFileStreamWriter.WriteLine() emptyLineIsAlreadyWritten = True @@ -3493,9 +3493,9 @@ Public Class SourceQcFile53 Me.theOutputFileStreamWriter.WriteLine(line) For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 aBone = Me.theMdlFileData.theBones(i) - If aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_JIGGLE AndAlso aBone.proceduralRuleOffset <> 0 Then + If aBone.proceduralRuleType = SourceMdlBone53.STUDIO_PROC_JIGGLE AndAlso aBone.proceduralRuleOffset <> 0 Then If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then line = "$JiggleBone " Else @@ -3677,7 +3677,7 @@ Public Class SourceQcFile53 Next End Sub - Private Sub WriteJiggleBoneConstraints(ByVal aBone As SourceMdlBone) + Private Sub WriteJiggleBoneConstraints(ByVal aBone As SourceMdlBone53) Dim line As String = "" If (aBone.theJiggleBone.flags And SourceMdlJiggleBone.JIGGLE_HAS_PITCH_CONSTRAINT) > 0 Then @@ -4095,14 +4095,14 @@ Public Class SourceQcFile53 '$screenalign <"sphere" or "cylinder"> Try If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(i) - If (aBone.flags And SourceMdlBone.BONE_SCREEN_ALIGN_SPHERE) > 0 Then + If (aBone.flags And SourceMdlBone53.BONE_SCREEN_ALIGN_SPHERE) > 0 Then If Not emptyLineIsAlreadyWritten Then Me.theOutputFileStreamWriter.WriteLine() emptyLineIsAlreadyWritten = True @@ -4116,7 +4116,7 @@ Public Class SourceQcFile53 line += aBone.theName line += " ""sphere""" Me.theOutputFileStreamWriter.WriteLine(line) - ElseIf (aBone.flags And SourceMdlBone.BONE_SCREEN_ALIGN_CYLINDER) > 0 Then + ElseIf (aBone.flags And SourceMdlBone53.BONE_SCREEN_ALIGN_CYLINDER) > 0 Then If Not emptyLineIsAlreadyWritten Then Me.theOutputFileStreamWriter.WriteLine() emptyLineIsAlreadyWritten = True diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 94d5c63..4c4e7c7 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -200,7 +200,7 @@ Public Class SourceSmdFile53 Me.theOutputFileStreamWriter.WriteLine(line) Dim collisionData As SourcePhyCollisionData - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim aTriangle As SourcePhyFace Dim faceSection As SourcePhyConvexMesh Dim phyVertex As SourcePhyVertex @@ -327,7 +327,7 @@ Public Class SourceSmdFile53 Public Sub WriteSkeletonSectionForAnimation(ByVal aSequenceDescBase As SourceMdlSequenceDescBase, ByVal anAnimationDescBase As SourceMdlAnimationDescBase) Dim line As String = "" - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim boneIndex As Integer Dim aFrameLine As AnimationFrameLine Dim position As New SourceVector() @@ -509,7 +509,7 @@ Public Class SourceSmdFile53 #Region "Private Methods" Private Sub AdjustPositionAndRotation(ByVal boneIndex As Integer, ByVal iPosition As SourceVector, ByVal iRotation As SourceVector, ByRef oPosition As SourceVector, ByRef oRotation As SourceVector) - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 aBone = Me.theMdlFileData.theBones(boneIndex) 'If iPosition.debug_text = "desc_delta" OrElse iPosition.debug_text.StartsWith("delta") Then @@ -573,7 +573,7 @@ Public Class SourceSmdFile53 End Sub Private Sub AdjustPositionAndRotationByPiecewiseMovement(ByVal frameIndex As Integer, ByVal boneIndex As Integer, ByVal movements As List(Of SourceMdlMovement), ByVal iPosition As SourceVector, ByVal iRotation As SourceVector, ByRef oPosition As SourceVector, ByRef oRotation As SourceVector) - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 aBone = Me.theMdlFileData.theBones(boneIndex) oPosition.x = iPosition.x @@ -700,7 +700,7 @@ Public Class SourceSmdFile53 Return line End Function - Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone, ByVal vertex As SourceVector) As SourceVector + Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone53, ByVal vertex As SourceVector) As SourceVector Dim aVectorTransformed As New SourceVector Dim aVector As New SourceVector() @@ -733,7 +733,7 @@ Public Class SourceSmdFile53 Private Sub CalcAnimation(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal frameIndex As Integer) Dim s As Double Dim animIndex As Integer - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone53 Dim aWeight As Double Dim anAnimation As SourceMdlAnimation Dim rot As SourceVector @@ -1154,7 +1154,7 @@ Public Class SourceSmdFile53 ' Return rot 'End Function - Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone, ByVal anAnimation As SourceMdlAnimation, ByRef rotationQuat As SourceQuaternion) As SourceVector + Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation, ByRef rotationQuat As SourceQuaternion) As SourceVector Dim rot As New SourceQuaternion() Dim angleVector As New SourceVector() @@ -1320,7 +1320,7 @@ Public Class SourceSmdFile53 ' Assert( pos.IsValid() ); '} - Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone, ByVal anAnimation As SourceMdlAnimation) As SourceVector + Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation) As SourceVector Dim pos As New SourceVector() If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS) > 0 Then diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceVrdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceVrdFile53.vb index 9f30ca2..3087df9 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceVrdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceVrdFile53.vb @@ -20,10 +20,10 @@ Public Class SourceVrdFile53 Public Sub WriteCommands() If Me.theMdlFileData.theBones IsNot Nothing Then Dim line As String = "" - Dim aBone As SourceMdlBone - Dim aParentBone As SourceMdlBone - Dim aControlBone As SourceMdlBone - Dim aParentControlBone As SourceMdlBone + Dim aBone As SourceMdlBone53 + Dim aParentBone As SourceMdlBone53 + Dim aControlBone As SourceMdlBone53 + Dim aParentControlBone As SourceMdlBone53 Dim aTrigger As SourceMdlQuatInterpBoneInfo Dim aTriggerTrigger As SourceVector Dim aTriggerQuat As SourceVector @@ -36,8 +36,8 @@ Public Class SourceVrdFile53 aBone = Me.theMdlFileData.theBones(i) If aBone.proceduralRuleOffset <> 0 Then - If aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_AXISINTERP Then - ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_QUATINTERP Then + If aBone.proceduralRuleType = SourceMdlBone53.STUDIO_PROC_AXISINTERP Then + ElseIf aBone.proceduralRuleType = SourceMdlBone53.STUDIO_PROC_QUATINTERP Then ' Bip01_L_Elbow Bip01_L_UpperArm Bip01_L_UpperArm Bip01_L_Forearm ' 1.5 3 3 100 ' 0 0 0 diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index fe1b364..60ab7fe 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -13,7 +13,7 @@ WindowsFormsWithCustomSubMain On Resources\crowbar_icon.ico - v4.0 + v4.8 @@ -127,6 +127,7 @@ + diff --git a/CrowbarLauncher/CrowbarLauncher.vbproj b/CrowbarLauncher/CrowbarLauncher.vbproj index dcbdbc4..0cd21b7 100644 --- a/CrowbarLauncher/CrowbarLauncher.vbproj +++ b/CrowbarLauncher/CrowbarLauncher.vbproj @@ -11,7 +11,7 @@ CrowbarLauncher 512 WindowsFormsWithCustomSubMain - v4.0 + v4.8 true diff --git a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj index fadfb6b..c4ef19b 100644 --- a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj +++ b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj @@ -11,7 +11,7 @@ CrowbarSteamPipe 512 Console - v4.0 + v4.8 true From f41746307abea3d30fc8770286fb0c72ed31cb86 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 11 Aug 2022 01:16:47 -0400 Subject: [PATCH 02/39] quick v52 bone update --- .../SourceModel52/SourceMdlFile52.vb | 77 +++--- .../SourceMdlFileData/SourceMdlBone52.vb | 234 ++++++++++++++++++ .../SourceMdlFileData/SourceMdlFileData52.vb | 2 +- .../GameModel/SourceModel52/SourceQcFile52.vb | 56 ++--- .../SourceModel52/SourceSmdFile52.vb | 18 +- .../SourceModel52/SourceVrdFile52.vb | 12 +- .../SourceMdlFileData/SourceMdlFileData53.vb | 4 +- .../GameModel/SourceModel53/SourceModel53.vb | 10 +- Crowbar/Crowbar.vbproj | 1 + 9 files changed, 316 insertions(+), 98 deletions(-) create mode 100644 Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 25f6682..154f941 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -340,10 +340,10 @@ Public Class SourceMdlFile52 Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.boneOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position - Me.theMdlFileData.theBones = New List(Of SourceMdlBone)(Me.theMdlFileData.boneCount) + Me.theMdlFileData.theBones = New List(Of SourceMdlBone52)(Me.theMdlFileData.boneCount) For i As Integer = 0 To Me.theMdlFileData.boneCount - 1 boneInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim aBone As New SourceMdlBone() + Dim aBone As New SourceMdlBone52() 'If Me.theMdlFileData.version = 10 Then ' aBone.name = Me.theInputFileReader.ReadChars(32) @@ -386,10 +386,12 @@ Public Class SourceMdlFile52 aBone.rotation.x = Me.theInputFileReader.ReadSingle() aBone.rotation.y = Me.theInputFileReader.ReadSingle() aBone.rotation.z = Me.theInputFileReader.ReadSingle() - aBone.positionScale = New SourceVector() - aBone.positionScale.x = Me.theInputFileReader.ReadSingle() - aBone.positionScale.y = Me.theInputFileReader.ReadSingle() - aBone.positionScale.z = Me.theInputFileReader.ReadSingle() + + aBone.unkVector = New SourceVector() + aBone.unkVector.x = Me.theInputFileReader.ReadSingle() + aBone.unkVector.y = Me.theInputFileReader.ReadSingle() + aBone.unkVector.z = Me.theInputFileReader.ReadSingle() + aBone.rotationScale = New SourceVector() aBone.rotationScale.x = Me.theInputFileReader.ReadSingle() aBone.rotationScale.y = Me.theInputFileReader.ReadSingle() @@ -419,30 +421,6 @@ Public Class SourceMdlFile52 aBone.qAlignment.w = Me.theInputFileReader.ReadSingle() aBone.flags = Me.theInputFileReader.ReadInt32() - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD0) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD1) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD2) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD3) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD4) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD5) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD6) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If - 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD7) <> 0 Then - ' Dim debug As Integer = 4242 - 'End If aBone.proceduralRuleType = Me.theInputFileReader.ReadInt32() aBone.proceduralRuleOffset = Me.theInputFileReader.ReadInt32() @@ -450,12 +428,19 @@ Public Class SourceMdlFile52 aBone.surfacePropNameOffset = Me.theInputFileReader.ReadInt32() aBone.contents = Me.theInputFileReader.ReadInt32() - 'If Me.theMdlFileData.version <> 2531 Then - For k As Integer = 0 To 7 - aBone.unused(k) = Me.theInputFileReader.ReadInt32() - Next - 'End If - 'End If + aBone.unk = Me.theInputFileReader.ReadInt32() + + aBone.positionScale = New SourceVector() + aBone.positionScale.x = Me.theInputFileReader.ReadSingle() + aBone.positionScale.y = Me.theInputFileReader.ReadSingle() + aBone.positionScale.z = Me.theInputFileReader.ReadSingle() + + aBone.unkVector1 = New SourceVector() + aBone.unkVector1.x = Me.theInputFileReader.ReadSingle() + aBone.unkVector1.y = Me.theInputFileReader.ReadSingle() + aBone.unkVector1.z = Me.theInputFileReader.ReadSingle() + + aBone.unused = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.theBones.Add(aBone) @@ -475,12 +460,12 @@ Public Class SourceMdlFile52 aBone.theName = "" End If If aBone.proceduralRuleOffset <> 0 Then - If aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_AXISINTERP Then + If aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_AXISINTERP Then Me.ReadAxisInterpBone(boneInputFileStreamPosition, aBone) - ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_QUATINTERP Then + ElseIf aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_QUATINTERP Then Me.theMdlFileData.theProceduralBonesCommandIsUsed = True Me.ReadQuatInterpBone(boneInputFileStreamPosition, aBone) - ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_JIGGLE Then + ElseIf aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_JIGGLE Then Me.ReadJiggleBone(boneInputFileStreamPosition, aBone) End If End If @@ -512,7 +497,7 @@ Public Class SourceMdlFile52 End Sub 'TODO: VERIFY ReadAxisInterpBone() - Private Sub ReadAxisInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone) + Private Sub ReadAxisInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone52) Dim axisInterpBoneInputFileStreamPosition As Long Dim inputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -551,7 +536,7 @@ Public Class SourceMdlFile52 End Try End Sub - Private Sub ReadQuatInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone) + Private Sub ReadQuatInterpBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone52) Dim quatInterpBoneInputFileStreamPosition As Long Dim inputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -621,7 +606,7 @@ Public Class SourceMdlFile52 End Try End Sub - Private Sub ReadJiggleBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone) + Private Sub ReadJiggleBone(ByVal boneInputFileStreamPosition As Long, ByVal aBone As SourceMdlBone52) Dim fileOffsetStart As Long Dim fileOffsetEnd As Long @@ -1226,18 +1211,18 @@ Public Class SourceMdlFile52 'NOTE: This code is reached by DoI's doi_models_dir_vpk\models\weapons\v_g43.mdl and v_vickers.mdl. fileOffsetStart = animInputFileStreamPosition + anAnimationDesc.spanOffset fileOffsetEnd = animInputFileStreamPosition + anAnimationDesc.spanOffset - 1 - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 For boneIndex As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(boneIndex) - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_POS) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_HAS_SAVEFRAME_POS) > 0 Then 'SourceVector48bits (6 bytes) fileOffsetEnd += anAnimationDesc.spanCount * 6 End If - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_HAS_SAVEFRAME_ROT) > 0 Then 'SourceQuaternion64bits (8 bytes) fileOffsetEnd += anAnimationDesc.spanCount * 8 End If - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT32) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_HAS_SAVEFRAME_ROT32) > 0 Then 'SourceQuaternion32bits (4 bytes) fileOffsetEnd += anAnimationDesc.spanCount * 4 End If diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb new file mode 100644 index 0000000..6ddc1f9 --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb @@ -0,0 +1,234 @@ +Public Class SourceMdlBone52 + + 'FROM: SourceEngineXXXX_source\public\studio.h + '// bones + 'struct mstudiobone_t + '{ + ' DECLARE_BYTESWAP_DATADESC(); + ' int sznameindex; + ' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; } + ' int parent; // parent bone + ' int bonecontroller[6]; // bone controller index, -1 == none + + ' // default values + ' Vector pos; + ' Quaternion quat; + ' RadianEuler rot; + ' // compression scale + ' Vector posscale; + ' Vector rotscale; + + ' matrix3x4_t poseToBone; + ' Quaternion qAlignment; + ' int flags; + ' int proctype; + ' int procindex; // procedural rule + ' mutable int physicsbone; // index into physically simulated bone + ' inline void *pProcedure( ) const { if (procindex == 0) return NULL; else return (void *)(((byte *)this) + procindex); }; + ' int surfacepropidx; // index into string tablefor property name + ' inline char * const pszSurfaceProp( void ) const { return ((char *)this) + surfacepropidx; } + ' int contents; // See BSPFlags.h for the contents flags + + ' int unused[8]; // remove as appropriate + + ' mstudiobone_t(){} + 'private: + ' // No copy constructors allowed + ' mstudiobone_t(const mstudiobone_t& vOther); + '}; + + ' int sznameindex; + Public nameOffset As Integer + + ' int parent; // parent bone + Public parentBoneIndex As Integer + ' int bonecontroller[6]; // bone controller index, -1 == none + Public boneControllerIndex(5) As Integer + + ' Vector pos; + Public position As SourceVector + + ' Quaternion quat; + Public quat As SourceQuaternion + + 'NOTE: Changed to Double, so that the values will be properly written to file with 6 decimal digits. + ' RadianEuler rot; + Public rotation As SourceVector + + Public unkVector As SourceVector + ' Vector rotscale; + Public rotationScale As SourceVector + + ' matrix3x4_t poseToBone; + Public poseToBoneColumn0 As SourceVector + Public poseToBoneColumn1 As SourceVector + Public poseToBoneColumn2 As SourceVector + Public poseToBoneColumn3 As SourceVector + ' Quaternion qAlignment; + Public qAlignment As SourceQuaternion + ' int flags; + Public flags As Integer + ' int proctype; + Public proceduralRuleType As Integer + ' int procindex; // procedural rule + ' inline void *pProcedure( ) const { if (procindex == 0) return NULL; else return (void *)(((byte *)this) + procindex); }; + Public proceduralRuleOffset As Integer + ' mutable int physicsbone; // index into physically simulated bone + Public physicsBoneIndex As Integer + ' int surfacepropidx; // index into string tablefor property name + ' inline char * const pszSurfaceProp( void ) const { return ((char *)this) + surfacepropidx; } + Public surfacePropNameOffset As Integer + ' int contents; // See BSPFlags.h for the contents flags + Public contents As Integer + + Public unk As Integer + + ' Vector posscale; + Public positionScale As SourceVector + + Public unkVector1 As SourceVector + + ' int unused[8]; // remove as appropriate + Public unused As Integer + + '54 words = 54 * 4 bytes = 216 (0xD8) bytes + + Public theName As String + Public theAxisInterpBone As SourceMdlAxisInterpBone + Public theQuatInterpBone As SourceMdlQuatInterpBone + Public theAimAtBone As SourceMdlAimAtBone + Public theJiggleBone As SourceMdlJiggleBone + Public theSurfacePropName As String + + + + ' flag values: + 'FROM: SourceEngine2006_source\public\studio.h + '#define BONE_SCREEN_ALIGN_SPHERE 0x08 // bone aligns to the screen, not constrained in motion. + '#define BONE_SCREEN_ALIGN_CYLINDER 0x10 // bone aligns to the screen, constrained by it's own axis. + ' + '#define BONE_USED_MASK 0x0007FF00 + '#define BONE_USED_BY_ANYTHING 0x0007FF00 + '#define BONE_USED_BY_HITBOX 0x00000100 // bone (or child) is used by a hit box + '#define BONE_USED_BY_ATTACHMENT 0x00000200 // bone (or child) is used by an attachment point + '#define BONE_USED_BY_VERTEX_MASK 0x0003FC00 + '#define BONE_USED_BY_VERTEX_LOD0 0x00000400 // bone (or child) is used by the toplevel model via skinned vertex + '#define BONE_USED_BY_VERTEX_LOD1 0x00000800 + '#define BONE_USED_BY_VERTEX_LOD2 0x00001000 + '#define BONE_USED_BY_VERTEX_LOD3 0x00002000 + '#define BONE_USED_BY_VERTEX_LOD4 0x00004000 + '#define BONE_USED_BY_VERTEX_LOD5 0x00008000 + '#define BONE_USED_BY_VERTEX_LOD6 0x00010000 + '#define BONE_USED_BY_VERTEX_LOD7 0x00020000 + '#define BONE_USED_BY_BONE_MERGE 0x00040000 // bone is available for bone merge to occur against it + ' + '#define BONE_USED_BY_VERTEX_AT_LOD(lod) ( BONE_USED_BY_VERTEX_LOD0 << (lod) ) + '#define BONE_USED_BY_ANYTHING_AT_LOD(lod) ( ( BONE_USED_BY_ANYTHING & ~BONE_USED_BY_VERTEX_MASK ) | BONE_USED_BY_VERTEX_AT_LOD(lod) ) + ' + '#define BONE_TYPE_MASK 0x00F00000 + '#define BONE_FIXED_ALIGNMENT 0x00100000 // bone can't spin 360 degrees, all interpolation is normalized around a fixed orientation + ' + '#define BONE_HAS_SAVEFRAME_POS 0x00200000 + '#define BONE_HAS_SAVEFRAME_ROT 0x00400000 + Public Const BONE_SCREEN_ALIGN_SPHERE As Integer = &H8 + Public Const BONE_SCREEN_ALIGN_CYLINDER As Integer = &H10 + Public Const BONE_USED_BY_VERTEX_LOD0 As Integer = &H400 + Public Const BONE_USED_BY_VERTEX_LOD1 As Integer = &H800 + Public Const BONE_USED_BY_VERTEX_LOD2 As Integer = &H1000 + Public Const BONE_USED_BY_VERTEX_LOD3 As Integer = &H2000 + Public Const BONE_USED_BY_VERTEX_LOD4 As Integer = &H4000 + Public Const BONE_USED_BY_VERTEX_LOD5 As Integer = &H8000 + Public Const BONE_USED_BY_VERTEX_LOD6 As Integer = &H10000 + Public Const BONE_USED_BY_VERTEX_LOD7 As Integer = &H20000 + Public Const BONE_USED_BY_BONE_MERGE As Integer = &H40000 + Public Const BONE_FIXED_ALIGNMENT As Integer = &H100000 + Public Const BONE_HAS_SAVEFRAME_POS As Integer = &H200000 + Public Const BONE_HAS_SAVEFRAME_ROT As Integer = &H400000 + ' MDL v49: + 'Public Const BONE_HAS_SAVEFRAME_ROT64 As Integer = &H400000 + Public Const BONE_HAS_SAVEFRAME_ROT32 As Integer = &H800000 + + + + ' proceduralRuleType values: + '#define STUDIO_PROC_AXISINTERP 1 + '#define STUDIO_PROC_QUATINTERP 2 + '#define STUDIO_PROC_AIMATBONE 3 + '#define STUDIO_PROC_AIMATATTACH 4 + '#define STUDIO_PROC_JIGGLE 5 + Public Const STUDIO_PROC_AXISINTERP As Integer = 1 + Public Const STUDIO_PROC_QUATINTERP As Integer = 2 + Public Const STUDIO_PROC_AIMATBONE As Integer = 3 + Public Const STUDIO_PROC_AIMATATTACH As Integer = 4 + Public Const STUDIO_PROC_JIGGLE As Integer = 5 + + + + ' contents values: + 'FROM: SourceEngine2006_source\public\bspflags.h + + '// contents flags are seperate bits + '// a given brush can contribute multiple content bits + '// multiple brushes can be in a single leaf + + '// lower bits are stronger, and will eat weaker brushes completely + '#define CONTENTS_EMPTY 0 // No contents + + '#define CONTENTS_SOLID 0x1 // an eye is never valid in a solid + '#define CONTENTS_WINDOW 0x2 // translucent, but not watery (glass) + '#define CONTENTS_AUX 0x4 + '#define CONTENTS_GRATE 0x8 // alpha-tested "grate" textures. Bullets/sight pass through, but solids don't + '#define CONTENTS_SLIME 0x10 + '#define CONTENTS_WATER 0x20 + '#define CONTENTS_MIST 0x40 + '#define CONTENTS_OPAQUE 0x80 // things that cannot be seen through (may be non-solid though) + '#define LAST_VISIBLE_CONTENTS 0x80 + + '#define ALL_VISIBLE_CONTENTS (LAST_VISIBLE_CONTENTS | (LAST_VISIBLE_CONTENTS-1)) + + '#define CONTENTS_TESTFOGVOLUME 0x100 + + '// unused + '// NOTE: If it's visible, grab from the top + update LAST_VISIBLE_CONTENTS + '// if not visible, then grab from the bottom. + '#define CONTENTS_UNUSED5 0x200 + '#define CONTENTS_UNUSED6 0x4000 + + '#define CONTENTS_TEAM1 0x800 // per team contents used to differentiate collisions + '#define CONTENTS_TEAM2 0x1000 // between players and objects on different teams + + '// ignore CONTENTS_OPAQUE on surfaces that have SURF_NODRAW + '#define CONTENTS_IGNORE_NODRAW_OPAQUE 0x2000 + + '// hits entities which are MOVETYPE_PUSH (doors, plats, etc.) + '#define CONTENTS_MOVEABLE 0x4000 + + '// remaining contents are non-visible, and don't eat brushes + '#define CONTENTS_AREAPORTAL 0x8000 + + '#define CONTENTS_PLAYERCLIP 0x10000 + '#define CONTENTS_MONSTERCLIP 0x20000 + + '// currents can be added to any other contents, and may be mixed + '#define CONTENTS_CURRENT_0 0x40000 + '#define CONTENTS_CURRENT_90 0x80000 + '#define CONTENTS_CURRENT_180 0x100000 + '#define CONTENTS_CURRENT_270 0x200000 + '#define CONTENTS_CURRENT_UP 0x400000 + '#define CONTENTS_CURRENT_DOWN 0x800000 + + '#define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity + + '#define CONTENTS_MONSTER 0x2000000 // should never be on a brush, only in game + '#define CONTENTS_DEBRIS 0x4000000 + '#define CONTENTS_DETAIL 0x8000000 // brushes to be added after vis leafs + '#define CONTENTS_TRANSLUCENT 0x10000000 // auto set if any surface has trans + '#define CONTENTS_LADDER 0x20000000 + '#define CONTENTS_HITBOX 0x40000000 // use accurate hitboxes on trace + + Public Const CONTENTS_SOLID As Integer = &H1 + Public Const CONTENTS_GRATE As Integer = &H8 + Public Const CONTENTS_MONSTER As Integer = &H2000000 + Public Const CONTENTS_LADDER As Integer = &H20000000 + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb index f00beb9..b4329af 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb @@ -562,7 +562,7 @@ Public theAnimBlockRelativePathFileName As String Public theAttachments As List(Of SourceMdlAttachment) Public theBodyParts As List(Of SourceMdlBodyPart) - Public theBones As List(Of SourceMdlBone) + Public theBones As List(Of SourceMdlBone52) Public theBoneControllers As List(Of SourceMdlBoneController) Public theBoneTableByName As List(Of Integer) Public theFlexDescs As List(Of SourceMdlFlexDesc) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb index 2106360..fdffc19 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb @@ -315,7 +315,7 @@ Public Class SourceQcFile52 'VectorITransform( tmp, pmodel->source->boneToPose[eyeball->bone], eyeball->org ); '------ ' WORKS! - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 aBone = Me.theMdlFileData.theBones(anEyeball.boneIndex) 'AngleMatrix(aBone.rotationX, aBone.rotationY, aBone.rotationZ, poseToBone0, poseToBone1, poseToBone2) 'poseToBone3.x = -aBone.positionX @@ -1288,15 +1288,15 @@ Public Class SourceQcFile52 Dim debug As Integer = 4242 End Try - For Each aBone As SourceMdlBone In Me.theMdlFileData.theBones + For Each aBone As SourceMdlBone52 In Me.theMdlFileData.theBones If aBone.parentBoneIndex >= 0 _ - AndAlso ((lodIndex = 1 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD1) = 0) _ - OrElse (lodIndex = 2 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD2) = 0) _ - OrElse (lodIndex = 3 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD3) = 0) _ - OrElse (lodIndex = 4 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD4) = 0) _ - OrElse (lodIndex = 5 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD5) = 0) _ - OrElse (lodIndex = 6 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD6) = 0) _ - OrElse (lodIndex = 7 AndAlso (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD7) = 0)) Then + AndAlso ((lodIndex = 1 AndAlso (aBone.flags And SourceMdlBone52.BONE_USED_BY_VERTEX_LOD1) = 0) _ + OrElse (lodIndex = 2 AndAlso (aBone.flags And SourceMdlBone52.BONE_USED_BY_VERTEX_LOD2) = 0) _ + OrElse (lodIndex = 3 AndAlso (aBone.flags And SourceMdlBone52.BONE_USED_BY_VERTEX_LOD3) = 0) _ + OrElse (lodIndex = 4 AndAlso (aBone.flags And SourceMdlBone52.BONE_USED_BY_VERTEX_LOD4) = 0) _ + OrElse (lodIndex = 5 AndAlso (aBone.flags And SourceMdlBone52.BONE_USED_BY_VERTEX_LOD5) = 0) _ + OrElse (lodIndex = 6 AndAlso (aBone.flags And SourceMdlBone52.BONE_USED_BY_VERTEX_LOD6) = 0) _ + OrElse (lodIndex = 7 AndAlso (aBone.flags And SourceMdlBone52.BONE_USED_BY_VERTEX_LOD7) = 0)) Then 'replacebone "ValveBiped.Bip01_Neck1" "ValveBiped.Bip01_Head1" line = vbTab line += "replacebone " @@ -1767,7 +1767,7 @@ Public Class SourceQcFile52 '$jointsurfaceprop '$jointsurfaceprop "ValveBiped.Bip01_L_Toe0" "flesh" If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False @@ -1822,7 +1822,7 @@ Public Class SourceQcFile52 '$jointcontents "" "" "" "" If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False @@ -1888,25 +1888,25 @@ Public Class SourceQcFile52 Private Function GetContentsFlags(ByVal contentsFlags As Integer) As String Dim flagNames As String = "" - If (contentsFlags And SourceMdlBone.CONTENTS_GRATE) > 0 Then + If (contentsFlags And SourceMdlBone52.CONTENTS_GRATE) > 0 Then flagNames += " " flagNames += """" flagNames += "grate" flagNames += """" End If - If (contentsFlags And SourceMdlBone.CONTENTS_MONSTER) > 0 Then + If (contentsFlags And SourceMdlBone52.CONTENTS_MONSTER) > 0 Then flagNames += " " flagNames += """" flagNames += "monster" flagNames += """" End If - If (contentsFlags And SourceMdlBone.CONTENTS_LADDER) > 0 Then + If (contentsFlags And SourceMdlBone52.CONTENTS_LADDER) > 0 Then flagNames += " " flagNames += """" flagNames += "ladder" flagNames += """" End If - If (contentsFlags And SourceMdlBone.CONTENTS_SOLID) > 0 Then + If (contentsFlags And SourceMdlBone52.CONTENTS_SOLID) > 0 Then flagNames += " " flagNames += """" flagNames += "solid" @@ -3168,14 +3168,14 @@ Public Class SourceQcFile52 '$BoneSaveFrame "Dog_Model.Leg1_L" rotation Try If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(i) - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_POS) > 0 OrElse (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_HAS_SAVEFRAME_POS) > 0 OrElse (aBone.flags And SourceMdlBone52.BONE_HAS_SAVEFRAME_ROT) > 0 Then If Not emptyLineIsAlreadyWritten Then line = "" Me.theOutputFileStreamWriter.WriteLine(line) @@ -3190,11 +3190,11 @@ Public Class SourceQcFile52 line += """" line += aBone.theName line += """" - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_POS) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_HAS_SAVEFRAME_POS) > 0 Then line += " " line += "position" End If - If (aBone.flags And SourceMdlBone.BONE_HAS_SAVEFRAME_ROT) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_HAS_SAVEFRAME_ROT) > 0 Then line += " " line += "rotation" End If @@ -3609,7 +3609,7 @@ Public Class SourceQcFile52 '$definebone "ValveBiped.root" "" 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim aParentBoneName As String Dim aFixupPosition As New SourceVector() Dim aFixupRotation As New SourceVector() @@ -3733,14 +3733,14 @@ Public Class SourceQcFile52 '$bonemerge "ValveBiped.Bip01_R_Hand" If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(i) - If (aBone.flags And SourceMdlBone.BONE_USED_BY_BONE_MERGE) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_USED_BY_BONE_MERGE) > 0 Then If Not emptyLineIsAlreadyWritten Then Me.theOutputFileStreamWriter.WriteLine() emptyLineIsAlreadyWritten = True @@ -3771,9 +3771,9 @@ Public Class SourceQcFile52 Me.theOutputFileStreamWriter.WriteLine(line) For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 aBone = Me.theMdlFileData.theBones(i) - If aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_JIGGLE AndAlso aBone.proceduralRuleOffset <> 0 Then + If aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_JIGGLE AndAlso aBone.proceduralRuleOffset <> 0 Then If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then line = "$JiggleBone " Else @@ -3957,7 +3957,7 @@ Public Class SourceQcFile52 Next End Sub - Private Sub WriteJiggleBoneConstraints(ByVal aBone As SourceMdlBone) + Private Sub WriteJiggleBoneConstraints(ByVal aBone As SourceMdlBone52) Dim line As String = "" If (aBone.theJiggleBone.flags And SourceMdlJiggleBone.JIGGLE_HAS_PITCH_CONSTRAINT) > 0 Then @@ -4376,14 +4376,14 @@ Public Class SourceQcFile52 '$screenalign <"sphere" or "cylinder"> Try If Me.theMdlFileData.theBones IsNot Nothing Then - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim emptyLineIsAlreadyWritten As Boolean emptyLineIsAlreadyWritten = False For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 aBone = Me.theMdlFileData.theBones(i) - If (aBone.flags And SourceMdlBone.BONE_SCREEN_ALIGN_SPHERE) > 0 Then + If (aBone.flags And SourceMdlBone52.BONE_SCREEN_ALIGN_SPHERE) > 0 Then If Not emptyLineIsAlreadyWritten Then Me.theOutputFileStreamWriter.WriteLine() emptyLineIsAlreadyWritten = True @@ -4397,7 +4397,7 @@ Public Class SourceQcFile52 line += aBone.theName line += " ""sphere""" Me.theOutputFileStreamWriter.WriteLine(line) - ElseIf (aBone.flags And SourceMdlBone.BONE_SCREEN_ALIGN_CYLINDER) > 0 Then + ElseIf (aBone.flags And SourceMdlBone52.BONE_SCREEN_ALIGN_CYLINDER) > 0 Then If Not emptyLineIsAlreadyWritten Then Me.theOutputFileStreamWriter.WriteLine() emptyLineIsAlreadyWritten = True diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb index 893686f..e0588b7 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceSmdFile52.vb @@ -75,7 +75,7 @@ Public Class SourceSmdFile52 Public Sub WriteSkeletonSection(ByVal lodIndex As Integer) Dim line As String = "" - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 'skeleton line = "skeleton" @@ -209,7 +209,7 @@ Public Class SourceSmdFile52 Me.theOutputFileStreamWriter.WriteLine(line) Dim collisionData As SourcePhyCollisionData - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim aTriangle As SourcePhyFace Dim faceSection As SourcePhyConvexMesh Dim phyVertex As SourcePhyVertex @@ -335,7 +335,7 @@ Public Class SourceSmdFile52 Public Sub WriteSkeletonSectionForAnimation(ByVal aSequenceDescBase As SourceMdlSequenceDescBase, ByVal anAnimationDescBase As SourceMdlAnimationDescBase) Dim line As String = "" - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim boneIndex As Integer Dim aFrameLine As AnimationFrameLine Dim position As New SourceVector() @@ -521,7 +521,7 @@ Public Class SourceSmdFile52 #Region "Private Methods" Private Sub AdjustPositionAndRotation(ByVal boneIndex As Integer, ByVal iPosition As SourceVector, ByVal iRotation As SourceVector, ByRef oPosition As SourceVector, ByRef oRotation As SourceVector) - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 aBone = Me.theMdlFileData.theBones(boneIndex) 'If iPosition.debug_text = "desc_delta" OrElse iPosition.debug_text.StartsWith("delta") Then @@ -585,7 +585,7 @@ Public Class SourceSmdFile52 End Sub Private Sub AdjustPositionAndRotationByPiecewiseMovement(ByVal frameIndex As Integer, ByVal boneIndex As Integer, ByVal movements As List(Of SourceMdlMovement), ByVal iPosition As SourceVector, ByVal iRotation As SourceVector, ByRef oPosition As SourceVector, ByRef oRotation As SourceVector) - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 aBone = Me.theMdlFileData.theBones(boneIndex) oPosition.x = iPosition.x @@ -808,7 +808,7 @@ Public Class SourceSmdFile52 'Dim aBone As SourceMdlBone 'aBone = Me.theSourceEngineModel.theMdlFileHeader.theBones(anEyeball.boneIndex) 'eyeballPosition = MathModule.VectorITransform(anEyeball.org, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone, ByVal vertex As SourceVector) As SourceVector + Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone52, ByVal vertex As SourceVector) As SourceVector Dim aVectorTransformed As New SourceVector Dim aVector As New SourceVector() @@ -1461,7 +1461,7 @@ Public Class SourceSmdFile52 Private Sub CalcAnimation(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal frameIndex As Integer) Dim s As Double Dim animIndex As Integer - Dim aBone As SourceMdlBone + Dim aBone As SourceMdlBone52 Dim aWeight As Double Dim anAnimation As SourceMdlAnimation Dim rot As SourceVector @@ -1882,7 +1882,7 @@ Public Class SourceSmdFile52 ' Return rot 'End Function - Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone, ByVal anAnimation As SourceMdlAnimation, ByRef rotationQuat As SourceQuaternion) As SourceVector + Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone52, ByVal anAnimation As SourceMdlAnimation, ByRef rotationQuat As SourceQuaternion) As SourceVector Dim rot As New SourceQuaternion() Dim angleVector As New SourceVector() @@ -2037,7 +2037,7 @@ Public Class SourceSmdFile52 ' Assert( pos.IsValid() ); '} - Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone, ByVal anAnimation As SourceMdlAnimation) As SourceVector + Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone52, ByVal anAnimation As SourceMdlAnimation) As SourceVector Dim pos As New SourceVector() If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS) > 0 Then diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceVrdFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceVrdFile52.vb index de9d3dd..badf611 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceVrdFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceVrdFile52.vb @@ -20,10 +20,10 @@ Public Class SourceVrdFile52 Public Sub WriteCommands() If Me.theMdlFileData.theBones IsNot Nothing Then Dim line As String = "" - Dim aBone As SourceMdlBone - Dim aParentBone As SourceMdlBone - Dim aControlBone As SourceMdlBone - Dim aParentControlBone As SourceMdlBone + Dim aBone As SourceMdlBone52 + Dim aParentBone As SourceMdlBone52 + Dim aControlBone As SourceMdlBone52 + Dim aParentControlBone As SourceMdlBone52 Dim aTrigger As SourceMdlQuatInterpBoneInfo Dim aTriggerTrigger As SourceVector Dim aTriggerQuat As SourceVector @@ -36,8 +36,8 @@ Public Class SourceVrdFile52 aBone = Me.theMdlFileData.theBones(i) If aBone.proceduralRuleOffset <> 0 Then - If aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_AXISINTERP Then - ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_QUATINTERP Then + If aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_AXISINTERP Then + ElseIf aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_QUATINTERP Then ' Bip01_L_Elbow Bip01_L_UpperArm Bip01_L_UpperArm Bip01_L_Forearm ' 1.5 3 3 100 ' 0 0 0 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index 6f5d6f7..ba2b755 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -525,8 +525,8 @@ ' void *pIndexBase; Public indexBaseP As Integer - ' // FIXME: Remove when we up the model version. Move all fields of studiohdr2_t into studiohdr_t. - ' int studiohdr2index; + ' it would be cool to export these strings in a txt but who cares. + ' int Public mayaOffset As Integer Public sourceBoneTransformCount As Integer diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index a1dad34..140fbdd 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -390,6 +390,7 @@ Public Class SourceModel53 ''TODO: Me.ReadAnimBlocks() ''TODO: Me.ReadAnimBlockName() + 'NOTE: V53 MDLs shouldn't really have more than one texture path due to how RPak materials work. mdlFile.ReadTexturePaths() 'NOTE: ReadTextures must be after ReadTexturePaths(), so it can compare with the texture paths. mdlFile.ReadTextures() @@ -417,10 +418,7 @@ Public Class SourceModel53 Me.ReadVvdFile_Internal() End If - If Me.theMdlFileData.vvdOffset > 0 Then - mdlFile.SetReaderToVvdOffset() - Me.ReadVvdFile_Internal() - End If + mdlFile.ReadUnreadBytes() @@ -434,7 +432,7 @@ Public Class SourceModel53 Me.thePhyFileDataGeneric = New SourcePhyFileData() End If - Dim phyFile As New SourcePhyFile(Me.theInputFileReader, Me.thePhyFileDataGeneric, Me.theMdlFileData.phyOffset + Me.theMdlFileData.phySize) + Dim phyFile As New SourcePhyFile(Me.theInputFileReader, Me.thePhyFileDataGeneric, Me.theMdlFileData.phyOffset) phyFile.ReadSourcePhyHeader() If Me.thePhyFileDataGeneric.solidCount > 0 Then @@ -446,7 +444,7 @@ Public Class SourceModel53 phyFile.ReadSourcePhyEditParamsSection() phyFile.ReadCollisionTextSection() End If - 'phyFile.ReadUnreadBytes() + phyFile.ReadUnreadBytes() End Sub Protected Overrides Sub ReadVtxFile_Internal() diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 60ab7fe..df1c48c 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -127,6 +127,7 @@ + From bd2ffa91f77a547185f51a169e51ebeb15f9af2e Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:26:18 -0400 Subject: [PATCH 03/39] working ik chain for v53 limited by crowbar itself only writing one link. --- .../SourceMdlFileData/SourceMdlBone52.vb | 7 ++-- .../SourceModel53/SourceMdlFile53.vb | 35 +++++++++++-------- .../SourceMdlFileData/SourceMdlBone53.vb | 7 ++-- .../SourceMdlFileData/SourceMdlFileData53.vb | 2 +- .../SourceMdlFileData/SourceMdlIkChain53.vb | 33 +++++++++++++++++ .../SourceMdlFileData/SourceMdlIkLink53.vb | 25 +++++++++++++ .../GameModel/SourceModel53/SourceModel53.vb | 6 ++-- .../GameModel/SourceModel53/SourceQcFile53.vb | 6 ++-- Crowbar/Crowbar.vbproj | 2 ++ 9 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb index 6ddc1f9..aa150a2 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb @@ -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 @@ -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 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 23beff4..c9c17b3 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -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() @@ -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() @@ -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 @@ -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 @@ -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 @@ -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() @@ -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 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb index 577c8ed..deb8700 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb @@ -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 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index ba2b755..03d9c9e 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -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) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb new file mode 100644 index 0000000..afd4b5b --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb @@ -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 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb new file mode 100644 index 0000000..8550b24 --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb @@ -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 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index 140fbdd..96f93a7 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -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() @@ -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 @@ -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() diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 638f0bf..09db800 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -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 """ diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index df1c48c..dc44a69 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -129,6 +129,8 @@ + + From 9134f35bf42c6c24790c4c2349ac495fc66afafd Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:52:40 -0400 Subject: [PATCH 04/39] formatting and v52 hdr updating --- .../GameModel/SourceModel52/SourceMdlFile52.vb | 12 ++++++++++-- .../SourceMdlFileData/SourceMdlFileData52.vb | 16 +++++++++++++--- .../SourceMdlFileData/SourceMdlFileData53.vb | 6 +++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 154f941..4826c76 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -263,7 +263,7 @@ Public Class SourceMdlFile52 Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte() - Me.theMdlFileData.unused4 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unkFloat = Me.theInputFileReader.ReadSingle() Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.flexControllerUiOffset = Me.theInputFileReader.ReadInt32() @@ -273,7 +273,7 @@ Public Class SourceMdlFile52 Me.theMdlFileData.studioHeader2Offset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unused2 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.mayaOffset = Me.theInputFileReader.ReadInt32() fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, logDescription) @@ -319,6 +319,14 @@ Public Class SourceMdlFile52 Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.boneFlexDriverOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unknownOffset01 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unknown01 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unknown02 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unknown03 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unknownOffset02 = Me.theInputFileReader.ReadInt32() + + 'NOTE: In V52 the subheader is 208 bytes instead of 256. + 'For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1 ' Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32() 'Next diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb index b4329af..0967ea7 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb @@ -517,7 +517,7 @@ ' byte unused[1]; Public unused As Byte ' int unused4; // zero out if version < 47 - Public unused4 As Integer + Public unkFloat As Single ' int numflexcontrollerui; Public flexControllerUiCount As Integer @@ -534,7 +534,7 @@ ' int studiohdr2index; Public studioHeader2Offset As Integer ' int unused2[1]; - Public unused2 As Integer + Public mayaOffset As Integer ' sutdiohdr2: Public sourceBoneTransformCount As Integer @@ -547,8 +547,18 @@ Public boneFlexDriverCount As Integer Public boneFlexDriverOffset As Integer + ' Both V52 and V53 have this section. + ' Related to some block that appears when linear bone data is not present. + Public unknownOffset01 As Integer + Public unknown01 As Integer + Public unknown02 As Integer + Public unknown03 As Integer + ' Points to byte just before string table. + Public unknownOffset02 As Integer + 'NOTE: Just skip reading these bytes, because it unknown if any are used. - 'Public reserved(55) As Integer + 'NOTE: These are unused in V52 as far as I can tell. + 'Public reserved(56) As Integer '====== 'Public studiohdr2(63) As Integer diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index 03d9c9e..a2437a3 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -539,11 +539,15 @@ Public boneFlexDriverCount As Integer Public boneFlexDriverOffset As Integer + ' Both V52 and V53 have this section. + ' Related to some block that appears when linear bone data is not present. Public unknownOffset01 As Integer Public unknown01 As Integer Public unknown02 As Integer Public unknown03 As Integer + ' Points to byte just before string table. Public unknownOffset02 As Integer + Public vtxOffset As Integer Public vvdOffset As Integer Public vvcOffset As Integer @@ -559,7 +563,7 @@ Public unknownOffset06 As Integer Public unknown(60) As Integer - + 'NOTE: Header is 716 bytes. 'Public theID As String 'Public theName As String From 06e4f33aee6d7bab176692078072021c33900db5 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:49:00 -0400 Subject: [PATCH 05/39] clean up --- .../Core/GameModel/SourceModel53/SourceMdlFile53.vb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index c9c17b3..60e6550 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -864,15 +864,9 @@ Public Class SourceMdlFile53 aHitbox.boundingBoxMax.z = Me.theInputFileReader.ReadSingle() aHitbox.nameOffset = Me.theInputFileReader.ReadInt32() - aHitbox.unused(0) = Me.theInputFileReader.ReadInt32() - ' This is actually an index into a KV if it has one, unsure how it works tbh. - aHitbox.unused(1) = Me.theInputFileReader.ReadInt32() - aHitbox.unused(2) = Me.theInputFileReader.ReadInt32() - aHitbox.unused(3) = Me.theInputFileReader.ReadInt32() - aHitbox.unused(4) = Me.theInputFileReader.ReadInt32() - aHitbox.unused(5) = Me.theInputFileReader.ReadInt32() - aHitbox.unused(6) = Me.theInputFileReader.ReadInt32() - aHitbox.unused(7) = Me.theInputFileReader.ReadInt32() + For k As Integer = 0 To 7 + aHitbox.unused(k) = Me.theInputFileReader.ReadInt32() + Next aHitboxSet.theHitboxes.Add(aHitbox) From 5875ead7e5129b303e47008368bbbee9fc72ef11 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:12:42 -0400 Subject: [PATCH 06/39] partial update of the smd file this fixes the physics smd decompiling with all parts clumped around the origin. --- .../SourceMdlFileData/SourceMdlFileData53.vb | 1 + .../SourceModel53/SourceSmdFile53.vb | 638 +++++++++++++++++- 2 files changed, 608 insertions(+), 31 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index a2437a3..1e80b83 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -605,6 +605,7 @@ Public theEyelidFlexFrameIndexes As List(Of Integer) 'Public theUpperEyelidFlexFrameIndexes As List(Of Integer) + Public theBoneNameToBoneIndexMap As New SortedList(Of String, Integer)() Public theFirstAnimationDesc As SourceMdlAnimationDesc52 Public theFirstAnimationDescFrameLines As SortedList(Of Integer, AnimationFrameLine) 'Public theMdlFileOnlyHasAnimations As Boolean diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 4c4e7c7..99f0c8f 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -201,26 +201,57 @@ Public Class SourceSmdFile53 Dim collisionData As SourcePhyCollisionData Dim aBone As SourceMdlBone53 + Dim boneIndex As Integer Dim aTriangle As SourcePhyFace - Dim faceSection As SourcePhyConvexMesh + Dim convexMesh As SourcePhyConvexMesh Dim phyVertex As SourcePhyVertex Dim aVectorTransformed As SourceVector + Dim aSourcePhysCollisionModel As SourcePhyPhysCollisionModel Try If Me.thePhyFileData.theSourcePhyCollisionDatas IsNot Nothing Then + Me.ProcessTransformsForPhysics() + For collisionDataIndex As Integer = 0 To Me.thePhyFileData.theSourcePhyCollisionDatas.Count - 1 collisionData = Me.thePhyFileData.theSourcePhyCollisionDatas(collisionDataIndex) - For faceSectionIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 - faceSection = collisionData.theConvexMeshes(faceSectionIndex) + If collisionDataIndex < Me.thePhyFileData.theSourcePhyPhysCollisionModels.Count Then + aSourcePhysCollisionModel = Me.thePhyFileData.theSourcePhyPhysCollisionModels(collisionDataIndex) + Else + aSourcePhysCollisionModel = Nothing + End If + + For convexMeshIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 + convexMesh = collisionData.theConvexMeshes(convexMeshIndex) - If faceSection.theBoneIndex >= Me.theMdlFileData.theBones.Count Then + ' [12-Apr-2022] From RED_EYE. (He is using someone else's set of data strutures for PHY file.) + ' flags: has_children: (self.flags >> 0) & 3 ' 0 = false; > 0 true + ' This seems to be correct way rather than checking Me.thePhyFileData.theSourcePhyIsCollisionModel. + ' Example where checking Me.thePhyFileData.theSourcePhyIsCollisionModel is incorrect (because the gib meshes are compiled in): + ' "SourceFilmmaker\game\hl2\models\combine_strider.mdl" + If (convexMesh.flags And 3) > 0 Then Continue For End If - aBone = Me.theMdlFileData.theBones(faceSection.theBoneIndex) - For triangleIndex As Integer = 0 To faceSection.theFaces.Count - 1 - aTriangle = faceSection.theFaces(triangleIndex) + If Me.theMdlFileData.theBones.Count = 1 Then + boneIndex = 0 + Else + boneIndex = convexMesh.theBoneIndex + ' MDL36 and MDL37 need this because their PHY does not store bone index. + ' Model versions above MDL37 can have multiple bones with same name, so this check needs to be last. + If boneIndex < 0 Then + If aSourcePhysCollisionModel IsNot Nothing AndAlso Me.theMdlFileData.theBoneNameToBoneIndexMap.ContainsKey(aSourcePhysCollisionModel.theName) Then + boneIndex = Me.theMdlFileData.theBoneNameToBoneIndexMap(aSourcePhysCollisionModel.theName) + Else + ' Not expected to reach here, but just in case, write a mesh connected to first bone instead of writing an empty mesh. + boneIndex = 0 + End If + End If + End If + aBone = Me.theMdlFileData.theBones(boneIndex) + + For triangleIndex As Integer = 0 To convexMesh.theFaces.Count - 1 + aTriangle = convexMesh.theFaces(triangleIndex) line = " phy" Me.theOutputFileStreamWriter.WriteLine(line) @@ -229,12 +260,17 @@ Public Class SourceSmdFile53 ' 19 -0.000005 1.000002 -0.000043 0.0 0.0 0.0 1 0 ' 19 -0.008333 0.997005 1.003710 0.0 0.0 0.0 1 0 For vertexIndex As Integer = 0 To aTriangle.vertexIndex.Length - 1 - phyVertex = faceSection.theVertices(aTriangle.vertexIndex(vertexIndex)) + 'phyVertex = collisionData.theVertices(aTriangle.vertexIndex(vertexIndex)) + phyVertex = convexMesh.theVertices(aTriangle.vertexIndex(vertexIndex)) + + aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex, aSourcePhysCollisionModel) - aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex) + ''DEBUG: Move different face sections away from each other. + 'aVectorTransformed.x += faceSectionIndex * 20 + 'aVectorTransformed.y += faceSectionIndex * 20 line = " " - line += faceSection.theBoneIndex.ToString(TheApp.InternalNumberFormat) + line += boneIndex.ToString(TheApp.InternalNumberFormat) line += " " line += aVectorTransformed.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " @@ -625,6 +661,56 @@ Public Class SourceSmdFile53 End If End Sub + Private Sub CalculateFirstAnimDescFrameLinesForPhysics(ByRef aFirstAnimationDescFrameLine As AnimationFrameLine) + Dim boneIndex As Integer + Dim aFrameLine As AnimationFrameLine + Dim frameIndex As Integer + Dim frameLineIndex As Integer + Dim aSequenceDesc As SourceMdlSequenceDesc + Dim anAnimationDesc As SourceMdlAnimationDesc52 + + aSequenceDesc = Nothing + anAnimationDesc = Me.theMdlFileData.theAnimationDescs(0) + + Me.theAnimationFrameLines = New SortedList(Of Integer, AnimationFrameLine)() + frameIndex = 0 + Me.theAnimationFrameLines.Clear() + 'If (anAnimationDesc.flags And SourceMdlAnimationDesc.STUDIO_ALLZEROS) = 0 Then + Me.CalcAnimation(aSequenceDesc, anAnimationDesc, frameIndex) + 'End If + + frameLineIndex = 0 + boneIndex = Me.theAnimationFrameLines.Keys(frameLineIndex) + aFrameLine = Me.theAnimationFrameLines.Values(frameLineIndex) + + aFirstAnimationDescFrameLine.rotation = New SourceVector() + aFirstAnimationDescFrameLine.position = New SourceVector() + + aFirstAnimationDescFrameLine.rotation.x = aFrameLine.rotation.x + aFirstAnimationDescFrameLine.rotation.y = aFrameLine.rotation.y + 'If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then + ' Dim z As Double + ' z = aFrameLine.rotation.z + ' z += MathModule.DegreesToRadians(-90) + ' aFirstAnimationDescFrameLine.rotation.z = z + 'Else + aFirstAnimationDescFrameLine.rotation.z = aFrameLine.rotation.z + 'End If + + ''NOTE: Only adjust position if bone is a root bone. Do not know why. + ''If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then + ''TEST: Try this version, because of "sequence_blend from Game Zombie" model. + 'If Me.theMdlFileData.theBones(boneIndex).parentBoneIndex = -1 AndAlso (aFrameLine.position.debug_text.StartsWith("raw") OrElse aFrameLine.rotation.debug_text = "anim+bone") Then + ' aFirstAnimationDescFrameLine.position.x = aFrameLine.position.y + ' aFirstAnimationDescFrameLine.position.y = (-aFrameLine.position.x) + ' aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z + 'Else + aFirstAnimationDescFrameLine.position.x = aFrameLine.position.x + aFirstAnimationDescFrameLine.position.y = aFrameLine.position.y + aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z + 'End If + End Sub + Private Function WriteVertexLine(ByVal aStripGroup As SourceVtxStripGroup07, ByVal aVtxIndexIndex As Integer, ByVal lodIndex As Integer, ByVal meshVertexIndexStart As Integer, ByVal bodyPartVertexIndexStart As Integer) As String Dim aVtxVertexIndex As UShort Dim aVtxVertex As SourceVtxVertex07 @@ -700,33 +786,514 @@ Public Class SourceSmdFile53 Return line End Function - Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone53, ByVal vertex As SourceVector) As SourceVector + Private Sub ProcessTransformsForPhysics() + If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then + Dim aFirstAnimationDescFrameLine As New AnimationFrameLine() + Me.CalculateFirstAnimDescFrameLinesForPhysics(aFirstAnimationDescFrameLine) + + Dim position As SourceVector + Dim rotation As SourceVector + position = aFirstAnimationDescFrameLine.position + rotation = aFirstAnimationDescFrameLine.rotation + + 'MathModule.AngleMatrix(rotation.y, rotation.z, rotation.x, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'MathModule.AngleMatrix(rotation.x, rotation.y, rotation.z, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'Me.worldToPoseColumn3.x = position.x + 'Me.worldToPoseColumn3.y = position.y + 'Me.worldToPoseColumn3.z = position.z + '------ + 'MathModule.AngleMatrix(rotation.x, rotation.y, rotation.z, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + 'poseToWorldColumn3.x = position.x + 'poseToWorldColumn3.y = position.y + 'poseToWorldColumn3.z = position.z + 'MathModule.MatrixInvert(poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + '------ + MathModule.AngleMatrix(rotation.x, rotation.y, rotation.z + MathModule.DegreesToRadians(-90), poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + poseToWorldColumn3.x = position.y + poseToWorldColumn3.y = -position.x + poseToWorldColumn3.z = position.z + MathModule.MatrixInvert(poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + End If + End Sub + + Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone53, ByVal vertex As SourceVector, ByVal aSourcePhysCollisionModel As SourcePhyPhysCollisionModel) As SourceVector Dim aVectorTransformed As New SourceVector Dim aVector As New SourceVector() - If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then - aVectorTransformed.x = 1 / 0.0254 * vertex.z - aVectorTransformed.y = 1 / 0.0254 * -vertex.x - aVectorTransformed.z = 1 / 0.0254 * -vertex.y + 'NOTE: Too small. + 'aVectorTransformed.x = vertex.x + 'aVectorTransformed.y = vertex.y + 'aVectorTransformed.z = vertex.z + '------ + 'NOTE: Rotated for: + ' simple_shape + ' L4D2 w_models\weapons\w_minigun + 'aVectorTransformed.x = 1 / 0.0254 * vertex.x + 'aVectorTransformed.y = 1 / 0.0254 * vertex.y + 'aVectorTransformed.z = 1 / 0.0254 * vertex.z + '------ + 'NOTE: Works for: + ' simple_shape + ' L4D2 w_models\weapons\w_minigun + ' L4D2 w_models\weapons\w_smg_uzi + ' L4D2 props_vehicles\van + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.x + 'aVectorTransformed.z = 1 / 0.0254 * -vertex.y + '------ + 'NOTE: Rotated for: + ' L4D2 w_models\weapons\w_minigun + 'aVectorTransformed.x = 1 / 0.0254 * vertex.x + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.y + 'aVectorTransformed.z = 1 / 0.0254 * vertex.z + '------ + 'NOTE: Rotated for: + ' L4D2 props_vehicles\van + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.y + 'aVectorTransformed.z = 1 / 0.0254 * vertex.x + '------ + 'NOTE: Rotated for: + ' L4D2 w_models\weapons\w_minigun + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '------ + 'NOTE: Rotated for: + ' L4D2 w_models\weapons\w_minigun + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '------ + 'NOTE: Works for: + ' L4D2 w_models\weapons\w_minigun + ' L4D2 w_models\weapons\w_smg_uzi + 'NOTE: Rotated for: + ' simple_shape + ' L4D2 props_vehicles\van + 'NOTE: Each mesh piece rotated for: + ' L4D2 survivors\survivor_producer + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.z = 1 / 0.0254 * vertex.x + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '------ + 'NOTE: Works for: + ' simple_shape + ' L4D2 props_vehicles\van + ' L4D2 survivors\survivor_producer + ' L4D2 w_models\weapons\w_autoshot_m4super + ' L4D2 w_models\weapons\w_desert_eagle + ' L4D2 w_models\weapons\w_minigun + ' L4D2 w_models\weapons\w_rifle_m16a2 + ' L4D2 w_models\weapons\w_smg_uzi + 'NOTE: Rotated for: + ' L4D2 w_models\weapons\w_desert_rifle + ' L4D2 w_models\weapons\w_shotgun_spas + 'If Me.thePhyFileData.theSourcePhyIsCollisionModel Then + ' aVectorTransformed.x = 1 / 0.0254 * vertex.z + ' aVectorTransformed.y = 1 / 0.0254 * -vertex.x + ' aVectorTransformed.z = 1 / 0.0254 * -vertex.y + 'Else + ' 'NOTE: Correct: + ' ' Team Fortress 2\tf2_misc_dir\models\player\demo.mdl + ' aVector.x = 1 / 0.0254 * vertex.x + ' aVector.y = 1 / 0.0254 * vertex.z + ' aVector.z = 1 / 0.0254 * -vertex.y + ' aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + 'End If + '------ + 'TODO: [TransformPhyVertex] Merge the various code blocks (separated by MDL version) into one code block. + If Me.theMdlFileData.version >= 44 AndAlso Me.theMdlFileData.version <= 47 Then + ' This works for various weapons and vehicles in HL2. + If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then + aVectorTransformed.x = 1 / 0.0254 * vertex.z + aVectorTransformed.y = 1 / 0.0254 * -vertex.x + aVectorTransformed.z = 1 / 0.0254 * -vertex.y + Else + aVector.x = 1 / 0.0254 * vertex.x + aVector.y = 1 / 0.0254 * vertex.z + aVector.z = 1 / 0.0254 * -vertex.y + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + End If Else - 'TEST: Shows blocks, but all seem to be at origin. - aVectorTransformed.x = 1 / 0.0254 * vertex.z - aVectorTransformed.y = 1 / 0.0254 * -vertex.x - aVectorTransformed.z = 1 / 0.0254 * -vertex.y - '------ - 'TEST: Strecthed flat planes. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - '------ - 'TEST: Strecthed flat planes. - 'aVector.x = 1 / 0.0254 * vertex.z - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then + 'Dim copyOfVector As New SourceVector() + ''copyOfVector.x = 1 / 0.0254 * vertex.x + ''copyOfVector.y = 1 / 0.0254 * vertex.y + ''copyOfVector.z = 1 / 0.0254 * vertex.z + ''copyOfVector.x = 1 / 0.0254 * vertex.x + ''copyOfVector.y = 1 / 0.0254 * vertex.z + ''copyOfVector.z = 1 / 0.0254 * -vertex.y + 'copyOfVector.x = 1 / 0.0254 * vertex.z + 'copyOfVector.y = 1 / 0.0254 * -vertex.x + 'copyOfVector.z = 1 / 0.0254 * -vertex.y + 'aVector = MathModule.VectorTransform(copyOfVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + ''aVector.x = 1 / 0.0254 * vertex.z + ''aVector.y = 1 / 0.0254 * -vertex.x + ''aVector.z = 1 / 0.0254 * -vertex.y + ''aVectorTransformed.x = 1 / 0.0254 * vertex.z + ''aVectorTransformed.y = 1 / 0.0254 * -vertex.x + ''aVectorTransformed.z = 1 / 0.0254 * -vertex.y + + 'Dim debug As Integer = 4242 + + ''Dim temp As Double + ''temp = aVector.y + ''aVector.y = aVector.z + ''aVector.z = -temp + ''------ + ''aVector.y = -aVector.y + ''------ + ''Dim temp As Double + ''temp = aVector.x + ''aVector.x = aVector.z + ''aVector.z = -aVector.y + ''aVector.y = -temp + ''------ + ''Dim temp As Double + ''temp = aVector.x + ''aVectorTransformed.x = aVector.z + ''aVectorTransformed.z = -aVector.y + ''aVectorTransformed.y = -temp + + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + + '[2017-12-22] + ' Correct for cube_like_mesh + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.x + 'aVectorTransformed.z = 1 / 0.0254 * -vertex.y + '------ + ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.y + 'aVectorTransformed.z = 1 / 0.0254 * vertex.x + '------ + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * -vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + ' Correct for cube_like_mesh + ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl + ' Incorrect for L4D2 w_models/weapons/w_rifle_m16a2.mdl + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.poseToWorldColumn0, Me.poseToWorldColumn1, Me.poseToWorldColumn2, Me.poseToWorldColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + ''Dim worldToBoneColumn0 As New SourceVector() + ''Dim worldToBoneColumn1 As New SourceVector() + ''Dim worldToBoneColumn2 As New SourceVector() + ''Dim worldToBoneColumn3 As New SourceVector() + ''MathModule.AngleMatrix(aBone.rotation.x, aBone.rotation.y, aBone.rotation.z, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) + ''worldToBoneColumn3.x = aBone.position.x + ''worldToBoneColumn3.y = aBone.position.y + ''worldToBoneColumn3.z = aBone.position.z + ''aVector.x = aVectorTransformed.x + ''aVector.y = aVectorTransformed.y + ''aVector.z = aVectorTransformed.z + ''aVectorTransformed = MathModule.VectorTransform(aVector, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + ' ''NOTE: These 3 lines work for airport_fuel_truck, ambulance, and army_truck, but not w_desert_file and w_rifle_m16a2. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + ' ''NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. + ''aVector.x = 1 / 0.0254 * vertex.x + ''aVector.y = 1 / 0.0254 * -vertex.y + ''aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + ''aVector.x = aVectorTransformed.x + ''aVector.y = aVectorTransformed.z + ''aVector.z = -aVectorTransformed.y + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '====== + 'FROM: collisionmodel.cpp ConvertToWorldSpace() + If (Me.theMdlFileData.flags And SourceMdlFileData.STUDIOHDR_FLAGS_STATIC_PROP) > 0 Then + 'NOTE: These 3 lines do not work for airport_fuel_truck, ambulance, and army_truck. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + '' Still need a rotate 90 on the z. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.y + + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + + '------ + + 'TEST: Works for props_vehciles that use $staticprop. + aVector.x = 1 / 0.0254 * vertex.z + aVector.y = 1 / 0.0254 * -vertex.x + aVector.z = 1 / 0.0254 * -vertex.y + aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + aVector.x = aVectorTransformed.x + aVector.y = aVectorTransformed.z + aVector.z = -aVectorTransformed.y + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + Else + 'NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. + 'TEST: Did not work for 50_cal. Rotated 180. Original model has phys mesh rotated oddly, anyway. + 'TEST: Incorrect. Need to 180 on the Y and -1 on scale Z. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'TEST: Incorrect. Need to 180 on the Y. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'TEST: Incorrect. Need to -1 on scale Z. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * -vertex.z + 'TEST: Works for w_minigun. + 'TEST: Works for 50cal, but be aware that the phys mesh does not look right for the model. It does look like original model, though. + 'TEST: Does not work for Garry's Mod addon "dodge_daytona" 236224475. + aVector.x = 1 / 0.0254 * vertex.x + aVector.y = 1 / 0.0254 * -vertex.y + aVector.z = 1 / 0.0254 * -vertex.z + + aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + aVector.x = aVectorTransformed.x + aVector.y = aVectorTransformed.y + aVector.z = aVectorTransformed.z + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + End If + Else + 'FROM: collisionmodel.cpp ConvertToBoneSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + aVector.x = 1 / 0.0254 * vertex.x + aVector.y = 1 / 0.0254 * vertex.z + aVector.z = 1 / 0.0254 * -vertex.y + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + End If End If + 'If Me.theMdlFileData.theBoneTransforms IsNot Nothing Then + ' Dim transform As SourceMdlBoneTransform + ' Dim boneIndex As Integer + ' Dim preToBoneColumn0 As New SourceVector() + ' Dim preToBoneColumn1 As New SourceVector() + ' Dim preToBoneColumn2 As New SourceVector() + ' Dim preToBoneColumn3 As New SourceVector() + ' Dim boneToPostColumn0 As New SourceVector() + ' Dim boneToPostColumn1 As New SourceVector() + ' Dim boneToPostColumn2 As New SourceVector() + ' Dim boneToPostColumn3 As New SourceVector() + + ' 'TODO: Find the real boneIndex based on boneName + ' boneIndex = 0 + ' transform = Me.theMdlFileData.theBoneTransforms(boneIndex) + + ' 'MathModule.MatrixInvert(poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + ' MathModule.R_ConcatTransforms(transform.preTransformColumn0, transform.preTransformColumn1, transform.preTransformColumn2, transform.preTransformColumn3, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3, preToBoneColumn0, preToBoneColumn1, preToBoneColumn2, preToBoneColumn3) + ' MathModule.R_ConcatTransforms(preToBoneColumn0, preToBoneColumn1, preToBoneColumn2, preToBoneColumn3, transform.postTransformColumn0, transform.postTransformColumn1, transform.postTransformColumn2, transform.postTransformColumn3, boneToPostColumn0, boneToPostColumn1, boneToPostColumn2, boneToPostColumn3) + ' aVectorTransformed = MathModule.VectorITransform(aVector, boneToPostColumn0, boneToPostColumn1, boneToPostColumn2, boneToPostColumn3) + 'Else + ' aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + 'End If + + + + '------ + 'NOTE: Works for: + ' survivor_producer + 'NOTE: Does not work for: + ' w_smg_uzi() + 'phyVertex.x = 1 / 0.0254 * aVector.x + 'phyVertex.y = 1 / 0.0254 * aVector.z + 'phyVertex.z = 1 / 0.0254 * -aVector.y + '------ + 'NOTE: These two lines match orientation for cstrike it_lampholder1 model, + ' but still doesn't compile properly. + 'NOTE: Does not work for: + ' w_smg_uzi() + 'phyVertex.x = 1 / 0.0254 * aVector.z + 'phyVertex.y = 1 / 0.0254 * -aVector.x + 'phyVertex.z = 1 / 0.0254 * -aVector.y + '------ + 'NOTE: Does not work for: + ' w_smg_uzi() + 'phyVertex.x = 1 / 0.0254 * aVector.y + 'phyVertex.y = 1 / 0.0254 * aVector.x + 'phyVertex.z = 1 / 0.0254 * -aVector.z + '------ + 'NOTE: Does not work for: + ' w_smg_uzi() + 'phyVertex.x = 1 / 0.0254 * aVector.x + 'phyVertex.y = 1 / 0.0254 * aVector.y + 'phyVertex.z = 1 / 0.0254 * -aVector.z + '------ + 'NOTE: Does not work for: + ' w_smg_uzi() + 'phyVertex.x = 1 / 0.0254 * -aVector.y + 'phyVertex.y = 1 / 0.0254 * aVector.x + 'phyVertex.z = 1 / 0.0254 * aVector.z + '------ + 'NOTE: Does not work for: + ' w_smg_uzi() + 'phyVertex.x = 1 / 0.0254 * -aVector.y + 'phyVertex.y = 1 / 0.0254 * aVector.x + 'phyVertex.z = 1 / 0.0254 * aVector.z + '------ + 'NOTE: Does not work for: + ' w_smg_uzi() + 'phyVertex.x = 1 / 0.0254 * aVector.z + 'phyVertex.y = 1 / 0.0254 * aVector.y + 'phyVertex.z = 1 / 0.0254 * aVector.x + '------ + 'NOTE: Works for: + ' w_smg_uzi() + 'NOTE: Does not work for: + ' survivor_producer + 'phyVertex.x = 1 / 0.0254 * aVector.z + 'phyVertex.y = 1 / 0.0254 * -aVector.y + 'phyVertex.z = 1 / 0.0254 * aVector.x + '------ + 'phyVertex.x = 1 / 0.0254 * aVector.z + 'phyVertex.y = 1 / 0.0254 * -aVector.y + 'phyVertex.z = 1 / 0.0254 * -aVector.x + '------ + 'If Me.theSourceEngineModel.thePhyFileHeader.theSourcePhyIsCollisionModel Then + ' 'TEST: Does not rotate L4D2's van phys mesh correctly. + ' 'aVector.x = 1 / 0.0254 * phyVertex.vertex.x + ' 'aVector.y = 1 / 0.0254 * phyVertex.vertex.y + ' 'aVector.z = 1 / 0.0254 * phyVertex.vertex.z + ' 'TEST: Does not rotate L4D2's van phys mesh correctly. + ' 'aVector.x = 1 / 0.0254 * phyVertex.vertex.y + ' 'aVector.y = 1 / 0.0254 * -phyVertex.vertex.x + ' 'aVector.z = 1 / 0.0254 * phyVertex.vertex.z + ' 'TEST: Does not rotate L4D2's van phys mesh correctly. + ' 'aVector.x = 1 / 0.0254 * phyVertex.vertex.z + ' 'aVector.y = 1 / 0.0254 * -phyVertex.vertex.y + ' 'aVector.z = 1 / 0.0254 * phyVertex.vertex.x + ' 'TEST: Does not rotate L4D2's van phys mesh correctly. + ' 'aVector.x = 1 / 0.0254 * phyVertex.vertex.x + ' 'aVector.y = 1 / 0.0254 * phyVertex.vertex.z + ' 'aVector.z = 1 / 0.0254 * -phyVertex.vertex.y + ' 'TEST: Works for L4D2's van phys mesh. + ' ' Does not work for L4D2 w_model\weapons\w_minigun.mdl. + ' aVector.x = 1 / 0.0254 * vertex.z + ' aVector.y = 1 / 0.0254 * -vertex.x + ' aVector.z = 1 / 0.0254 * -vertex.y + 'Else + ' 'TEST: Does not work for L4D2 w_model\weapons\w_minigun.mdl. + ' aVector.x = 1 / 0.0254 * vertex.x + ' aVector.y = 1 / 0.0254 * vertex.z + ' aVector.z = 1 / 0.0254 * -vertex.y + + ' aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + 'End If + '------ + 'TEST: Does not rotate L4D2's van phys mesh correctly. + 'aVector.x = 1 / 0.0254 * phyVertex.vertex.x + 'aVector.y = 1 / 0.0254 * phyVertex.vertex.y + 'aVector.z = 1 / 0.0254 * phyVertex.vertex.z + 'TEST: Does not rotate L4D2's van phys mesh correctly. + 'aVector.x = 1 / 0.0254 * phyVertex.vertex.y + 'aVector.y = 1 / 0.0254 * -phyVertex.vertex.x + 'aVector.z = 1 / 0.0254 * phyVertex.vertex.z + 'TEST: works for survivor_producer; matches ref and phy meshes of van, but both are rotated 90 degrees on z-axis + 'aVector.x = 1 / 0.0254 * phyVertex.vertex.x + 'aVector.y = 1 / 0.0254 * phyVertex.vertex.z + 'aVector.z = 1 / 0.0254 * -phyVertex.vertex.y + + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + Return aVectorTransformed End Function @@ -1469,6 +2036,15 @@ Public Class SourceSmdFile53 Private theAnimationFrameLines As SortedList(Of Integer, AnimationFrameLine) + Private worldToPoseColumn0 As New SourceVector() + Private worldToPoseColumn1 As New SourceVector() + Private worldToPoseColumn2 As New SourceVector() + Private worldToPoseColumn3 As New SourceVector() + Private poseToWorldColumn0 As New SourceVector() + Private poseToWorldColumn1 As New SourceVector() + Private poseToWorldColumn2 As New SourceVector() + Private poseToWorldColumn3 As New SourceVector() + #End Region End Class From 8b5ef5645a6587f2d90db47d1b4615bceb2fa510 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 11 Aug 2022 17:20:52 -0400 Subject: [PATCH 07/39] swap version back --- Crowbar/Crowbar.vbproj | 2 +- CrowbarLauncher/CrowbarLauncher.vbproj | 2 +- CrowbarSteamPipe/CrowbarSteamPipe.vbproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index dc44a69..49a49dd 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -13,7 +13,7 @@ WindowsFormsWithCustomSubMain On Resources\crowbar_icon.ico - v4.8 + v4.0 diff --git a/CrowbarLauncher/CrowbarLauncher.vbproj b/CrowbarLauncher/CrowbarLauncher.vbproj index 0cd21b7..dcbdbc4 100644 --- a/CrowbarLauncher/CrowbarLauncher.vbproj +++ b/CrowbarLauncher/CrowbarLauncher.vbproj @@ -11,7 +11,7 @@ CrowbarLauncher 512 WindowsFormsWithCustomSubMain - v4.8 + v4.0 true diff --git a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj index c4ef19b..fadfb6b 100644 --- a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj +++ b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj @@ -11,7 +11,7 @@ CrowbarSteamPipe 512 Console - v4.8 + v4.0 true From 3ff71062b5fdc4a54ddc516db0312d2a429076d9 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Fri, 26 Aug 2022 13:47:39 -0400 Subject: [PATCH 08/39] yep --- Crowbar/Crowbar.vbproj | 2 +- CrowbarLauncher/CrowbarLauncher.vbproj | 2 +- CrowbarSteamPipe/CrowbarSteamPipe.vbproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 49a49dd..dc44a69 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -13,7 +13,7 @@ WindowsFormsWithCustomSubMain On Resources\crowbar_icon.ico - v4.0 + v4.8 diff --git a/CrowbarLauncher/CrowbarLauncher.vbproj b/CrowbarLauncher/CrowbarLauncher.vbproj index dcbdbc4..0cd21b7 100644 --- a/CrowbarLauncher/CrowbarLauncher.vbproj +++ b/CrowbarLauncher/CrowbarLauncher.vbproj @@ -11,7 +11,7 @@ CrowbarLauncher 512 WindowsFormsWithCustomSubMain - v4.0 + v4.8 true diff --git a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj index fadfb6b..c4ef19b 100644 --- a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj +++ b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj @@ -11,7 +11,7 @@ CrowbarSteamPipe 512 Console - v4.0 + v4.8 true From 5f609a3953375d719b93387d68e83a509972363d Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Fri, 26 Aug 2022 16:15:21 -0400 Subject: [PATCH 09/39] some anim fixes plus updated smd file --- .../SourceModel53/SourceMdlFile53.vb | 319 +++--- .../SourceMdlFileData/SourceMdlAnimation53.vb | 72 ++ .../SourceMdlAnimationDesc53.vb | 201 ++++ .../SourceMdlFileData/SourceMdlFileData53.vb | 4 +- .../GameModel/SourceModel53/SourceModel53.vb | 2 +- .../GameModel/SourceModel53/SourceQcFile53.vb | 16 +- .../SourceModel53/SourceSmdFile53.vb | 920 ++++++++++-------- Crowbar/Crowbar.vbproj | 4 +- 8 files changed, 947 insertions(+), 591 deletions(-) create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 60e6550..e196e42 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -925,10 +925,10 @@ Public Class SourceMdlFile53 Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.localAnimationOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position - Me.theMdlFileData.theAnimationDescs = New List(Of SourceMdlAnimationDesc52)(Me.theMdlFileData.localAnimationCount) + Me.theMdlFileData.theAnimationDescs = New List(Of SourceMdlAnimationDesc53)(Me.theMdlFileData.localAnimationCount) For i As Integer = 0 To Me.theMdlFileData.localAnimationCount - 1 animInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim anAnimationDesc As New SourceMdlAnimationDesc52() + Dim anAnimationDesc As New SourceMdlAnimationDesc53() anAnimationDesc.theOffsetStart = Me.theInputFileReader.BaseStream.Position @@ -940,11 +940,7 @@ Public Class SourceMdlFile53 anAnimationDesc.movementCount = Me.theInputFileReader.ReadInt32() anAnimationDesc.movementOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() - - For x As Integer = 0 To anAnimationDesc.unused1.Length - 1 - anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() - Next + 'anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.animBlock = Me.theInputFileReader.ReadInt32() anAnimationDesc.animOffset = Me.theInputFileReader.ReadInt32() @@ -958,8 +954,12 @@ Public Class SourceMdlFile53 anAnimationDesc.spanFrameCount = Me.theInputFileReader.ReadInt16() anAnimationDesc.spanCount = Me.theInputFileReader.ReadInt16() - 'anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() - 'anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() + anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() + + For x As Integer = 0 To 3 + anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() + Next Me.theMdlFileData.theAnimationDescs.Add(anAnimationDesc) @@ -977,7 +977,7 @@ Public Class SourceMdlFile53 Public Sub ReadAnimationSections() If Me.theMdlFileData.theAnimationDescs IsNot Nothing Then - For Each anAnimationDesc As SourceMdlAnimationDesc52 In Me.theMdlFileData.theAnimationDescs + For Each anAnimationDesc As SourceMdlAnimationDesc53 In Me.theMdlFileData.theAnimationDescs If anAnimationDesc.sectionOffset <> 0 AndAlso anAnimationDesc.sectionFrameCount > 0 Then Dim sectionCount As Integer @@ -1006,8 +1006,8 @@ Public Class SourceMdlFile53 Public Sub ReadAnimationMdlBlocks() If Me.theMdlFileData.theAnimationDescs IsNot Nothing Then Dim animInputFileStreamPosition As Long - Dim anAnimationDesc As SourceMdlAnimationDesc52 - Dim aSectionOfAnimation As List(Of SourceMdlAnimation) + Dim anAnimationDesc As SourceMdlAnimationDesc53 + Dim aSectionOfAnimation As List(Of SourceMdlAnimation53) Dim aSectionOfFrameAnimation As SourceAniFrameAnim52 For anAnimDescIndex As Integer = 0 To Me.theMdlFileData.theAnimationDescs.Count - 1 @@ -1071,8 +1071,8 @@ Public Class SourceMdlFile53 Me.ReadAnimationFrameByBone(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, sectionIndex, True) End If Else - anAnimationDesc.theSectionsOfAnimations = New List(Of List(Of SourceMdlAnimation))() - aSectionOfAnimation = New List(Of SourceMdlAnimation)() + anAnimationDesc.theSectionsOfAnimations = New List(Of List(Of SourceMdlAnimation53))() + aSectionOfAnimation = New List(Of SourceMdlAnimation53)() anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) If anAnimationDesc.sectionOffset <> 0 AndAlso anAnimationDesc.sectionFrameCount > 0 Then @@ -1092,7 +1092,7 @@ Public Class SourceMdlFile53 'NOTE: First sectionOfAnimation was created above. For sectionIndex As Integer = 1 To sectionCount - 1 - aSectionOfAnimation = New List(Of SourceMdlAnimation)() + aSectionOfAnimation = New List(Of SourceMdlAnimation53)() anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) Next @@ -1132,7 +1132,7 @@ Public Class SourceMdlFile53 End If End Sub - Protected Sub ReadAnimationDescName(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Sub ReadAnimationDescName(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) If anAnimationDesc.nameOffset <> 0 Then Dim fileOffsetStart As Long Dim fileOffsetEnd As Long @@ -1158,7 +1158,28 @@ Public Class SourceMdlFile53 End If End Sub - Protected Function ReadAnimationDescSpanData(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) As Long + ' for (j = 0; j < g_numbones; j++) + ' { + ' if (g_bonetable[j].flags & BONE_HAS_SAVEFRAME_POS) + ' { + ' for (int n = 0; n < panimdesc[i].zeroframecount; n++) + ' { + ' *(Vector48 *)pData = anim->sanim[panimdesc[i].zeroframespan*n][j].pos; + ' pData += sizeof( Vector48 ); + ' } + ' } + ' if (g_bonetable[j].flags & BONE_HAS_SAVEFRAME_ROT) + ' { + ' for (int n = 0; n < panimdesc[i].zeroframecount; n++) + ' { + ' Quaternion q; + ' AngleQuaternion( anim->sanim[panimdesc[i].zeroframespan*n][j].rot, q ); + ' *((Quaternion64 *)pData) = q; + ' pData += sizeof( Quaternion64 ); + ' } + ' } + ' } + Protected Function ReadAnimationDescSpanData(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long = 0 @@ -1204,41 +1225,7 @@ Public Class SourceMdlFile53 Return fileOffsetEnd End Function - 'TODO: Should this be the same as SourceAniFile49.ReadAniAnimation()? - 'Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation)) - ' Dim animationInputFileStreamPosition As Long - ' 'Dim inputFileStreamPosition As Long - ' 'Dim fileOffsetStart As Long - ' 'Dim fileOffsetEnd As Long - ' 'Dim fileOffsetStart2 As Long - ' 'Dim fileOffsetEnd2 As Long - ' Dim boneCount As Integer - - ' Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition, SeekOrigin.Begin) - ' 'fileOffsetStart = Me.theInputFileReader.BaseStream.Position - - ' For frameIndex As Integer = 0 To sectionFrameCount - 1 - ' animationInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - ' 'Dim anAnimation As New SourceMdlAnimation() - - ' 'boneCount = Me.theMdlFileData.theBones.Count - ' 'For boneIndex As Integer = 0 To boneCount - 1 - ' ' anAnimation.flags = Me.theInputFileReader.ReadByte() - ' 'Next - - ' 'aSectionOfAnimation.Add(anAnimation) - - ' ''inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - - ' ''Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - - ' Me.theMdlFileData.theFileSeekLog.Add(animationInputFileStreamPosition, Me.theInputFileReader.BaseStream.Position - 1, "anAnimationDesc.anAnimation [ReadAnimationFrameByBone()] (frameCount = " + CStr(anAnimationDesc.frameCount) + "; sectionFrameCount = " + CStr(sectionFrameCount) + ")") - ' Next - - ' 'Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.anAnimation [ReadAnimationFrameByBone()] alignment") - 'End Sub - '====== - Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal sectionFrameCount As Integer, ByVal sectionIndex As Integer, ByVal lastSectionIsBeingRead As Boolean) + Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal sectionFrameCount As Integer, ByVal sectionIndex As Integer, ByVal lastSectionIsBeingRead As Boolean) Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition, SeekOrigin.Begin) Dim animFrameInputFileStreamPosition As Long @@ -1293,6 +1280,44 @@ Public Class SourceMdlFile53 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "aSectionOfAnimation.theBoneFlags " + aSectionOfAnimation.theBoneFlags.Count.ToString()) Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "aSectionOfAnimation.theBoneFlags alignment") + 'fileOffsetStart = Me.theInputFileReader.BaseStream.Position + + ''Dim unknownByte As Byte + ''aSectionOfAnimation.theUnknownBytes01 = New List(Of Byte)(boneCount) + ''aSectionOfAnimation.theUnknownBytes02 = New List(Of Byte)(boneCount) + ''aSectionOfAnimation.theUnknownBytes03 = New List(Of Byte)(boneCount) + ''For boneIndex As Integer = 0 To boneCount - 1 + '' unknownByte = Me.theInputFileReader.ReadByte() + '' aSectionOfAnimation.theUnknownBytes01.Add(unknownByte) + ''Next + ''For boneIndex As Integer = 0 To boneCount - 1 + '' unknownByte = Me.theInputFileReader.ReadByte() + '' aSectionOfAnimation.theUnknownBytes02.Add(unknownByte) + ''Next + ''For boneIndex As Integer = 0 To boneCount - 1 + '' unknownByte = Me.theInputFileReader.ReadByte() + '' aSectionOfAnimation.theUnknownBytes03.Add(unknownByte) + ''Next + ' ''------ + ''Dim unknownBytes As Integer + ''aSectionOfAnimation.theUnknownBytes = New List(Of Integer)(boneCount) + ''For boneIndex As Integer = 0 To boneCount - 1 + '' unknownBytes = Me.theInputFileReader.ReadInt32() + '' 'unknownBytes = Me.theInputFileReader.ReadInt16() + '' aSectionOfAnimation.theUnknownBytes.Add(unknownBytes) + ''Next + ''------ + 'Dim unknownBytes As Integer + 'aSectionOfAnimation.theUnknownBytes = New List(Of Integer)(aSectionOfAnimation.unused(1)) + 'For boneIndex As Integer = 0 To aSectionOfAnimation.unused(1) - 1 + ' unknownBytes = Me.theInputFileReader.ReadInt32() + ' 'unknownBytes = Me.theInputFileReader.ReadInt16() + ' aSectionOfAnimation.theUnknownBytes.Add(unknownBytes) + 'Next + + 'fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + 'Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAniFrameAnim.theUnknownBytes") + If aSectionOfAnimation.constantsOffset <> 0 Then Me.theInputFileReader.BaseStream.Seek(animFrameInputFileStreamPosition + aSectionOfAnimation.constantsOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position @@ -1328,7 +1353,7 @@ Public Class SourceMdlFile53 End If End If - If aSectionOfAnimation.frameOffset <> 0 Then + If aSectionOfAnimation.frameLength > 0 AndAlso aSectionOfAnimation.frameOffset <> 0 Then Me.theInputFileReader.BaseStream.Seek(animFrameInputFileStreamPosition + aSectionOfAnimation.frameOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position @@ -1342,7 +1367,7 @@ Public Class SourceMdlFile53 adjustedFrameCount = sectionFrameCount + 1 End If - For frameIndex As Integer = 0 To sectionFrameCount - 1 + For frameIndex As Integer = 0 To adjustedFrameCount - 1 aBoneFrameDataInfoList = New List(Of BoneFrameDataInfo49)(boneCount) If lastSectionIsBeingRead OrElse (frameIndex < (adjustedFrameCount - 1)) Then aSectionOfAnimation.theBoneFrameDataInfos.Add(aBoneFrameDataInfoList) @@ -1406,15 +1431,15 @@ Public Class SourceMdlFile53 End Try End Sub - Protected Sub ReadMdlAnimation(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation), ByVal lastSectionIsBeingRead As Boolean) + Protected Sub ReadMdlAnimation(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation53), ByVal lastSectionIsBeingRead As Boolean) Dim animationInputFileStreamPosition As Long Dim nextAnimationInputFileStreamPosition As Long Dim animValuePointerInputFileStreamPosition As Long - Dim rotValuePointerInputFileStreamPosition As Long - Dim posValuePointerInputFileStreamPosition As Long + 'Dim rotValuePointerInputFileStreamPosition As Long + 'Dim posValuePointerInputFileStreamPosition As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long - Dim anAnimation As SourceMdlAnimation + Dim anAnimation As SourceMdlAnimation53 Dim boneCount As Integer Dim boneIndex As Byte @@ -1441,114 +1466,46 @@ Public Class SourceMdlFile53 End If 'DEBUG: If boneIndex >= boneCount Then + ' L4D2 "left4dead2\ghostanim.mdl" reaches here. Dim badIfGetsHere As Integer = 42 Exit For End If - anAnimation = New SourceMdlAnimation() + anAnimation = New SourceMdlAnimation53() aSectionOfAnimation.Add(anAnimation) + anAnimation.translationScale = Me.theInputFileReader.ReadSingle() + anAnimation.boneIndex = boneIndex anAnimation.flags = Me.theInputFileReader.ReadByte() - anAnimation.nextSourceMdlAnimationOffset = Me.theInputFileReader.ReadInt16() - - 'DEBUG: - If (anAnimation.flags And &H40) > 0 Then - Dim badIfGetsHere As Integer = 42 - End If - If (anAnimation.flags And &H80) > 0 Then - Dim badIfGetsHere As Integer = 42 - End If - - 'If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then - 'End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT2) > 0 Then - anAnimation.theRot64bits = New SourceQuaternion64bits() - anAnimation.theRot64bits.theBytes = Me.theInputFileReader.ReadBytes(8) - - 'Me.DebugQuaternion(anAnimation.theRot64) - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT) > 0 Then - anAnimation.theRot48bits = New SourceQuaternion48bits() - anAnimation.theRot48bits.theXInput = Me.theInputFileReader.ReadUInt16() - anAnimation.theRot48bits.theYInput = Me.theInputFileReader.ReadUInt16() - anAnimation.theRot48bits.theZWInput = Me.theInputFileReader.ReadUInt16() - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS) > 0 Then - anAnimation.thePos = New SourceVector48bits() - anAnimation.thePos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.thePos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.thePos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - End If - - animValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - ' First, read both sets of offsets. - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMROT) > 0 Then - rotValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anAnimation.theRotV = New SourceMdlAnimationValuePointer() + anAnimation.unk = Me.theInputFileReader.ReadInt16() - anAnimation.theRotV.animXValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.theRotV.theAnimXValues Is Nothing Then - anAnimation.theRotV.theAnimXValues = New List(Of SourceMdlAnimationValue)() - End If + anAnimation.theRot64bits = New SourceQuaternion64bits() + anAnimation.theRot64bits.theBytes = Me.theInputFileReader.ReadBytes(8) - anAnimation.theRotV.animYValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.theRotV.theAnimYValues Is Nothing Then - anAnimation.theRotV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - End If + 'Me.DebugQuaternion(anAnimation.theRot64) + anAnimation.thePos = New SourceVector48bits() + anAnimation.thePos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.thePos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.thePos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.theRotV.animZValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.theRotV.theAnimZValues Is Nothing Then - anAnimation.theRotV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - End If - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMPOS) > 0 Then - posValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anAnimation.thePosV = New SourceMdlAnimationValuePointer() + anAnimation.theScale = New SourceVector48bits() + anAnimation.theScale.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.theScale.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.theScale.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.thePosV.animXValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.thePosV.theAnimXValues Is Nothing Then - anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() - End If + anAnimation.nextSourceMdlAnimationOffset = Me.theInputFileReader.ReadInt32() - anAnimation.thePosV.animYValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.thePosV.theAnimYValues Is Nothing Then - anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - End If + animValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anAnimation.thePosV.animZValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.thePosV.theAnimZValues Is Nothing Then - anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - End If - End If + ' First, read both sets of offsets. Me.theMdlFileData.theFileSeekLog.Add(animationInputFileStreamPosition, Me.theInputFileReader.BaseStream.Position - 1, "anAnimationDesc.anAnimation (frameCount = " + CStr(anAnimationDesc.frameCount) + "; sectionFrameCount = " + CStr(sectionFrameCount) + ")") ' Second, read the anim values using the offsets. 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMROT) > 0 Then - If anAnimation.theRotV.animXValueOffset > 0 Then - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRotV.animXValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimXValues, "anAnimation.theRotV.theAnimXValues") - End If - If anAnimation.theRotV.animYValueOffset > 0 Then - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRotV.animYValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimYValues, "anAnimation.theRotV.theAnimYValues") - End If - If anAnimation.theRotV.animZValueOffset > 0 Then - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRotV.animZValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimZValues, "anAnimation.theRotV.theAnimZValues") - End If - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMPOS) > 0 Then - If anAnimation.thePosV.animXValueOffset > 0 Then - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.thePosV.animXValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") - End If - If anAnimation.thePosV.animYValueOffset > 0 Then - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.thePosV.animYValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimYValues, "anAnimation.thePosV.theAnimYValues") - End If - If anAnimation.thePosV.animZValueOffset > 0 Then - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.thePosV.animZValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimZValues, "anAnimation.thePosV.theAnimZValues") - End If - End If + 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) 'NOTE: If the offset is 0 then there are no more bone animation structures, so end the loop. @@ -1559,7 +1516,7 @@ Public Class SourceMdlFile53 Else ' Skip to next anim, just in case not all data is being read in. nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + anAnimation.nextSourceMdlAnimationOffset - ''TEST: Use this with ANI file, so see if it extracts better. + ''TEST: Use this with ANI file, to see if it extracts better. 'nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + CType(anAnimation.nextSourceMdlAnimationOffset, UShort) If nextAnimationInputFileStreamPosition < Me.theInputFileReader.BaseStream.Position Then 'PROBLEM! Should not be going backwards in file. @@ -1805,7 +1762,7 @@ Public Class SourceMdlFile53 'End Sub - Protected Sub ReadMdlIkRules(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Function ReadMdlIkRules(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long If anAnimationDesc.ikRuleCount > 0 Then Dim ikRuleInputFileStreamPosition As Long Dim inputFileStreamPosition As Long @@ -1816,7 +1773,6 @@ Public Class SourceMdlFile53 Dim fileOffsetEndOfIkRuleExtraData As Long Dim fileOffsetOfLastEndOfIkRuleExtraData As Long - If anAnimationDesc.animBlock > 0 AndAlso anAnimationDesc.animblockIkRuleOffset = 0 Then 'Return 0 Else @@ -1933,15 +1889,15 @@ Public Class SourceMdlFile53 Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.theIkRules alignment") - 'If fileOffsetOfLastEndOfIkRuleExtraData > 0 Then - ' Return fileOffsetOfLastEndOfIkRuleExtraData - 'Else - ' Return Me.theInputFileReader.BaseStream.Position - 1 - 'End If + If fileOffsetOfLastEndOfIkRuleExtraData > 0 Then + Return fileOffsetOfLastEndOfIkRuleExtraData + Else + Return Me.theInputFileReader.BaseStream.Position - 1 + End If End If - End Sub + End Function - Private Function ReadCompressedIkErrors(ByVal ikRuleInputFileStreamPosition As Long, ByVal ikRuleIndex As Integer, ByVal anAnimationDesc As SourceMdlAnimationDesc52) As Long + Private Function ReadCompressedIkErrors(ByVal ikRuleInputFileStreamPosition As Long, ByVal ikRuleIndex As Integer, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long Dim anIkRule As SourceMdlIkRule anIkRule = anAnimationDesc.theIkRules(ikRuleIndex) @@ -2002,7 +1958,7 @@ Public Class SourceMdlFile53 Return Me.theInputFileReader.BaseStream.Position - 1 End Function - Protected Sub ReadMdlAnimationSection(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal aFileSeekLog As FileSeekLog) + Protected Sub ReadMdlAnimationSection(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal aFileSeekLog As FileSeekLog) 'Dim animSectionInputFileStreamPosition As Long 'Dim inputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -2010,24 +1966,41 @@ Public Class SourceMdlFile53 'Dim fileOffsetStart2 As Long 'Dim fileOffsetEnd2 As Long - fileOffsetStart = animInputFileStreamPosition + Try + fileOffsetStart = animInputFileStreamPosition - 'animSectionInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + 'animSectionInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim anAnimSection As New SourceMdlAnimationSection() - anAnimSection.animBlock = Me.theInputFileReader.ReadInt32() - anAnimSection.animOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.theSections.Add(anAnimSection) + Dim anAnimSection As New SourceMdlAnimationSection() + anAnimSection.animBlock = Me.theInputFileReader.ReadInt32() + anAnimSection.animOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.theSections.Add(anAnimSection) - 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theSections") + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + 'aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimSection [" + anAnimationDesc.theName + "] [animBlock = " + anAnimSection.animBlock.ToString() + "] [calculated ANI file Offset = " + (Me.theMdlFileData.theAnimBlocks(anAnimSection.animBlock).dataStart + anAnimSection.animOffset).ToString() + "]") + If Me.theMdlFileData.theAnimBlocks Is Nothing Then + aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimSection [" + anAnimationDesc.theName + "] [animBlock = " + anAnimSection.animBlock.ToString() + "]") + Else + Dim animBlock As Integer + Dim description As String + animBlock = anAnimSection.animBlock + If animBlock = 0 Then + description = "MDL" + Else + description = "ANI" + End If + aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimSection [" + anAnimationDesc.theName + "] [animBlock = " + animBlock.ToString() + "] [calculated " + description + " file Offset = " + (Me.theMdlFileData.theAnimBlocks(animBlock).dataStart + anAnimSection.animOffset).ToString() + "]") + End If + Catch ex As Exception + Dim debug As Integer = 4242 + End Try End Sub - Protected Sub ReadMdlMovements(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Function ReadMdlMovements(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long If anAnimationDesc.movementCount > 0 Then Dim movementInputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -2060,11 +2033,15 @@ Public Class SourceMdlFile53 Next fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theMovements") + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theMovements " + anAnimationDesc.theMovements.Count.ToString()) + + Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.theMovements alignment") + + Return Me.theInputFileReader.BaseStream.Position - 1 End If - End Sub + End Function - Protected Sub ReadLocalHierarchies(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Sub ReadLocalHierarchies(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) If anAnimationDesc.localHierarchyCount > 0 Then Dim localHieararchyInputFileStreamPosition As Long Dim fileOffsetStart As Long diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb new file mode 100644 index 0000000..2257ab2 --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb @@ -0,0 +1,72 @@ +Imports System.Runtime.InteropServices + +Public Class SourceMdlAnimation53 + + 'FROM: SourceEngineXXXX_source\public\studio.h + '// per bone per animation DOF and weight pointers + 'struct mstudioanim_t + '{ + ' DECLARE_BYTESWAP_DATADESC(); + ' byte bone; + ' byte flags; // weighing options + + ' // valid for animating data only + ' inline byte *pData( void ) const { return (((byte *)this) + sizeof( struct mstudioanim_t )); }; + ' inline mstudioanim_valueptr_t *pRotV( void ) const { return (mstudioanim_valueptr_t *)(pData()); }; + ' inline mstudioanim_valueptr_t *pPosV( void ) const { return (mstudioanim_valueptr_t *)(pData()) + ((flags & STUDIO_ANIM_ANIMROT) != 0); }; + + ' // valid if animation unvaring over timeline + ' inline Quaternion48 *pQuat48( void ) const { return (Quaternion48 *)(pData()); }; + ' inline Quaternion64 *pQuat64( void ) const { return (Quaternion64 *)(pData()); }; + ' inline Vector48 *pPos( void ) const { return (Vector48 *)(pData() + ((flags & STUDIO_ANIM_RAWROT) != 0) * sizeof( *pQuat48() ) + ((flags & STUDIO_ANIM_RAWROT2) != 0) * sizeof( *pQuat64() ) ); }; + + ' short nextoffset; + ' inline mstudioanim_t *pNext( void ) const { if (nextoffset != 0) return (mstudioanim_t *)(((byte *)this) + nextoffset); else return NULL; }; + '}; + + Public translationScale As Single + + ' byte bone; + Public boneIndex As Byte + ' byte flags; // weighing options + Public flags As Byte + + Public unk As Short + + ' if (flags & STUDIO_ANIM_RAWROT2) <> 0 then this field is filled + Public theRot64bits As SourceQuaternion64bits + ' if (flags & STUDIO_ANIM_RAWPOS) <> 0 then this field is filled + Public thePos As SourceVector48bits + + Public theScale As SourceVector48bits + + ' short nextoffset; + Public nextSourceMdlAnimationOffset As Integer + + + ' Values for the field, flags: + '#define STUDIO_ANIM_RAWPOS 0x01 // Vector48 + '#define STUDIO_ANIM_RAWROT 0x02 // Quaternion48 + '#define STUDIO_ANIM_ANIMPOS 0x04 // mstudioanim_valueptr_t + '#define STUDIO_ANIM_ANIMROT 0x08 // mstudioanim_valueptr_t + '#define STUDIO_ANIM_DELTA 0x10 + '#define STUDIO_ANIM_RAWROT2 0x20 // Quaternion64 + Public Const STUDIO_ANIM_RAWPOS As Integer = &H1 + Public Const STUDIO_ANIM_RAWROT As Integer = &H2 + Public Const STUDIO_ANIM_ANIMPOS As Integer = &H4 + Public Const STUDIO_ANIM_ANIMROT As Integer = &H8 + Public Const STUDIO_ANIM_DELTA As Integer = &H10 + Public Const STUDIO_ANIM_RAWROT2 As Integer = &H20 + + + ' Do not use union, because it will have to rely on size of a .NET Framework data type. + ' _ + 'Public Structure theData + ' Public theRotV As SourceMdlAnimationValuePointer + ' Public thePosV As SourceMdlAnimationValuePointer + ' Public theQuat48 As SourceQuaternion48 + ' Public theQuat64 As SourceQuaternion64 + ' Public thePosV2 As SourceMdlAnimationValuePointer + 'End Structure + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb new file mode 100644 index 0000000..35a3fd7 --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb @@ -0,0 +1,201 @@ +Public Class SourceMdlAnimationDesc53 + Inherits SourceMdlAnimationDescBase + + Public Sub New() + Me.theLinkedSequences = New List(Of SourceMdlSequenceDesc)() + End Sub + + 'FROM: AlienSwarm_source\src\public\studio.h + 'struct mstudioanimdesc_t + '{ + ' DECLARE_BYTESWAP_DATADESC(); + ' int baseptr; + ' inline studiohdr_t *pStudiohdr( void ) const { return (studiohdr_t *)(((byte *)this) + baseptr); } + ' + ' int sznameindex; + ' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; } + ' + ' float fps; // frames per second + ' int flags; // looping/non-looping flags + ' + ' int numframes; + ' + ' // piecewise movement + ' int nummovements; + ' int movementindex; + ' inline mstudiomovement_t * const pMovement( int i ) const { return (mstudiomovement_t *)(((byte *)this) + movementindex) + i; }; + ' + ' int ikrulezeroframeindex; + ' mstudioikrulezeroframe_t *pIKRuleZeroFrame( int i ) const { if (ikrulezeroframeindex) return (mstudioikrulezeroframe_t *)(((byte *)this) + ikrulezeroframeindex) + i; else return NULL; }; + ' + ' int unused1[5]; // remove as appropriate (and zero if loading older versions) + ' + ' int animblock; + ' int animindex; // non-zero when anim data isn't in sections + ' byte *pAnimBlock( int block, int index ) const; // returns pointer to a specific anim block (local or external) + ' byte *pAnim( int *piFrame, float &flStall ) const; // returns pointer to data and new frame index + ' byte *pAnim( int *piFrame ) const; // returns pointer to data and new frame index + ' + ' int numikrules; + ' int ikruleindex; // non-zero when IK rule is stored in the mdl + ' int animblockikruleindex; // non-zero when IK data is stored in animblock file + ' mstudioikrule_t *pIKRule( int i ) const; + ' + ' int numlocalhierarchy; + ' int localhierarchyindex; + ' mstudiolocalhierarchy_t *pHierarchy( int i ) const; + ' + ' int sectionindex; + ' int sectionframes; // number of frames used in each fast lookup section, zero if not used + ' inline mstudioanimsections_t * const pSection( int i ) const { return (mstudioanimsections_t *)(((byte *)this) + sectionindex) + i; } + ' + ' short zeroframespan; // frames per span + ' short zeroframecount; // number of spans + ' int zeroframeindex; + ' byte *pZeroFrameData( ) const { if (zeroframeindex) return (((byte *)this) + zeroframeindex); else return NULL; }; + ' mutable float zeroframestalltime; // saved during read stalls + ' + ' mstudioanimdesc_t(){} + 'private: + ' // No copy constructors allowed + ' mstudioanimdesc_t(const mstudioanimdesc_t& vOther); + '}; + + 'NOTE: Size of this struct: 100 bytes. + + ' int baseptr; + ' inline studiohdr_t *pStudiohdr( void ) const { return (studiohdr_t *)(((byte *)this) + baseptr); } + Public baseHeaderOffset As Integer + + ' int sznameindex; + Public nameOffset As Integer + + ' float fps; // frames per second + Public fps As Single + ' int flags; // looping/non-looping flags + Public flags As Integer + + ' int numframes; + Public frameCount As Integer + + ' // piecewise movement + ' int nummovements; + Public movementCount As Integer + ' int movementindex; + Public movementOffset As Integer + ' inline mstudiomovement_t * const pMovement( int i ) const { return (mstudiomovement_t *)(((byte *)this) + movementindex) + i; }; + + ' int ikrulezeroframeindex; + ' mstudioikrulezeroframe_t *pIKRuleZeroFrame( int i ) const { if (ikrulezeroframeindex) return (mstudioikrulezeroframe_t *)(((byte *)this) + ikrulezeroframeindex) + i; else return NULL; }; + 'Public ikRuleZeroFrameOffset As Integer + + ' int animblock; + Public animBlock As Integer + ' int animindex; // non-zero when anim data isn't in sections + Public animOffset As Integer + ' mstudioanim_t *pAnimBlock( int block, int index ) const; // returns pointer to a specific anim block (local or external) + ' mstudioanim_t *pAnim( int *piFrame, float &flStall ) const; // returns pointer to data and new frame index + ' mstudioanim_t *pAnim( int *piFrame ) const; // returns pointer to data and new frame index + + ' int numikrules; + Public ikRuleCount As Integer + ' int ikruleindex; // non-zero when IK data is stored in the mdl + Public ikRuleOffset As Integer + ' int animblockikruleindex; // non-zero when IK data is stored in animblock file + Public animblockIkRuleOffset As Integer + ' mstudioikrule_t *pIKRule( int i ) const; + + ' int numlocalhierarchy; + Public localHierarchyCount As Integer + ' int localhierarchyindex; + Public localHierarchyOffset As Integer + ' mstudiolocalhierarchy_t *pHierarchy( int i ) const; + + ' int sectionindex; + Public sectionOffset As Integer + ' int sectionframes; // number of frames used in each fast lookup section, zero if not used + Public sectionFrameCount As Integer + ' inline mstudioanimsections_t * const pSection( int i ) const { return (mstudioanimsections_t *)(((byte *)this) + sectionindex) + i; } + + ' short zeroframespan; // frames per span + Public spanFrameCount As Short + ' short zeroframecount; // number of spans + Public spanCount As Short + ' int zeroframeindex; + Public spanOffset As Integer + ' byte *pZeroFrameData( ) const { if (zeroframeindex) return (((byte *)this) + zeroframeindex); else return NULL; }; + ' mutable float zeroframestalltime; // saved during read stalls + Public spanStallTime As Single + + ' int unused1[5]; // remove as appropriate (and zero if loading older versions) + Public unused1(3) As Integer + + ' Moved to SourceMdlAnimationDescBase + '' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; } + 'Public theName As String + + Public theSectionsOfAnimations As List(Of List(Of SourceMdlAnimation53)) + Public theSectionsOfFrameAnim As List(Of SourceAniFrameAnim52) + Public theIkRules As List(Of SourceMdlIkRule) + Public theSections As List(Of SourceMdlAnimationSection) + Public theMovements As List(Of SourceMdlMovement) + Public theLocalHierarchies As List(Of SourceMdlLocalHierarchy) + + Public theAnimIsLinkedToSequence As Boolean + Public theLinkedSequences As List(Of SourceMdlSequenceDesc) + Public theOffsetStart As Long + + + + ' Values for the field, flags: + 'FROM: SourceEngineXXXX_source\public\studio.h + '// sequence and autolayer flags + '#define STUDIO_LOOPING 0x0001 // ending frame should be the same as the starting frame + '#define STUDIO_SNAP 0x0002 // do not interpolate between previous animation and this one + '#define STUDIO_DELTA 0x0004 // this sequence "adds" to the base sequences, not slerp blends + '#define STUDIO_AUTOPLAY 0x0008 // temporary flag that forces the sequence to always play + '#define STUDIO_POST 0x0010 // + '#define STUDIO_ALLZEROS 0x0020 // this animation/sequence has no real animation data + '// 0x0040 + '#define STUDIO_CYCLEPOSE 0x0080 // cycle index is taken from a pose parameter index + '#define STUDIO_REALTIME 0x0100 // cycle index is taken from a real-time clock, not the animations cycle index + '#define STUDIO_LOCAL 0x0200 // sequence has a local context sequence + '#define STUDIO_HIDDEN 0x0400 // don't show in default selection views + '#define STUDIO_OVERRIDE 0x0800 // a forward declared sequence (empty) + '#define STUDIO_ACTIVITY 0x1000 // Has been updated at runtime to activity index + '#define STUDIO_EVENT 0x2000 // Has been updated at runtime to event index + '#define STUDIO_WORLD 0x4000 // sequence blends in worldspace + '------ + 'VERSION 49 + 'FROM: AlienSwarm_source\src\public\studio.h + ' Adds these to the above. + '#define STUDIO_FRAMEANIM 0x0040 // animation is encoded as by frame x bone instead of RLE bone x frame + '#define STUDIO_NOFORCELOOP 0x8000 // do not force the animation loop + '#define STUDIO_EVENT_CLIENT 0x10000 // Has been updated at runtime to event index on client + + + Public Const STUDIO_LOOPING As Integer = &H1 + Public Const STUDIO_SNAP As Integer = &H2 + Public Const STUDIO_DELTA As Integer = &H4 + Public Const STUDIO_AUTOPLAY As Integer = &H8 + Public Const STUDIO_POST As Integer = &H10 + Public Const STUDIO_ALLZEROS As Integer = &H20 + ' &H40 + Public Const STUDIO_CYCLEPOSE As Integer = &H80 + Public Const STUDIO_REALTIME As Integer = &H100 + 'NOTE: STUDIO_LOCAL used internally by studiomdl and not needed by Crowbar. + Public Const STUDIO_LOCAL As Integer = &H200 + Public Const STUDIO_HIDDEN As Integer = &H400 + Public Const STUDIO_OVERRIDE As Integer = &H800 + 'NOTE: STUDIO_ACTIVITY used internally by game engine and not needed by Crowbar. + Public Const STUDIO_ACTIVITY As Integer = &H1000 + 'NOTE: STUDIO_EVENT used internally by game engine and not needed by Crowbar. + Public Const STUDIO_EVENT As Integer = &H2000 + Public Const STUDIO_WORLD As Integer = &H4000 + '------ + 'VERSION 49 + Public Const STUDIO_FRAMEANIM As Integer = &H40 + Public Const STUDIO_NOFORCELOOP As Integer = &H8000 + Public Const STUDIO_EVENT_CLIENT As Integer = &H10000 + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index 1e80b83..16923de 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -569,7 +569,7 @@ 'Public theName As String Public theNameCopy As String - Public theAnimationDescs As List(Of SourceMdlAnimationDesc52) + Public theAnimationDescs As List(Of SourceMdlAnimationDesc53) Public theAnimBlocks As List(Of SourceMdlAnimBlock) Public theAnimBlockRelativePathFileName As String Public theAttachments As List(Of SourceMdlAttachment) @@ -606,7 +606,7 @@ 'Public theUpperEyelidFlexFrameIndexes As List(Of Integer) Public theBoneNameToBoneIndexMap As New SortedList(Of String, Integer)() - Public theFirstAnimationDesc As SourceMdlAnimationDesc52 + Public theFirstAnimationDesc As SourceMdlAnimationDesc53 Public theFirstAnimationDescFrameLines As SortedList(Of Integer, AnimationFrameLine) 'Public theMdlFileOnlyHasAnimations As Boolean Public theProceduralBonesCommandIsUsed As Boolean diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index 96f93a7..41b552d 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -191,7 +191,7 @@ Public Class SourceModel53 Public Overrides Function WriteBoneAnimationSmdFiles(ByVal modelOutputPath As String) As AppEnums.StatusMessage Dim status As AppEnums.StatusMessage = StatusMessage.Success - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 Dim smdPath As String 'Dim smdFileName As String Dim smdPathFileName As String diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 09db800..8e78fb7 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -2104,7 +2104,7 @@ Public Class SourceQcFile53 Private Sub WriteAnimationOrDeclareAnimationCommand() If Me.theMdlFileData.theAnimationDescs IsNot Nothing Then For i As Integer = 0 To Me.theMdlFileData.theAnimationDescs.Count - 1 - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 anAnimationDesc = Me.theMdlFileData.theAnimationDescs(i) If anAnimationDesc.theName(0) <> "@" Then @@ -2114,7 +2114,7 @@ Public Class SourceQcFile53 End If End Sub - Private Sub WriteAnimationLine(ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Private Sub WriteAnimationLine(ByVal anAnimationDesc As SourceMdlAnimationDesc53) Dim line As String = "" Me.theOutputFileStreamWriter.WriteLine() @@ -2242,9 +2242,9 @@ Public Class SourceQcFile53 Private Sub WriteSequenceOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc) Dim line As String = "" Dim valueString As String - Dim impliedAnimDesc As SourceMdlAnimationDesc52 = Nothing + Dim impliedAnimDesc As SourceMdlAnimationDesc53 = Nothing - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 Dim name As String For j As Integer = 0 To aSequenceDesc.theAnimDescIndexes.Count - 1 anAnimationDesc = Me.theMdlFileData.theAnimationDescs(aSequenceDesc.theAnimDescIndexes(j)) @@ -2405,7 +2405,7 @@ Public Class SourceQcFile53 ' Me.theOutputFileStreamWriter.WriteLine(line) 'End If - Dim firstAnimDesc As SourceMdlAnimationDesc52 + Dim firstAnimDesc As SourceMdlAnimationDesc53 firstAnimDesc = Me.theMdlFileData.theAnimationDescs(aSequenceDesc.theAnimDescIndexes(0)) Me.WriteAnimationOptions(aSequenceDesc, firstAnimDesc, impliedAnimDesc) End Sub @@ -2432,7 +2432,7 @@ Public Class SourceQcFile53 'ParseCmdlistToken( panim->numcmds, panim->cmds ) 'TODO: All these options (LX, LY, etc.) seem to be baked-in, but might need to be calculated for anims that have movement. 'lookupControl( token ) - Private Sub WriteAnimationOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal impliedAnimDesc As SourceMdlAnimationDesc52) + Private Sub WriteAnimationOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal impliedAnimDesc As SourceMdlAnimationDesc53) Dim line As String = "" line = vbTab @@ -2484,7 +2484,7 @@ Public Class SourceQcFile53 'weightlist // done 'worldspaceblend // 'worldspaceblendloop // - Private Sub WriteCmdListOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal impliedAnimDesc As SourceMdlAnimationDesc52) + Private Sub WriteCmdListOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal impliedAnimDesc As SourceMdlAnimationDesc53) Dim line As String = "" If anAnimationDesc.theIkRules IsNot Nothing Then @@ -2760,7 +2760,7 @@ Public Class SourceQcFile53 End If End Sub - Private Sub WriteCmdListLocalHierarchyOption(ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Private Sub WriteCmdListLocalHierarchyOption(ByVal anAnimationDesc As SourceMdlAnimationDesc53) Dim line As String = "" If anAnimationDesc.theLocalHierarchies IsNot Nothing Then diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 99f0c8f..c565a1d 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -51,7 +51,13 @@ Public Class SourceSmdFile53 Else boneCount = Me.theMdlFileData.theBones.Count End If - For boneIndex As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 + For boneIndex As Integer = 0 To boneCount - 1 + 'Dim aBone As SourceMdlBone + 'aBone = Me.theMdlFileData.theBones(boneIndex) + 'If lodIndex = -2 AndAlso aBone.proceduralRuleOffset <> 0 AndAlso aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_JIGGLE Then + ' Continue For + 'End If + name = Me.theMdlFileData.theBones(boneIndex).theName line = " " @@ -69,6 +75,7 @@ Public Class SourceSmdFile53 Public Sub WriteSkeletonSection(ByVal lodIndex As Integer) Dim line As String = "" + Dim aBone As SourceMdlBone53 'skeleton line = "skeleton" @@ -81,20 +88,22 @@ Public Class SourceSmdFile53 End If Me.theOutputFileStreamWriter.WriteLine(line) For boneIndex As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 + aBone = Me.theMdlFileData.theBones(boneIndex) + line = " " line += boneIndex.ToString(TheApp.InternalNumberFormat) line += " " - line += Me.theMdlFileData.theBones(boneIndex).position.x.ToString("0.000000", TheApp.InternalNumberFormat) + line += aBone.position.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += Me.theMdlFileData.theBones(boneIndex).position.y.ToString("0.000000", TheApp.InternalNumberFormat) + line += aBone.position.y.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += Me.theMdlFileData.theBones(boneIndex).position.z.ToString("0.000000", TheApp.InternalNumberFormat) + line += aBone.position.z.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += Me.theMdlFileData.theBones(boneIndex).rotation.x.ToString("0.000000", TheApp.InternalNumberFormat) + line += aBone.rotation.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += Me.theMdlFileData.theBones(boneIndex).rotation.y.ToString("0.000000", TheApp.InternalNumberFormat) + line += aBone.rotation.y.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += Me.theMdlFileData.theBones(boneIndex).rotation.z.ToString("0.000000", TheApp.InternalNumberFormat) + line += aBone.rotation.z.ToString("0.000000", TheApp.InternalNumberFormat) Me.theOutputFileStreamWriter.WriteLine(line) Next @@ -201,12 +210,10 @@ Public Class SourceSmdFile53 Dim collisionData As SourcePhyCollisionData Dim aBone As SourceMdlBone53 - Dim boneIndex As Integer Dim aTriangle As SourcePhyFace - Dim convexMesh As SourcePhyConvexMesh + Dim faceSection As SourcePhyConvexMesh Dim phyVertex As SourcePhyVertex Dim aVectorTransformed As SourceVector - Dim aSourcePhysCollisionModel As SourcePhyPhysCollisionModel Try If Me.thePhyFileData.theSourcePhyCollisionDatas IsNot Nothing Then @@ -215,62 +222,29 @@ Public Class SourceSmdFile53 For collisionDataIndex As Integer = 0 To Me.thePhyFileData.theSourcePhyCollisionDatas.Count - 1 collisionData = Me.thePhyFileData.theSourcePhyCollisionDatas(collisionDataIndex) - If collisionDataIndex < Me.thePhyFileData.theSourcePhyPhysCollisionModels.Count Then - aSourcePhysCollisionModel = Me.thePhyFileData.theSourcePhyPhysCollisionModels(collisionDataIndex) - Else - aSourcePhysCollisionModel = Nothing - End If - - For convexMeshIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 - convexMesh = collisionData.theConvexMeshes(convexMeshIndex) + For faceSectionIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 + faceSection = collisionData.theConvexMeshes(faceSectionIndex) - ' [12-Apr-2022] From RED_EYE. (He is using someone else's set of data strutures for PHY file.) - ' flags: has_children: (self.flags >> 0) & 3 ' 0 = false; > 0 true - ' This seems to be correct way rather than checking Me.thePhyFileData.theSourcePhyIsCollisionModel. - ' Example where checking Me.thePhyFileData.theSourcePhyIsCollisionModel is incorrect (because the gib meshes are compiled in): - ' "SourceFilmmaker\game\hl2\models\combine_strider.mdl" - If (convexMesh.flags And 3) > 0 Then + If faceSection.theBoneIndex >= Me.theMdlFileData.theBones.Count Then Continue For End If + aBone = Me.theMdlFileData.theBones(faceSection.theBoneIndex) - If Me.theMdlFileData.theBones.Count = 1 Then - boneIndex = 0 - Else - boneIndex = convexMesh.theBoneIndex - ' MDL36 and MDL37 need this because their PHY does not store bone index. - ' Model versions above MDL37 can have multiple bones with same name, so this check needs to be last. - If boneIndex < 0 Then - If aSourcePhysCollisionModel IsNot Nothing AndAlso Me.theMdlFileData.theBoneNameToBoneIndexMap.ContainsKey(aSourcePhysCollisionModel.theName) Then - boneIndex = Me.theMdlFileData.theBoneNameToBoneIndexMap(aSourcePhysCollisionModel.theName) - Else - ' Not expected to reach here, but just in case, write a mesh connected to first bone instead of writing an empty mesh. - boneIndex = 0 - End If - End If - End If - aBone = Me.theMdlFileData.theBones(boneIndex) - - For triangleIndex As Integer = 0 To convexMesh.theFaces.Count - 1 - aTriangle = convexMesh.theFaces(triangleIndex) + For triangleIndex As Integer = 0 To faceSection.theFaces.Count - 1 + aTriangle = faceSection.theFaces(triangleIndex) line = " phy" Me.theOutputFileStreamWriter.WriteLine(line) ' 19 -0.000009 0.000001 0.999953 0.0 0.0 0.0 1 0 - ' 19 -0.000005 1.000002 -0.000043 0.0 0.0 0.0 1 0 - ' 19 -0.008333 0.997005 1.003710 0.0 0.0 0.0 1 0 For vertexIndex As Integer = 0 To aTriangle.vertexIndex.Length - 1 'phyVertex = collisionData.theVertices(aTriangle.vertexIndex(vertexIndex)) - phyVertex = convexMesh.theVertices(aTriangle.vertexIndex(vertexIndex)) - - aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex, aSourcePhysCollisionModel) + phyVertex = faceSection.theVertices(aTriangle.vertexIndex(vertexIndex)) - ''DEBUG: Move different face sections away from each other. - 'aVectorTransformed.x += faceSectionIndex * 20 - 'aVectorTransformed.y += faceSectionIndex * 20 + aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex) line = " " - line += boneIndex.ToString(TheApp.InternalNumberFormat) + line += faceSection.theBoneIndex.ToString(TheApp.InternalNumberFormat) line += " " line += aVectorTransformed.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " @@ -278,8 +252,6 @@ Public Class SourceSmdFile53 line += " " line += aVectorTransformed.z.ToString("0.000000", TheApp.InternalNumberFormat) - 'line += " 0 0 0" - '------ line += " " line += phyVertex.Normal.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " @@ -310,7 +282,7 @@ Public Class SourceSmdFile53 Dim aFrameLine As AnimationFrameLine Dim frameIndex As Integer Dim aSequenceDesc As SourceMdlSequenceDesc - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 aSequenceDesc = Nothing anAnimationDesc = Me.theMdlFileData.theFirstAnimationDesc @@ -370,10 +342,14 @@ Public Class SourceSmdFile53 Dim rotation As New SourceVector() 'Dim tempRotation As New SourceVector() Dim aSequenceDesc As SourceMdlSequenceDesc - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 + 'Dim beforeMovementFrameRotation As New SourceVector() + 'Dim previousFrameRotation As New SourceVector() + 'Dim beforeMovementFramePosition As New SourceVector() + 'Dim previousFramePosition As New SourceVector() aSequenceDesc = CType(aSequenceDescBase, SourceMdlSequenceDesc) - anAnimationDesc = CType(anAnimationDescBase, SourceMdlAnimationDesc52) + anAnimationDesc = CType(anAnimationDescBase, SourceMdlAnimationDesc53) 'skeleton line = "skeleton" @@ -661,54 +637,8 @@ Public Class SourceSmdFile53 End If End Sub - Private Sub CalculateFirstAnimDescFrameLinesForPhysics(ByRef aFirstAnimationDescFrameLine As AnimationFrameLine) - Dim boneIndex As Integer - Dim aFrameLine As AnimationFrameLine - Dim frameIndex As Integer - Dim frameLineIndex As Integer - Dim aSequenceDesc As SourceMdlSequenceDesc - Dim anAnimationDesc As SourceMdlAnimationDesc52 - - aSequenceDesc = Nothing - anAnimationDesc = Me.theMdlFileData.theAnimationDescs(0) - - Me.theAnimationFrameLines = New SortedList(Of Integer, AnimationFrameLine)() - frameIndex = 0 - Me.theAnimationFrameLines.Clear() - 'If (anAnimationDesc.flags And SourceMdlAnimationDesc.STUDIO_ALLZEROS) = 0 Then - Me.CalcAnimation(aSequenceDesc, anAnimationDesc, frameIndex) - 'End If - - frameLineIndex = 0 - boneIndex = Me.theAnimationFrameLines.Keys(frameLineIndex) - aFrameLine = Me.theAnimationFrameLines.Values(frameLineIndex) + Private Sub AdjustPositionAndRotationForDelta(ByVal iPosition As SourceVector, ByVal iRotation As SourceVector, ByRef oPosition As SourceVector, ByRef oRotation As SourceVector) - aFirstAnimationDescFrameLine.rotation = New SourceVector() - aFirstAnimationDescFrameLine.position = New SourceVector() - - aFirstAnimationDescFrameLine.rotation.x = aFrameLine.rotation.x - aFirstAnimationDescFrameLine.rotation.y = aFrameLine.rotation.y - 'If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then - ' Dim z As Double - ' z = aFrameLine.rotation.z - ' z += MathModule.DegreesToRadians(-90) - ' aFirstAnimationDescFrameLine.rotation.z = z - 'Else - aFirstAnimationDescFrameLine.rotation.z = aFrameLine.rotation.z - 'End If - - ''NOTE: Only adjust position if bone is a root bone. Do not know why. - ''If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then - ''TEST: Try this version, because of "sequence_blend from Game Zombie" model. - 'If Me.theMdlFileData.theBones(boneIndex).parentBoneIndex = -1 AndAlso (aFrameLine.position.debug_text.StartsWith("raw") OrElse aFrameLine.rotation.debug_text = "anim+bone") Then - ' aFirstAnimationDescFrameLine.position.x = aFrameLine.position.y - ' aFirstAnimationDescFrameLine.position.y = (-aFrameLine.position.x) - ' aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z - 'Else - aFirstAnimationDescFrameLine.position.x = aFrameLine.position.x - aFirstAnimationDescFrameLine.position.y = aFrameLine.position.y - aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z - 'End If End Sub Private Function WriteVertexLine(ByVal aStripGroup As SourceVtxStripGroup07, ByVal aVtxIndexIndex As Integer, ByVal lodIndex As Integer, ByVal meshVertexIndexStart As Integer, ByVal bodyPartVertexIndexStart As Integer) As String @@ -786,6 +716,56 @@ Public Class SourceSmdFile53 Return line End Function + Private Sub CalculateFirstAnimDescFrameLinesForPhysics(ByRef aFirstAnimationDescFrameLine As AnimationFrameLine) + Dim boneIndex As Integer + Dim aFrameLine As AnimationFrameLine + Dim frameIndex As Integer + Dim frameLineIndex As Integer + Dim aSequenceDesc As SourceMdlSequenceDesc + Dim anAnimationDesc As SourceMdlAnimationDesc53 + + aSequenceDesc = Nothing + anAnimationDesc = Me.theMdlFileData.theAnimationDescs(0) + + Me.theAnimationFrameLines = New SortedList(Of Integer, AnimationFrameLine)() + frameIndex = 0 + Me.theAnimationFrameLines.Clear() + 'If (anAnimationDesc.flags And SourceMdlAnimationDesc.STUDIO_ALLZEROS) = 0 Then + Me.CalcAnimation(aSequenceDesc, anAnimationDesc, frameIndex) + 'End If + + frameLineIndex = 0 + boneIndex = Me.theAnimationFrameLines.Keys(frameLineIndex) + aFrameLine = Me.theAnimationFrameLines.Values(frameLineIndex) + + aFirstAnimationDescFrameLine.rotation = New SourceVector() + aFirstAnimationDescFrameLine.position = New SourceVector() + + aFirstAnimationDescFrameLine.rotation.x = aFrameLine.rotation.x + aFirstAnimationDescFrameLine.rotation.y = aFrameLine.rotation.y + 'If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then + ' Dim z As Double + ' z = aFrameLine.rotation.z + ' z += MathModule.DegreesToRadians(-90) + ' aFirstAnimationDescFrameLine.rotation.z = z + 'Else + aFirstAnimationDescFrameLine.rotation.z = aFrameLine.rotation.z + 'End If + + ''NOTE: Only adjust position if bone is a root bone. Do not know why. + ''If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then + ''TEST: Try this version, because of "sequence_blend from Game Zombie" model. + 'If Me.theMdlFileData.theBones(boneIndex).parentBoneIndex = -1 AndAlso (aFrameLine.position.debug_text.StartsWith("raw") OrElse aFrameLine.rotation.debug_text = "anim+bone") Then + ' aFirstAnimationDescFrameLine.position.x = aFrameLine.position.y + ' aFirstAnimationDescFrameLine.position.y = (-aFrameLine.position.x) + ' aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z + 'Else + aFirstAnimationDescFrameLine.position.x = aFrameLine.position.x + aFirstAnimationDescFrameLine.position.y = aFrameLine.position.y + aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z + 'End If + End Sub + Private Sub ProcessTransformsForPhysics() If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then Dim aFirstAnimationDescFrameLine As New AnimationFrameLine() @@ -816,7 +796,19 @@ Public Class SourceSmdFile53 End If End Sub - Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone53, ByVal vertex As SourceVector, ByVal aSourcePhysCollisionModel As SourcePhyPhysCollisionModel) As SourceVector + 'NOTE: From disassembling of MDL Decompiler with OllyDbg, the following calculations are used in VPHYSICS.DLL for each face: + ' convertedZ = 1.0 / 0.0254 * lastVertex.position.z + ' convertedY = 1.0 / 0.0254 * -lastVertex.position.y + ' convertedX = 1.0 / 0.0254 * lastVertex.position.x + 'NOTE: From disassembling of MDL Decompiler with OllyDbg, the following calculations are used after above for each vertex: + ' newValue1 = unknownZ1 * convertedZ + unknownY1 * convertedY + unknownX1 * convertedX + unknownW1 + ' newValue2 = unknownZ2 * convertedZ + unknownY2 * convertedY + unknownX2 * convertedX + unknownW2 + ' newValue3 = unknownZ3 * convertedZ + unknownY3 * convertedY + unknownX3 * convertedX + unknownW3 + 'Seems to be same as this code: + 'Dim aBone As SourceMdlBone + 'aBone = Me.theSourceEngineModel.theMdlFileHeader.theBones(anEyeball.boneIndex) + 'eyeballPosition = MathModule.VectorITransform(anEyeball.org, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone53, ByVal vertex As SourceVector) As SourceVector Dim aVectorTransformed As New SourceVector Dim aVector As New SourceVector() @@ -897,270 +889,253 @@ Public Class SourceSmdFile53 ' aVectorTransformed.y = 1 / 0.0254 * -vertex.x ' aVectorTransformed.z = 1 / 0.0254 * -vertex.y 'Else - ' 'NOTE: Correct: - ' ' Team Fortress 2\tf2_misc_dir\models\player\demo.mdl ' aVector.x = 1 / 0.0254 * vertex.x ' aVector.y = 1 / 0.0254 * vertex.z ' aVector.z = 1 / 0.0254 * -vertex.y ' aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) 'End If '------ - 'TODO: [TransformPhyVertex] Merge the various code blocks (separated by MDL version) into one code block. - If Me.theMdlFileData.version >= 44 AndAlso Me.theMdlFileData.version <= 47 Then - ' This works for various weapons and vehicles in HL2. - If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then - aVectorTransformed.x = 1 / 0.0254 * vertex.z - aVectorTransformed.y = 1 / 0.0254 * -vertex.x - aVectorTransformed.z = 1 / 0.0254 * -vertex.y - Else - aVector.x = 1 / 0.0254 * vertex.x - aVector.y = 1 / 0.0254 * vertex.z - aVector.z = 1 / 0.0254 * -vertex.y - aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - End If - Else - If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then - 'Dim copyOfVector As New SourceVector() - ''copyOfVector.x = 1 / 0.0254 * vertex.x - ''copyOfVector.y = 1 / 0.0254 * vertex.y - ''copyOfVector.z = 1 / 0.0254 * vertex.z - ''copyOfVector.x = 1 / 0.0254 * vertex.x - ''copyOfVector.y = 1 / 0.0254 * vertex.z - ''copyOfVector.z = 1 / 0.0254 * -vertex.y - 'copyOfVector.x = 1 / 0.0254 * vertex.z - 'copyOfVector.y = 1 / 0.0254 * -vertex.x - 'copyOfVector.z = 1 / 0.0254 * -vertex.y - 'aVector = MathModule.VectorTransform(copyOfVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - ''aVector.x = 1 / 0.0254 * vertex.z - ''aVector.y = 1 / 0.0254 * -vertex.x - ''aVector.z = 1 / 0.0254 * -vertex.y - ''aVectorTransformed.x = 1 / 0.0254 * vertex.z - ''aVectorTransformed.y = 1 / 0.0254 * -vertex.x - ''aVectorTransformed.z = 1 / 0.0254 * -vertex.y - - 'Dim debug As Integer = 4242 - - ''Dim temp As Double - ''temp = aVector.y - ''aVector.y = aVector.z - ''aVector.z = -temp - ''------ - ''aVector.y = -aVector.y - ''------ - ''Dim temp As Double - ''temp = aVector.x - ''aVector.x = aVector.z - ''aVector.z = -aVector.y - ''aVector.y = -temp - ''------ - ''Dim temp As Double - ''temp = aVector.x - ''aVectorTransformed.x = aVector.z - ''aVectorTransformed.z = -aVector.y - ''aVectorTransformed.y = -temp - - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - - '[2017-12-22] - ' Correct for cube_like_mesh - 'aVectorTransformed.x = 1 / 0.0254 * vertex.z - 'aVectorTransformed.y = 1 / 0.0254 * -vertex.x - 'aVectorTransformed.z = 1 / 0.0254 * -vertex.y - '------ - ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl - 'aVectorTransformed.x = 1 / 0.0254 * vertex.z - 'aVectorTransformed.y = 1 / 0.0254 * -vertex.y - 'aVectorTransformed.z = 1 / 0.0254 * vertex.x - '------ - 'aVector.x = 1 / 0.0254 * vertex.z - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.y + If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then + 'Dim copyOfVector As New SourceVector() + ''copyOfVector.x = 1 / 0.0254 * vertex.x + ''copyOfVector.y = 1 / 0.0254 * vertex.y + ''copyOfVector.z = 1 / 0.0254 * vertex.z + ''copyOfVector.x = 1 / 0.0254 * vertex.x + ''copyOfVector.y = 1 / 0.0254 * vertex.z + ''copyOfVector.z = 1 / 0.0254 * -vertex.y + 'copyOfVector.x = 1 / 0.0254 * vertex.z + 'copyOfVector.y = 1 / 0.0254 * -vertex.x + 'copyOfVector.z = 1 / 0.0254 * -vertex.y + 'aVector = MathModule.VectorTransform(copyOfVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + ''aVector.x = 1 / 0.0254 * vertex.z + ''aVector.y = 1 / 0.0254 * -vertex.x + ''aVector.z = 1 / 0.0254 * -vertex.y + ''aVectorTransformed.x = 1 / 0.0254 * vertex.z + ''aVectorTransformed.y = 1 / 0.0254 * -vertex.x + ''aVectorTransformed.z = 1 / 0.0254 * -vertex.y + + 'Dim debug As Integer = 4242 + + ''Dim temp As Double + ''temp = aVector.y + ''aVector.y = aVector.z + ''aVector.z = -temp + ''------ + ''aVector.y = -aVector.y + ''------ + ''Dim temp As Double + ''temp = aVector.x + ''aVector.x = aVector.z + ''aVector.z = -aVector.y + ''aVector.y = -temp + ''------ + ''Dim temp As Double + ''temp = aVector.x + ''aVectorTransformed.x = aVector.z + ''aVectorTransformed.z = -aVector.y + ''aVectorTransformed.y = -temp + + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + + '[2017-12-22] + ' Correct for cube_like_mesh + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.x + 'aVectorTransformed.z = 1 / 0.0254 * -vertex.y + '------ + ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.y + 'aVectorTransformed.z = 1 / 0.0254 * vertex.x + '------ + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * -vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + ' Correct for cube_like_mesh + ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl + ' Incorrect for L4D2 w_models/weapons/w_rifle_m16a2.mdl + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.poseToWorldColumn0, Me.poseToWorldColumn1, Me.poseToWorldColumn2, Me.poseToWorldColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + ''Dim worldToBoneColumn0 As New SourceVector() + ''Dim worldToBoneColumn1 As New SourceVector() + ''Dim worldToBoneColumn2 As New SourceVector() + ''Dim worldToBoneColumn3 As New SourceVector() + ''MathModule.AngleMatrix(aBone.rotation.x, aBone.rotation.y, aBone.rotation.z, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) + ''worldToBoneColumn3.x = aBone.position.x + ''worldToBoneColumn3.y = aBone.position.y + ''worldToBoneColumn3.z = aBone.position.z + ''aVector.x = aVectorTransformed.x + ''aVector.y = aVectorTransformed.y + ''aVector.z = aVectorTransformed.z + ''aVectorTransformed = MathModule.VectorTransform(aVector, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + ' ''NOTE: These 3 lines work for airport_fuel_truck, ambulance, and army_truck, but not w_desert_file and w_rifle_m16a2. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + ' ''NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. + ''aVector.x = 1 / 0.0254 * vertex.x + ''aVector.y = 1 / 0.0254 * -vertex.y + ''aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + ''aVector.x = aVectorTransformed.x + ''aVector.y = aVectorTransformed.z + ''aVector.z = -aVectorTransformed.y + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '====== + 'FROM: collisionmodel.cpp ConvertToWorldSpace() + If (Me.theMdlFileData.flags And SourceMdlFileData.STUDIOHDR_FLAGS_STATIC_PROP) > 0 Then + 'NOTE: These 3 lines do not work for airport_fuel_truck, ambulance, and army_truck. 'aVector.x = 1 / 0.0254 * vertex.x 'aVector.y = 1 / 0.0254 * vertex.z 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.z - 'aVector.z = 1 / 0.0254 * vertex.y - 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * -vertex.y 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y 'aVector.z = 1 / 0.0254 * vertex.z - 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) 'aVector.x = 1 / 0.0254 * vertex.x 'aVector.y = 1 / 0.0254 * vertex.y 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * -vertex.x + 'aVector.x = 1 / 0.0254 * vertex.x 'aVector.y = 1 / 0.0254 * vertex.z 'aVector.z = 1 / 0.0254 * vertex.y - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x + '' Still need a rotate 90 on the z. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.y 'aVector.z = 1 / 0.0254 * vertex.z 'aVector.x = 1 / 0.0254 * -vertex.y 'aVector.y = 1 / 0.0254 * vertex.x 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.z - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.z - ' Correct for cube_like_mesh - ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl - ' Incorrect for L4D2 w_models/weapons/w_rifle_m16a2.mdl - 'aVector.x = 1 / 0.0254 * -vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.z - 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.poseToWorldColumn0, Me.poseToWorldColumn1, Me.poseToWorldColumn2, Me.poseToWorldColumn3) - '====== - ''FROM: collisionmodel.cpp ConvertToWorldSpace() - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - ''Dim worldToBoneColumn0 As New SourceVector() - ''Dim worldToBoneColumn1 As New SourceVector() - ''Dim worldToBoneColumn2 As New SourceVector() - ''Dim worldToBoneColumn3 As New SourceVector() - ''MathModule.AngleMatrix(aBone.rotation.x, aBone.rotation.y, aBone.rotation.z, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) - ''worldToBoneColumn3.x = aBone.position.x - ''worldToBoneColumn3.y = aBone.position.y - ''worldToBoneColumn3.z = aBone.position.z - ''aVector.x = aVectorTransformed.x - ''aVector.y = aVectorTransformed.y - ''aVector.z = aVectorTransformed.z - ''aVectorTransformed = MathModule.VectorTransform(aVector, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) - 'aVector.x = aVectorTransformed.x - 'aVector.y = aVectorTransformed.y - 'aVector.z = aVectorTransformed.z - 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) - '====== - ''FROM: collisionmodel.cpp ConvertToWorldSpace() - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) - 'aVector.x = aVectorTransformed.x - 'aVector.y = aVectorTransformed.y - 'aVector.z = aVectorTransformed.z - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - '====== - ''FROM: collisionmodel.cpp ConvertToWorldSpace() - ' ''NOTE: These 3 lines work for airport_fuel_truck, ambulance, and army_truck, but not w_desert_file and w_rifle_m16a2. 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x 'aVector.z = 1 / 0.0254 * -vertex.y - ' ''NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. - ''aVector.x = 1 / 0.0254 * vertex.x - ''aVector.y = 1 / 0.0254 * -vertex.y - ''aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) 'aVector.x = aVectorTransformed.x 'aVector.y = aVectorTransformed.y 'aVector.z = aVectorTransformed.z - ''aVector.x = aVectorTransformed.x - ''aVector.y = aVectorTransformed.z - ''aVector.z = -aVectorTransformed.y 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - '====== - 'FROM: collisionmodel.cpp ConvertToWorldSpace() - If (Me.theMdlFileData.flags And SourceMdlFileData.STUDIOHDR_FLAGS_STATIC_PROP) > 0 Then - 'NOTE: These 3 lines do not work for airport_fuel_truck, ambulance, and army_truck. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * -vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * vertex.y - '' Still need a rotate 90 on the z. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * -vertex.y - 'aVector.y = 1 / 0.0254 * vertex.x - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.z - 'aVector.z = 1 / 0.0254 * vertex.y - 'aVector.x = 1 / 0.0254 * vertex.z - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.y - - 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - 'aVector.x = aVectorTransformed.x - 'aVector.y = aVectorTransformed.y - 'aVector.z = aVectorTransformed.z - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - '------ + '------ - 'TEST: Works for props_vehciles that use $staticprop. - aVector.x = 1 / 0.0254 * vertex.z - aVector.y = 1 / 0.0254 * -vertex.x - aVector.z = 1 / 0.0254 * -vertex.y - aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - aVector.x = aVectorTransformed.x - aVector.y = aVectorTransformed.z - aVector.z = -aVectorTransformed.y - aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - Else - 'NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. - 'TEST: Did not work for 50_cal. Rotated 180. Original model has phys mesh rotated oddly, anyway. - 'TEST: Incorrect. Need to 180 on the Y and -1 on scale Z. Noticable on w_minigun. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'TEST: Incorrect. Need to 180 on the Y. Noticable on w_minigun. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'TEST: Incorrect. Need to -1 on scale Z. Noticable on w_minigun. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * -vertex.z - 'TEST: Works for w_minigun. - 'TEST: Works for 50cal, but be aware that the phys mesh does not look right for the model. It does look like original model, though. - 'TEST: Does not work for Garry's Mod addon "dodge_daytona" 236224475. - aVector.x = 1 / 0.0254 * vertex.x - aVector.y = 1 / 0.0254 * -vertex.y - aVector.z = 1 / 0.0254 * -vertex.z - - aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - aVector.x = aVectorTransformed.x - aVector.y = aVectorTransformed.y - aVector.z = aVectorTransformed.z - aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - End If + 'TEST: Works for props_vehciles that use $staticprop. + aVector.x = 1 / 0.0254 * vertex.z + aVector.y = 1 / 0.0254 * -vertex.x + aVector.z = 1 / 0.0254 * -vertex.y + aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + aVector.x = aVectorTransformed.x + aVector.y = aVectorTransformed.z + aVector.z = -aVectorTransformed.y + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) Else - 'FROM: collisionmodel.cpp ConvertToBoneSpace() + 'NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. + 'TEST: Did not work for 50_cal. Rotated 180. Original model has phys mesh rotated oddly, anyway. + 'TEST: Incorrect. Need to 180 on the Y and -1 on scale Z. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'TEST: Incorrect. Need to 180 on the Y. Noticable on w_minigun. 'aVector.x = 1 / 0.0254 * vertex.x 'aVector.y = 1 / 0.0254 * vertex.y 'aVector.z = 1 / 0.0254 * vertex.z + 'TEST: Incorrect. Need to -1 on scale Z. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * -vertex.z + 'TEST: Works for w_minigun. + 'TEST: Works for 50cal, but be aware that the phys mesh does not look right for the model. It does look like original model, though. + 'TEST: Does not work for Garry's Mod addon "dodge_daytona" 236224475. aVector.x = 1 / 0.0254 * vertex.x - aVector.y = 1 / 0.0254 * vertex.z - aVector.z = 1 / 0.0254 * -vertex.y + aVector.y = 1 / 0.0254 * -vertex.y + aVector.z = 1 / 0.0254 * -vertex.z + + aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + aVector.x = aVectorTransformed.x + aVector.y = aVectorTransformed.y + aVector.z = aVectorTransformed.z aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) End If + Else + 'FROM: collisionmodel.cpp ConvertToBoneSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + aVector.x = 1 / 0.0254 * vertex.x + aVector.y = 1 / 0.0254 * vertex.z + aVector.z = 1 / 0.0254 * -vertex.y + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) End If 'If Me.theMdlFileData.theBoneTransforms IsNot Nothing Then @@ -1297,12 +1272,198 @@ Public Class SourceSmdFile53 Return aVectorTransformed End Function - Private Sub CalcAnimation(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal frameIndex As Integer) + 'Private Sub CreateAnimationFrameLines(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal frameIndex As Integer) + + 'End Sub + + 'static void CalcAnimation( const CStudioHdr *pStudioHdr, Vector *pos, Quaternion *q, + ' mstudioseqdesc_t &seqdesc, + ' int sequence, int animation, + ' float cycle, int boneMask ) + '{ + ' int i; + ' + ' mstudioanimdesc_t &animdesc = pStudioHdr->pAnimdesc( animation ); + ' mstudiobone_t *pbone = pStudioHdr->pBone( 0 ); + ' mstudioanim_t *panim = animdesc.pAnim( ); + ' + ' int iFrame; + ' float s; + ' + ' float fFrame = cycle * (animdesc.numframes - 1); + ' + ' iFrame = (int)fFrame; + ' s = (fFrame - iFrame); + ' + ' float *pweight = seqdesc.pBoneweight( 0 ); + ' + ' for (i = 0; i < pStudioHdr->numbones(); i++, pbone++, pweight++) + ' { + ' if (panim && panim->bone == i) + ' { + ' if (*pweight > 0 && (pbone->flags & boneMask)) + ' { + ' CalcBoneQuaternion( iFrame, s, pbone, panim, q[i] ); + ' CalcBonePosition ( iFrame, s, pbone, panim, pos[i] ); + ' } + ' panim = panim->pNext(); + ' } + ' else if (*pweight > 0 && (pbone->flags & boneMask)) + ' { + ' if (animdesc.flags & STUDIO_DELTA) + ' { + ' q[i].Init( 0.0f, 0.0f, 0.0f, 1.0f ); + ' pos[i].Init( 0.0f, 0.0f, 0.0f ); + ' } + ' else + ' { + ' q[i] = pbone->quat; + ' pos[i] = pbone->pos; + ' } + ' } + ' } + '} + '====== + 'FROM: SourceEngine2007_source\src_main\public\bone_setup.cpp + '//----------------------------------------------------------------------------- + '// Purpose: Find and decode a sub-frame of animation + '//----------------------------------------------------------------------------- + ' + 'static void CalcAnimation( const CStudioHdr *pStudioHdr, Vector *pos, Quaternion *q, + ' mstudioseqdesc_t &seqdesc, + ' int sequence, int animation, + ' float cycle, int boneMask ) + '{ + '#ifdef STUDIO_ENABLE_PERF_COUNTERS + ' pStudioHdr->m_nPerfAnimationLayers++; + '#endif + ' + ' virtualmodel_t *pVModel = pStudioHdr->GetVirtualModel(); + ' + ' if (pVModel) + ' { + ' CalcVirtualAnimation( pVModel, pStudioHdr, pos, q, seqdesc, sequence, animation, cycle, boneMask ); + ' return; + ' } + ' + ' mstudioanimdesc_t &animdesc = pStudioHdr->pAnimdesc( animation ); + ' mstudiobone_t *pbone = pStudioHdr->pBone( 0 ); + ' const mstudiolinearbone_t *pLinearBones = pStudioHdr->pLinearBones(); + ' + ' int i; + ' int iFrame; + ' float s; + ' + ' float fFrame = cycle * (animdesc.numframes - 1); + ' + ' iFrame = (int)fFrame; + ' s = (fFrame - iFrame); + ' + ' int iLocalFrame = iFrame; + ' float flStall; + ' mstudioanim_t *panim = animdesc.pAnim( &iLocalFrame, flStall ); + ' + ' float *pweight = seqdesc.pBoneweight( 0 ); + ' + ' // if the animation isn't available, look for the zero frame cache + ' if (!panim) + ' { + ' // Msg("zeroframe %s\n", animdesc.pszName() ); + ' // pre initialize + ' for (i = 0; i < pStudioHdr->numbones(); i++, pbone++, pweight++) + ' { + ' if (*pweight > 0 && (pStudioHdr->boneFlags(i) & boneMask)) + ' { + ' if (animdesc.flags & STUDIO_DELTA) + ' { + ' q[i].Init( 0.0f, 0.0f, 0.0f, 1.0f ); + ' pos[i].Init( 0.0f, 0.0f, 0.0f ); + ' } + ' else + ' { + ' q[i] = pbone->quat; + ' pos[i] = pbone->pos; + ' } + ' } + ' } + ' + ' CalcZeroframeData( pStudioHdr, pStudioHdr->GetRenderHdr(), NULL, pStudioHdr->pBone( 0 ), animdesc, fFrame, pos, q, boneMask, 1.0 ); + ' + ' return; + ' } + ' + ' // BUGBUG: the sequence, the anim, and the model can have all different bone mappings. + ' for (i = 0; i < pStudioHdr->numbones(); i++, pbone++, pweight++) + ' { + ' if (panim && panim->bone == i) + ' { + ' if (*pweight > 0 && (pStudioHdr->boneFlags(i) & boneMask)) + ' { + ' CalcBoneQuaternion( iLocalFrame, s, pbone, pLinearBones, panim, q[i] ); + ' CalcBonePosition ( iLocalFrame, s, pbone, pLinearBones, panim, pos[i] ); + '#ifdef STUDIO_ENABLE_PERF_COUNTERS + ' pStudioHdr->m_nPerfAnimatedBones++; + ' pStudioHdr->m_nPerfUsedBones++; + '#endif + ' } + ' panim = panim->pNext(); + ' } + ' else if (*pweight > 0 && (pStudioHdr->boneFlags(i) & boneMask)) + ' { + ' if (animdesc.flags & STUDIO_DELTA) + ' { + ' q[i].Init( 0.0f, 0.0f, 0.0f, 1.0f ); + ' pos[i].Init( 0.0f, 0.0f, 0.0f ); + ' } + ' else + ' { + ' q[i] = pbone->quat; + ' pos[i] = pbone->pos; + ' } + '#ifdef STUDIO_ENABLE_PERF_COUNTERS + ' pStudioHdr->m_nPerfUsedBones++; + '#endif + ' } + ' } + ' + ' // cross fade in previous zeroframe data + ' if (flStall > 0.0f) + ' { + ' CalcZeroframeData( pStudioHdr, pStudioHdr->GetRenderHdr(), NULL, pStudioHdr->pBone( 0 ), animdesc, fFrame, pos, q, boneMask, flStall ); + ' } + ' + ' if (animdesc.numlocalhierarchy) + ' { + ' matrix3x4_t *boneToWorld = g_MatrixPool.Alloc(); + ' CBoneBitList boneComputed; + ' + ' int i; + ' for (i = 0; i < animdesc.numlocalhierarchy; i++) + ' { + ' mstudiolocalhierarchy_t *pHierarchy = animdesc.pHierarchy( i ); + ' + ' if ( !pHierarchy ) + ' break; + ' + ' if (pStudioHdr->boneFlags(pHierarchy->iBone) & boneMask) + ' { + ' if (pStudioHdr->boneFlags(pHierarchy->iNewParent) & boneMask) + ' { + ' CalcLocalHierarchyAnimation( pStudioHdr, boneToWorld, boneComputed, pos, q, pbone, pHierarchy, pHierarchy->iBone, pHierarchy->iNewParent, cycle, iFrame, s, boneMask ); + ' } + ' } + ' } + ' + ' g_MatrixPool.Free( boneToWorld ); + ' } + ' + '} + Private Sub CalcAnimation(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal frameIndex As Integer) Dim s As Double Dim animIndex As Integer Dim aBone As SourceMdlBone53 Dim aWeight As Double - Dim anAnimation As SourceMdlAnimation + Dim anAnimation As SourceMdlAnimation53 Dim rot As SourceVector Dim pos As SourceVector Dim aFrameLine As AnimationFrameLine @@ -1319,7 +1480,7 @@ Public Class SourceSmdFile53 'End If '------ Dim sectionIndex As Integer - Dim aSectionOfAnimation As List(Of SourceMdlAnimation) + Dim aSectionOfAnimation As List(Of SourceMdlAnimation53) If anAnimationDesc.sectionFrameCount = 0 Then sectionIndex = 0 sectionFrameIndex = frameIndex @@ -1721,35 +1882,13 @@ Public Class SourceSmdFile53 ' Return rot 'End Function - Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation, ByRef rotationQuat As SourceQuaternion) As SourceVector + Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation53, ByRef rotationQuat As SourceQuaternion) As SourceVector Dim rot As New SourceQuaternion() Dim angleVector As New SourceVector() - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT) > 0 Then - rot.x = anAnimation.theRot48bits.x - rot.y = anAnimation.theRot48bits.y - rot.z = anAnimation.theRot48bits.z - rot.w = anAnimation.theRot48bits.w - rotationQuat.x = rot.x - rotationQuat.y = rot.y - rotationQuat.z = rot.z - rotationQuat.w = rot.w - angleVector = MathModule.ToEulerAngles(rot) - - 'NOTE: Change NaN to 0. This is needed for Titanfall 2 "models\titans\light\titan_light_northstar_prime.mdl" for "ragdoll.smd". - If Double.IsNaN(angleVector.x) Then - angleVector.x = 0 - End If - If Double.IsNaN(angleVector.y) Then - angleVector.y = 0 - End If - If Double.IsNaN(angleVector.z) Then - angleVector.z = 0 - End If + If (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_RAWROT) > 0 Then - angleVector.debug_text = "raw48" - Return angleVector - ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT2) > 0 Then + ElseIf (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_RAWROT2) > 0 Then 'angleVector.x = anAnimation.theRot64.xRadians 'angleVector.y = anAnimation.theRot64.yRadians 'angleVector.z = anAnimation.theRot64.zRadians @@ -1772,8 +1911,8 @@ Public Class SourceSmdFile53 Return angleVector End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMROT) = 0 Then - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then + If (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_ANIMROT) = 0 Then + If (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_DELTA) > 0 Then angleVector.x = 0 angleVector.y = 0 angleVector.z = 0 @@ -1795,29 +1934,11 @@ Public Class SourceSmdFile53 Return angleVector End If - Dim rotV As SourceMdlAnimationValuePointer - - rotV = anAnimation.theRotV - - If rotV.animXValueOffset <= 0 Then - angleVector.x = 0 - Else - angleVector.x = Me.ExtractAnimValue(frameIndex, rotV.theAnimXValues, aBone.rotationScale.x) - End If - If rotV.animYValueOffset <= 0 Then - angleVector.y = 0 - Else - angleVector.y = Me.ExtractAnimValue(frameIndex, rotV.theAnimYValues, aBone.rotationScale.y) - End If - If rotV.animZValueOffset <= 0 Then - angleVector.z = 0 - Else - angleVector.z = Me.ExtractAnimValue(frameIndex, rotV.theAnimZValues, aBone.rotationScale.z) - End If + 'Dim rotV As SourceMdlAnimationValuePointer angleVector.debug_text = "anim" - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) = 0 Then + If (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_DELTA) = 0 Then angleVector.x += aBone.rotation.x angleVector.y += aBone.rotation.y angleVector.z += aBone.rotation.z @@ -1887,10 +2008,10 @@ Public Class SourceSmdFile53 ' Assert( pos.IsValid() ); '} - Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation) As SourceVector + Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation53) As SourceVector Dim pos As New SourceVector() - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS) > 0 Then + If (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_RAWPOS) > 0 Then 'If aBone.parentBoneIndex = -1 Then ' pos.x = anAnimation.thePos.y ' pos.y = -anAnimation.thePos.x @@ -1910,8 +2031,8 @@ Public Class SourceSmdFile53 pos.debug_text = "raw" Return pos - ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMPOS) = 0 Then - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then + ElseIf (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_ANIMPOS) = 0 Then + If (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_DELTA) > 0 Then pos.x = 0 pos.y = 0 pos.z = 0 @@ -1927,31 +2048,11 @@ Public Class SourceSmdFile53 Return pos End If - Dim posV As SourceMdlAnimationValuePointer - - posV = anAnimation.thePosV - - If posV.animXValueOffset <= 0 Then - pos.x = 0 - Else - pos.x = Me.ExtractAnimValue(frameIndex, posV.theAnimXValues, aBone.positionScale.x) - End If - - If posV.animYValueOffset <= 0 Then - pos.y = 0 - Else - pos.y = Me.ExtractAnimValue(frameIndex, posV.theAnimYValues, aBone.positionScale.y) - End If - - If posV.animZValueOffset <= 0 Then - pos.z = 0 - Else - pos.z = Me.ExtractAnimValue(frameIndex, posV.theAnimZValues, aBone.positionScale.z) - End If + 'Dim posV As SourceMdlAnimationValuePointer pos.debug_text = "anim" - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) = 0 Then + If (anAnimation.flags And SourceMdlAnimation53.STUDIO_ANIM_DELTA) = 0 Then pos.x += aBone.position.x pos.y += aBone.position.y pos.z += aBone.position.z @@ -2045,6 +2146,9 @@ Public Class SourceSmdFile53 Private poseToWorldColumn2 As New SourceVector() Private poseToWorldColumn3 As New SourceVector() + Private previousFrameRotation As New SourceVector() + Private frame0Position As New SourceVector() + #End Region End Class diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index dc44a69..9dbb690 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -128,9 +128,12 @@ + + + @@ -360,7 +363,6 @@ - From 85ffde8608d380569475f6939b6cf7cf1c0db46f Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Fri, 26 Aug 2022 19:52:06 -0400 Subject: [PATCH 10/39] Progress on MDL 53 animation decompiling. --- .../SourceMdlFileData/SourceMdlAnimation.vb | 16 + .../SourceModel53/SourceMdlFile53.vb | 393 +++++------------- .../SourceModel53/SourceSmdFile53.vb | 327 ++------------- Crowbar/My Project/AssemblyInfo.vb | 4 +- 4 files changed, 150 insertions(+), 590 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb index 73e9438..5a2ef88 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb @@ -32,6 +32,22 @@ Public Class SourceMdlAnimation ' short nextoffset; Public nextSourceMdlAnimationOffset As Short + 'MDL 53 stuff + Public TranslationScale As Double + Public Flags2 As Byte + Public Flags3 As Byte + 'Public OffsetX As Short + 'Public OffsetY As Short + 'Public OffsetZ As Short + 'Public OffsetL As Short + Public TranslationX As SourceFloat16bits + Public TranslationY As SourceFloat16bits + Public TranslationZ As SourceFloat16bits + Public ScaleX As SourceFloat16bits + Public ScaleY As SourceFloat16bits + Public ScaleZ As SourceFloat16bits + Public nextTitanfall2MdlAnimationOffset As Integer + ' Values for the field, flags: '#define STUDIO_ANIM_RAWPOS 0x01 // Vector48 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 60e6550..60ed918 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -925,51 +925,55 @@ Public Class SourceMdlFile53 Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.localAnimationOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position - Me.theMdlFileData.theAnimationDescs = New List(Of SourceMdlAnimationDesc52)(Me.theMdlFileData.localAnimationCount) - For i As Integer = 0 To Me.theMdlFileData.localAnimationCount - 1 - animInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim anAnimationDesc As New SourceMdlAnimationDesc52() + Try + Me.theMdlFileData.theAnimationDescs = New List(Of SourceMdlAnimationDesc52)(Me.theMdlFileData.localAnimationCount) + For i As Integer = 0 To Me.theMdlFileData.localAnimationCount - 1 + animInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + Dim anAnimationDesc As New SourceMdlAnimationDesc52() + + anAnimationDesc.theOffsetStart = Me.theInputFileReader.BaseStream.Position + + anAnimationDesc.baseHeaderOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.nameOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.fps = Me.theInputFileReader.ReadSingle() + anAnimationDesc.flags = Me.theInputFileReader.ReadInt32() + anAnimationDesc.frameCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.movementCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.movementOffset = Me.theInputFileReader.ReadInt32() + + anAnimationDesc.animBlock = Me.theInputFileReader.ReadInt32() + anAnimationDesc.animOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.ikRuleOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.animblockIkRuleOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.localHierarchyCount = Me.theInputFileReader.ReadInt32() + anAnimationDesc.localHierarchyOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.sectionOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.sectionFrameCount = Me.theInputFileReader.ReadInt32() + + anAnimationDesc.spanFrameCount = Me.theInputFileReader.ReadInt16() + anAnimationDesc.spanCount = Me.theInputFileReader.ReadInt16() + 'anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() + 'anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() + + anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() + + For x As Integer = 0 To anAnimationDesc.unused1.Length - 1 + anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() + Next - anAnimationDesc.theOffsetStart = Me.theInputFileReader.BaseStream.Position + Me.theMdlFileData.theAnimationDescs.Add(anAnimationDesc) - anAnimationDesc.baseHeaderOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.nameOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.fps = Me.theInputFileReader.ReadSingle() - anAnimationDesc.flags = Me.theInputFileReader.ReadInt32() - anAnimationDesc.frameCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.movementCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.movementOffset = Me.theInputFileReader.ReadInt32() + inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() + Me.ReadAnimationDescName(animInputFileStreamPosition, anAnimationDesc) + 'Me.ReadAnimationDescSpanData(animInputFileStreamPosition, anAnimationDesc) - For x As Integer = 0 To anAnimationDesc.unused1.Length - 1 - anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() + Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) Next - - anAnimationDesc.animBlock = Me.theInputFileReader.ReadInt32() - anAnimationDesc.animOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.ikRuleOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.animblockIkRuleOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.localHierarchyCount = Me.theInputFileReader.ReadInt32() - anAnimationDesc.localHierarchyOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.sectionOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.sectionFrameCount = Me.theInputFileReader.ReadInt32() - - anAnimationDesc.spanFrameCount = Me.theInputFileReader.ReadInt16() - anAnimationDesc.spanCount = Me.theInputFileReader.ReadInt16() - 'anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() - 'anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() - - Me.theMdlFileData.theAnimationDescs.Add(anAnimationDesc) - - inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - - Me.ReadAnimationDescName(animInputFileStreamPosition, anAnimationDesc) - 'Me.ReadAnimationDescSpanData(animInputFileStreamPosition, anAnimationDesc) - - Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - Next + Catch ex As Exception + Dim debug As Integer = 4242 + End Try fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theAnimationDescs " + Me.theMdlFileData.theAnimationDescs.Count.ToString()) @@ -1008,7 +1012,6 @@ Public Class SourceMdlFile53 Dim animInputFileStreamPosition As Long Dim anAnimationDesc As SourceMdlAnimationDesc52 Dim aSectionOfAnimation As List(Of SourceMdlAnimation) - Dim aSectionOfFrameAnimation As SourceAniFrameAnim52 For anAnimDescIndex As Integer = 0 To Me.theMdlFileData.theAnimationDescs.Count - 1 anAnimationDesc = Me.theMdlFileData.theAnimationDescs(anAnimDescIndex) @@ -1019,113 +1022,15 @@ Public Class SourceMdlFile53 Me.theMdlFileData.theFirstAnimationDesc = anAnimationDesc End If - If ((anAnimationDesc.flags And SourceMdlAnimationDesc.STUDIO_FRAMEANIM) <> 0) Then - anAnimationDesc.theSectionsOfFrameAnim = New List(Of SourceAniFrameAnim52)() - aSectionOfFrameAnimation = New SourceAniFrameAnim52() - anAnimationDesc.theSectionsOfFrameAnim.Add(aSectionOfFrameAnimation) - - Dim sectionIndex As Integer - If anAnimationDesc.sectionOffset <> 0 AndAlso anAnimationDesc.sectionFrameCount > 0 Then - Dim sectionFrameCount As Integer - Dim sectionCount As Integer + anAnimationDesc.theSectionsOfAnimations = New List(Of List(Of SourceMdlAnimation))() + aSectionOfAnimation = New List(Of SourceMdlAnimation)() + anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) + Me.ReadMdlAnimation(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, anAnimationDesc.theSectionsOfAnimations(0), True) - 'TODO: Shouldn't this be set to largest sectionFrameCount? - Me.theMdlFileData.theSectionFrameCount = anAnimationDesc.sectionFrameCount - If Me.theMdlFileData.theSectionFrameMinFrameCount >= anAnimationDesc.frameCount Then - Me.theMdlFileData.theSectionFrameMinFrameCount = anAnimationDesc.frameCount - 1 - End If - - ''FROM: simplify.cpp: - '' panim->numsections = (int)(panim->numframes / panim->sectionframes) + 2; - ''NOTE: It is unclear why "+ 2" is used in studiomdl. - sectionCount = CInt(Math.Truncate(anAnimationDesc.frameCount / anAnimationDesc.sectionFrameCount)) + 2 - - 'NOTE: First sectionOfAnimation was created above. - For sectionIndex = 1 To sectionCount - 1 - aSectionOfFrameAnimation = New SourceAniFrameAnim52() - anAnimationDesc.theSectionsOfFrameAnim.Add(aSectionOfFrameAnimation) - Next - - 'TODO: Is this "if" check correct? Should it be removed? - ' Maybe when there are sections, the section.animBlock determines which file the data is in. - If anAnimationDesc.animBlock = 0 Then - For sectionIndex = 0 To sectionCount - 1 - If anAnimationDesc.theSections(sectionIndex).animBlock = 0 Then - aSectionOfFrameAnimation = anAnimationDesc.theSectionsOfFrameAnim(sectionIndex) - - If sectionIndex < sectionCount - 2 Then - sectionFrameCount = anAnimationDesc.sectionFrameCount - Else - 'NOTE: Due to the weird calculation of sectionCount in studiomdl, this line is called twice, which means there are two "last" sections. - ' This also likely means that the last section is bogus unused data. - sectionFrameCount = anAnimationDesc.frameCount - ((sectionCount - 2) * anAnimationDesc.sectionFrameCount) - End If - - Me.ReadAnimationFrameByBone(animInputFileStreamPosition + anAnimationDesc.theSections(sectionIndex).animOffset, anAnimationDesc, sectionFrameCount, sectionIndex, (sectionIndex >= sectionCount - 2) Or (anAnimationDesc.frameCount = (sectionIndex + 1) * anAnimationDesc.sectionFrameCount)) - End If - Next - End If - ElseIf anAnimationDesc.animBlock = 0 Then - 'NOTE: This code is reached by L4D2's pak01_dir.vpk\models\v_models\v_huntingrifle.mdl. - sectionIndex = 0 - Me.ReadAnimationFrameByBone(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, sectionIndex, True) - End If - Else - anAnimationDesc.theSectionsOfAnimations = New List(Of List(Of SourceMdlAnimation))() - aSectionOfAnimation = New List(Of SourceMdlAnimation)() - anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) - - If anAnimationDesc.sectionOffset <> 0 AndAlso anAnimationDesc.sectionFrameCount > 0 Then - Dim sectionFrameCount As Integer - Dim sectionCount As Integer - - 'TODO: Shouldn't this be set to largest sectionFrameCount? - Me.theMdlFileData.theSectionFrameCount = anAnimationDesc.sectionFrameCount - If Me.theMdlFileData.theSectionFrameMinFrameCount >= anAnimationDesc.frameCount Then - Me.theMdlFileData.theSectionFrameMinFrameCount = anAnimationDesc.frameCount - 1 - End If - - ''FROM: simplify.cpp: - '' panim->numsections = (int)(panim->numframes / panim->sectionframes) + 2; - ''NOTE: It is unclear why "+ 2" is used in studiomdl. - sectionCount = CInt(Math.Truncate(anAnimationDesc.frameCount / anAnimationDesc.sectionFrameCount)) + 2 - - 'NOTE: First sectionOfAnimation was created above. - For sectionIndex As Integer = 1 To sectionCount - 1 - aSectionOfAnimation = New List(Of SourceMdlAnimation)() - anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) - Next - - Dim adjustedAnimOffset As Long - If anAnimationDesc.animBlock = 0 Then - For sectionIndex As Integer = 0 To sectionCount - 1 - If anAnimationDesc.theSections(sectionIndex).animBlock = 0 Then - 'NOTE: This is weird, but it fits with a few oddball models (such as L4D2 "left4dead2\ghostanim.mdl") while not messing up the normal ones. - adjustedAnimOffset = anAnimationDesc.theSections(sectionIndex).animOffset + (anAnimationDesc.animOffset - anAnimationDesc.theSections(0).animOffset) - - aSectionOfAnimation = anAnimationDesc.theSectionsOfAnimations(sectionIndex) - - If sectionIndex < sectionCount - 2 Then - sectionFrameCount = anAnimationDesc.sectionFrameCount - Else - 'NOTE: Due to the weird calculation of sectionCount in studiomdl, this line is called twice, which means there are two "last" sections. - ' This also likely means that the last section is bogus unused data. - sectionFrameCount = anAnimationDesc.frameCount - ((sectionCount - 2) * anAnimationDesc.sectionFrameCount) - End If - - Me.ReadMdlAnimation(animInputFileStreamPosition + adjustedAnimOffset, anAnimationDesc, sectionFrameCount, aSectionOfAnimation, (sectionIndex >= sectionCount - 2) Or (anAnimationDesc.frameCount = (sectionIndex + 1) * anAnimationDesc.sectionFrameCount)) - End If - Next - End If - ElseIf anAnimationDesc.animBlock = 0 Then - Me.ReadMdlAnimation(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, anAnimationDesc.theSectionsOfAnimations(0), True) - End If - End If - - If anAnimationDesc.animBlock = 0 Then - Me.ReadMdlIkRules(animInputFileStreamPosition, anAnimationDesc) - Me.ReadLocalHierarchies(animInputFileStreamPosition, anAnimationDesc) - End If + 'If anAnimationDesc.animBlock = 0 Then + ' Me.ReadMdlIkRules(animInputFileStreamPosition, anAnimationDesc) + ' Me.ReadLocalHierarchies(animInputFileStreamPosition, anAnimationDesc) + 'End If Me.ReadMdlMovements(animInputFileStreamPosition, anAnimationDesc) Next @@ -1409,187 +1314,77 @@ Public Class SourceMdlFile53 Protected Sub ReadMdlAnimation(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation), ByVal lastSectionIsBeingRead As Boolean) Dim animationInputFileStreamPosition As Long Dim nextAnimationInputFileStreamPosition As Long - Dim animValuePointerInputFileStreamPosition As Long - Dim rotValuePointerInputFileStreamPosition As Long - Dim posValuePointerInputFileStreamPosition As Long + 'Dim animValuePointerInputFileStreamPosition As Long + 'Dim rotValuePointerInputFileStreamPosition As Long + 'Dim posValuePointerInputFileStreamPosition As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long Dim anAnimation As SourceMdlAnimation Dim boneCount As Integer - Dim boneIndex As Byte + 'Dim boneIndex As Byte + Dim boneChangeCount As Integer Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition, SeekOrigin.Begin) + fileOffsetStart = Me.theInputFileReader.BaseStream.Position - If Me.theMdlFileData.theBones Is Nothing Then - boneCount = 1 - Else - boneCount = Me.theMdlFileData.theBones.Count - End If + boneCount = Me.theMdlFileData.theBones.Count + boneChangeCount = 0 For j As Integer = 0 To boneCount - 1 animationInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - - boneIndex = Me.theInputFileReader.ReadByte() - If boneIndex = 255 Then - Me.theInputFileReader.ReadByte() - Me.theInputFileReader.ReadInt16() - - fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(animationInputFileStreamPosition, fileOffsetEnd, "anAnimationDesc.anAnimation (boneIndex = 255)") - - 'Continue For - Exit For - End If - 'DEBUG: - If boneIndex >= boneCount Then - Dim badIfGetsHere As Integer = 42 - Exit For - End If + boneChangeCount += 1 anAnimation = New SourceMdlAnimation() aSectionOfAnimation.Add(anAnimation) - anAnimation.boneIndex = boneIndex + anAnimation.TranslationScale = Me.theInputFileReader.ReadSingle() + anAnimation.boneIndex = Me.theInputFileReader.ReadByte() anAnimation.flags = Me.theInputFileReader.ReadByte() - anAnimation.nextSourceMdlAnimationOffset = Me.theInputFileReader.ReadInt16() - - 'DEBUG: - If (anAnimation.flags And &H40) > 0 Then - Dim badIfGetsHere As Integer = 42 - End If - If (anAnimation.flags And &H80) > 0 Then - Dim badIfGetsHere As Integer = 42 - End If - - 'If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then - 'End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT2) > 0 Then - anAnimation.theRot64bits = New SourceQuaternion64bits() - anAnimation.theRot64bits.theBytes = Me.theInputFileReader.ReadBytes(8) - - 'Me.DebugQuaternion(anAnimation.theRot64) - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT) > 0 Then - anAnimation.theRot48bits = New SourceQuaternion48bits() - anAnimation.theRot48bits.theXInput = Me.theInputFileReader.ReadUInt16() - anAnimation.theRot48bits.theYInput = Me.theInputFileReader.ReadUInt16() - anAnimation.theRot48bits.theZWInput = Me.theInputFileReader.ReadUInt16() - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS) > 0 Then - anAnimation.thePos = New SourceVector48bits() - anAnimation.thePos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.thePos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.thePos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - End If - - animValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - - ' First, read both sets of offsets. - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMROT) > 0 Then - rotValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anAnimation.theRotV = New SourceMdlAnimationValuePointer() - - anAnimation.theRotV.animXValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.theRotV.theAnimXValues Is Nothing Then - anAnimation.theRotV.theAnimXValues = New List(Of SourceMdlAnimationValue)() - End If - - anAnimation.theRotV.animYValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.theRotV.theAnimYValues Is Nothing Then - anAnimation.theRotV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - End If - - anAnimation.theRotV.animZValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.theRotV.theAnimZValues Is Nothing Then - anAnimation.theRotV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - End If - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMPOS) > 0 Then - posValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anAnimation.thePosV = New SourceMdlAnimationValuePointer() - - anAnimation.thePosV.animXValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.thePosV.theAnimXValues Is Nothing Then - anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() - End If - - anAnimation.thePosV.animYValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.thePosV.theAnimYValues Is Nothing Then - anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - End If - - anAnimation.thePosV.animZValueOffset = Me.theInputFileReader.ReadInt16() - If anAnimation.thePosV.theAnimZValues Is Nothing Then - anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - End If - End If - - Me.theMdlFileData.theFileSeekLog.Add(animationInputFileStreamPosition, Me.theInputFileReader.BaseStream.Position - 1, "anAnimationDesc.anAnimation (frameCount = " + CStr(anAnimationDesc.frameCount) + "; sectionFrameCount = " + CStr(sectionFrameCount) + ")") - - ' Second, read the anim values using the offsets. - 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMROT) > 0 Then - If anAnimation.theRotV.animXValueOffset > 0 Then - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRotV.animXValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimXValues, "anAnimation.theRotV.theAnimXValues") - End If - If anAnimation.theRotV.animYValueOffset > 0 Then - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRotV.animYValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimYValues, "anAnimation.theRotV.theAnimYValues") - End If - If anAnimation.theRotV.animZValueOffset > 0 Then - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRotV.animZValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimZValues, "anAnimation.theRotV.theAnimZValues") - End If - End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMPOS) > 0 Then - If anAnimation.thePosV.animXValueOffset > 0 Then - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.thePosV.animXValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") - End If - If anAnimation.thePosV.animYValueOffset > 0 Then - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.thePosV.animYValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimYValues, "anAnimation.thePosV.theAnimYValues") - End If - If anAnimation.thePosV.animZValueOffset > 0 Then - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.thePosV.animZValueOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimZValues, "anAnimation.thePosV.theAnimZValues") - End If - End If - 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + anAnimation.Flags2 = Me.theInputFileReader.ReadByte() + anAnimation.Flags3 = Me.theInputFileReader.ReadByte() + + 'anAnimation.OffsetX = Me.theInputFileReader.ReadInt16() + 'anAnimation.OffsetY = Me.theInputFileReader.ReadInt16() + 'anAnimation.OffsetZ = Me.theInputFileReader.ReadInt16() + 'anAnimation.OffsetL = Me.theInputFileReader.ReadInt16() + anAnimation.theRot64bits = New SourceQuaternion64bits() + anAnimation.theRot64bits.theBytes = Me.theInputFileReader.ReadBytes(8) + + anAnimation.TranslationX = New SourceFloat16bits() + anAnimation.TranslationY = New SourceFloat16bits() + anAnimation.TranslationZ = New SourceFloat16bits() + anAnimation.TranslationX.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.TranslationY.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.TranslationZ.the16BitValue = Me.theInputFileReader.ReadUInt16() + + anAnimation.ScaleX = New SourceFloat16bits() + anAnimation.ScaleY = New SourceFloat16bits() + anAnimation.ScaleZ = New SourceFloat16bits() + anAnimation.ScaleX.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.ScaleY.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.ScaleZ.the16BitValue = Me.theInputFileReader.ReadUInt16() + + anAnimation.nextTitanfall2MdlAnimationOffset = Me.theInputFileReader.ReadInt32() + 'TODO: Read in rest of struct. 'NOTE: If the offset is 0 then there are no more bone animation structures, so end the loop. - If anAnimation.nextSourceMdlAnimationOffset = 0 Then - 'j = boneCount - 'lastFullAnimDataWasFound = True + If anAnimation.nextTitanfall2MdlAnimationOffset = 0 Then Exit For Else - ' Skip to next anim, just in case not all data is being read in. - nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + anAnimation.nextSourceMdlAnimationOffset - ''TEST: Use this with ANI file, so see if it extracts better. - 'nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + CType(anAnimation.nextSourceMdlAnimationOffset, UShort) + nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + anAnimation.nextTitanfall2MdlAnimationOffset If nextAnimationInputFileStreamPosition < Me.theInputFileReader.BaseStream.Position Then 'PROBLEM! Should not be going backwards in file. Dim i As Integer = 42 Exit For - ElseIf nextAnimationInputFileStreamPosition > Me.theInputFileReader.BaseStream.Position Then - 'PROBLEM! Should not be skipping ahead. Crowbar has skipped some data, but continue decompiling. - Dim i As Integer = 42 End If Me.theInputFileReader.BaseStream.Seek(nextAnimationInputFileStreamPosition, SeekOrigin.Begin) End If Next - If boneIndex <> 255 Then - 'NOTE: There is always an unused empty data structure at the end of the list. - 'prevanim = destanim; - 'destanim->nextoffset = pData - (byte *)destanim; - 'destanim = (mstudioanim_t *)pData; - 'pData += sizeof( *destanim ); - fileOffsetStart = Me.theInputFileReader.BaseStream.Position - Me.theInputFileReader.ReadByte() - Me.theInputFileReader.ReadByte() - Me.theInputFileReader.ReadInt16() - - fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] (unused empty data structure at the end of the list)") - End If + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] (boneChangeCount = " + CStr(boneChangeCount) + ")") - Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] alignment") + 'Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] alignment") End Sub '========================================================== diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 99f0c8f..538bcd5 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -363,7 +363,7 @@ Public Class SourceSmdFile53 Public Sub WriteSkeletonSectionForAnimation(ByVal aSequenceDescBase As SourceMdlSequenceDescBase, ByVal anAnimationDescBase As SourceMdlAnimationDescBase) Dim line As String = "" - Dim aBone As SourceMdlBone53 + 'Dim aBone As SourceMdlBone53 Dim boneIndex As Integer Dim aFrameLine As AnimationFrameLine Dim position As New SourceVector() @@ -384,105 +384,7 @@ Public Class SourceSmdFile53 For frameIndex As Integer = 0 To anAnimationDesc.frameCount - 1 Me.theAnimationFrameLines.Clear() - If ((anAnimationDesc.flags And SourceMdlAnimationDesc.STUDIO_FRAMEANIM) <> 0) Then - Dim sectionFrameIndex As Integer - Dim sectionIndex As Integer - Dim aSectionOfAnimation As SourceAniFrameAnim52 - If anAnimationDesc.sectionFrameCount = 0 Then - sectionIndex = 0 - sectionFrameIndex = frameIndex - Else - sectionIndex = CInt(Math.Truncate(frameIndex / anAnimationDesc.sectionFrameCount)) - sectionFrameIndex = frameIndex - (sectionIndex * anAnimationDesc.sectionFrameCount) - End If - aSectionOfAnimation = anAnimationDesc.theSectionsOfFrameAnim(sectionIndex) - - Dim aBoneConstantInfo As BoneConstantInfo49 - Dim aBoneFrameDataInfo As BoneFrameDataInfo49 - - For boneIndex = 0 To Me.theMdlFileData.theBones.Count - 1 - aBone = Me.theMdlFileData.theBones(boneIndex) - - aFrameLine = New AnimationFrameLine() - Me.theAnimationFrameLines.Add(boneIndex, aFrameLine) - - aFrameLine.position = New SourceVector() - aFrameLine.rotation = New SourceVector() - - If (anAnimationDesc.flags And SourceMdlAnimationDesc.STUDIO_DELTA) > 0 Then - aFrameLine.position.x = 0 - aFrameLine.position.y = 0 - aFrameLine.position.z = 0 - aFrameLine.position.debug_text = "ZERO" - aFrameLine.rotation.x = 0 - aFrameLine.rotation.y = 0 - aFrameLine.rotation.z = 0 - aFrameLine.rotation.debug_text = "ZERO" - Else - aFrameLine.position.x = aBone.position.x - aFrameLine.position.y = aBone.position.y - aFrameLine.position.z = aBone.position.z - aFrameLine.position.debug_text = "BONE" - aFrameLine.rotation.x = aBone.rotation.x - aFrameLine.rotation.y = aBone.rotation.y - aFrameLine.rotation.z = aBone.rotation.z - aFrameLine.rotation.debug_text = "BONE" - End If - - Dim boneFlag As Integer - boneFlag = aSectionOfAnimation.theBoneFlags(boneIndex) - If aSectionOfAnimation.theBoneConstantInfos IsNot Nothing Then - aBoneConstantInfo = aSectionOfAnimation.theBoneConstantInfos(boneIndex) - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWROT) > 0 Then - aFrameLine.rotation = MathModule.ToEulerAngles(aBoneConstantInfo.theConstantRawRot.quaternion) - aFrameLine.rotation.debug_text = "RAWROT" - End If - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWPOS) > 0 Then - aFrameLine.position.x = aBoneConstantInfo.theConstantRawPos.x - aFrameLine.position.y = aBoneConstantInfo.theConstantRawPos.y - aFrameLine.position.z = aBoneConstantInfo.theConstantRawPos.z - aFrameLine.position.debug_text = "RAWPOS" - End If - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_CONST_ROT2) > 0 Then - aFrameLine.rotation = MathModule.ToEulerAngles(aBoneConstantInfo.theConstantRotationUnknown.quaternion) - aFrameLine.rotation.debug_text = "FRAME_CONST_ROT2" - End If - End If - If aSectionOfAnimation.theBoneFrameDataInfos IsNot Nothing Then - aBoneFrameDataInfo = aSectionOfAnimation.theBoneFrameDataInfos(sectionFrameIndex)(boneIndex) - 'If (boneFlag And SourceAniFrameAnim.STUDIO_FRAME_ANIMROT) > 0 Then - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_FULLANIMPOS) > 0 Then - aFrameLine.rotation = MathModule.ToEulerAngles(aBoneFrameDataInfo.theAnimRotation.quaternion) - aFrameLine.rotation.debug_text = "ANIMROT" - End If - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIMPOS) > 0 Then - aFrameLine.position.x = aBoneFrameDataInfo.theAnimPosition.x - aFrameLine.position.y = aBoneFrameDataInfo.theAnimPosition.y - aFrameLine.position.z = aBoneFrameDataInfo.theAnimPosition.z - aFrameLine.position.debug_text = "ANIMPOS" - End If - 'If (boneFlag And SourceAniFrameAnim.STUDIO_FRAME_FULLANIMPOS) > 0 Then - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIMROT) > 0 Then - 'aFrameLine.position.x = aBoneFrameDataInfo.theFullAnimPosition.x - 'aFrameLine.position.y = aBoneFrameDataInfo.theFullAnimPosition.y - 'aFrameLine.position.z = aBoneFrameDataInfo.theFullAnimPosition.z - aFrameLine.position.x = aBoneFrameDataInfo.theAnimPosition.x - aFrameLine.position.y = aBoneFrameDataInfo.theAnimPosition.y - aFrameLine.position.z = aBoneFrameDataInfo.theAnimPosition.z - aFrameLine.position.debug_text = "FULLANIMPOS" - End If - If (boneFlag And &H20) > 0 Then - Dim unknownFlagIsUsed As Integer = 4242 - End If - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIM_ROT2) > 0 Then - aFrameLine.rotation = MathModule.ToEulerAngles(aBoneFrameDataInfo.theAnimRotationUnknown.quaternion) - aFrameLine.rotation.debug_text = "FRAME_ANIM_ROT2" - End If - End If - Next - Else - Me.CalcAnimation(aSequenceDesc, anAnimationDesc, frameIndex) - End If + Me.CalcAnimation(aSequenceDesc, anAnimationDesc, frameIndex) If TheApp.Settings.DecompileStricterFormatIsChecked Then line = "time " @@ -1303,8 +1205,8 @@ Public Class SourceSmdFile53 Dim aBone As SourceMdlBone53 Dim aWeight As Double Dim anAnimation As SourceMdlAnimation - Dim rot As SourceVector - Dim pos As SourceVector + Dim rot As SourceQuaternion + 'Dim pos As SourceVector Dim aFrameLine As AnimationFrameLine Dim sectionFrameIndex As Integer @@ -1312,12 +1214,6 @@ Public Class SourceSmdFile53 animIndex = 0 - 'If anAnimationDesc.theAnimations Is Nothing OrElse animIndex >= anAnimationDesc.theAnimations.Count Then - ' anAnimation = Nothing - 'Else - ' anAnimation = anAnimationDesc.theAnimations(animIndex) - 'End If - '------ Dim sectionIndex As Integer Dim aSectionOfAnimation As List(Of SourceMdlAnimation) If anAnimationDesc.sectionFrameCount = 0 Then @@ -1327,12 +1223,6 @@ Public Class SourceSmdFile53 sectionIndex = CInt(Math.Truncate(frameIndex / anAnimationDesc.sectionFrameCount)) sectionFrameIndex = frameIndex - (sectionIndex * anAnimationDesc.sectionFrameCount) End If - 'aSectionOfAnimation = anAnimationDesc.theSectionsOfAnimations(sectionIndex) - 'If anAnimationDesc.theSectionsOfAnimations Is Nothing OrElse animIndex >= aSectionOfAnimation.Count Then - ' anAnimation = Nothing - 'Else - ' anAnimation = aSectionOfAnimation(animIndex) - 'End If anAnimation = Nothing aSectionOfAnimation = Nothing If anAnimationDesc.theSectionsOfAnimations IsNot Nothing Then @@ -1363,132 +1253,45 @@ Public Class SourceSmdFile53 End If aFrameLine.rotationQuat = New SourceQuaternion() - 'rot = CalcBoneRotation(frameIndex, s, aBone, anAnimation) - rot = CalcBoneRotation(sectionFrameIndex, s, aBone, anAnimation, aFrameLine.rotationQuat) - aFrameLine.rotation = New SourceVector() - 'NOTE: z = z puts head-foot axis horizontally - ' facing viewer - aFrameLine.rotation.x = rot.x - aFrameLine.rotation.y = rot.y - aFrameLine.rotation.z = rot.z - '------ - 'aFrameLine.rotation.x = rot.x - 'aFrameLine.rotation.y = rot.y - 1.570796 - 'aFrameLine.rotation.z = rot.z - '------ - 'aFrameLine.rotation.x = rot.y - 'aFrameLine.rotation.y = rot.x - 'aFrameLine.rotation.z = rot.z - '------ - '------ - 'NOTE: x = z puts head-foot axis horizontally - ' facing away from viewer - 'aFrameLine.rotation.x = rot.z - 'aFrameLine.rotation.y = rot.y - 'aFrameLine.rotation.z = rot.x - '------ - 'aFrameLine.rotation.x = rot.z - 'aFrameLine.rotation.y = rot.x - 'aFrameLine.rotation.z = rot.y - '------ - '------ - 'NOTE: y = z : head-foot axis vertically correctly - ' x = -x : upside-down - ' z = y : - ' facing to window right - 'aFrameLine.rotation.x = rot.x - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = rot.y - '------ - 'NOTE: Upside-down; facing to window left - 'aFrameLine.rotation.x = -rot.x - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = rot.y - '------ - ' facing to window right - 'aFrameLine.rotation.x = rot.x - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = rot.y - '------ - 'NOTE: Upside-down; facing to window left - 'aFrameLine.rotation.x = -rot.x - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = rot.y - '------ - ' facing to window left - 'aFrameLine.rotation.x = rot.x - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = -rot.y - '------ - 'NOTE: Upside-down; facing to window right - 'aFrameLine.rotation.x = -rot.x - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = -rot.y - '------ - ' facing to window left - 'aFrameLine.rotation.x = rot.x - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = -rot.y - '------ - 'NOTE: Upside-down; facing to window right - 'aFrameLine.rotation.x = -rot.x - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = -rot.y - '------ - '------ - ' facing to window right - 'aFrameLine.rotation.x = rot.y - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = rot.x - '------ - 'NOTE: Upside-down; facing to window left - 'aFrameLine.rotation.x = -rot.y - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = rot.x - '------ - ' facing to window right - 'aFrameLine.rotation.x = rot.y - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = rot.x - '------ - 'aFrameLine.rotation.x = -rot.y - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = rot.x - '------ - 'aFrameLine.rotation.x = rot.y - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = -rot.x - '------ - 'aFrameLine.rotation.x = -rot.y - 'aFrameLine.rotation.y = rot.z - 'aFrameLine.rotation.z = -rot.x - '------ - 'aFrameLine.rotation.x = rot.y - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = -rot.x - '------ - 'aFrameLine.rotation.x = -rot.y - 'aFrameLine.rotation.y = -rot.z - 'aFrameLine.rotation.z = -rot.x - - aFrameLine.rotation.debug_text = rot.debug_text + 'rot = CalcBoneRotation(sectionFrameIndex, s, aBone, anAnimation, aFrameLine.rotationQuat) + Dim angleVector As New SourceVector() + If (anAnimation.flags And &H4) > 0 Then + rot = New SourceQuaternion() + rot.x = anAnimation.theRot64bits.x + rot.y = anAnimation.theRot64bits.y + rot.z = anAnimation.theRot64bits.z + rot.w = anAnimation.theRot64bits.w + angleVector = MathModule.ToEulerAngles(rot) + angleVector.debug_text = "raw64 (" + rot.x.ToString() + ", " + rot.y.ToString() + ", " + rot.z.ToString() + ", " + rot.w.ToString() + ")" + Else + angleVector.x = aBone.rotation.x + angleVector.y = aBone.rotation.y + angleVector.z = aBone.rotation.z + angleVector.debug_text = "bone" + End If + aFrameLine.rotation = New SourceVector() + aFrameLine.rotation.x = angleVector.x + aFrameLine.rotation.y = angleVector.y + aFrameLine.rotation.z = angleVector.z + aFrameLine.rotation.debug_text = angleVector.debug_text - 'pos = Me.CalcBonePosition(frameIndex, s, aBone, anAnimation) - pos = Me.CalcBonePosition(sectionFrameIndex, s, aBone, anAnimation) + 'pos = Me.CalcBonePosition(sectionFrameIndex, s, aBone, anAnimation) aFrameLine.position = New SourceVector() - aFrameLine.position.x = pos.x - aFrameLine.position.y = pos.y - aFrameLine.position.z = pos.z - aFrameLine.position.debug_text = pos.debug_text + If (anAnimation.flags And &H2) > 0 Then + aFrameLine.position.x = anAnimation.TranslationX.TheFloatValue + aFrameLine.position.y = anAnimation.TranslationY.TheFloatValue + aFrameLine.position.z = anAnimation.TranslationZ.TheFloatValue + aFrameLine.position.debug_text = "anim" + Else + aFrameLine.position.x = aBone.position.x + aFrameLine.position.y = aBone.position.y + aFrameLine.position.z = aBone.position.z + aFrameLine.position.debug_text = "bone" + End If End If animIndex += 1 - 'If animIndex >= anAnimationDesc.theAnimations.Count Then - ' anAnimation = Nothing - 'Else - ' anAnimation = anAnimationDesc.theAnimations(animIndex) - 'End If If animIndex >= aSectionOfAnimation.Count Then anAnimation = Nothing Else @@ -1725,35 +1528,7 @@ Public Class SourceSmdFile53 Dim rot As New SourceQuaternion() Dim angleVector As New SourceVector() - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT) > 0 Then - rot.x = anAnimation.theRot48bits.x - rot.y = anAnimation.theRot48bits.y - rot.z = anAnimation.theRot48bits.z - rot.w = anAnimation.theRot48bits.w - rotationQuat.x = rot.x - rotationQuat.y = rot.y - rotationQuat.z = rot.z - rotationQuat.w = rot.w - angleVector = MathModule.ToEulerAngles(rot) - - 'NOTE: Change NaN to 0. This is needed for Titanfall 2 "models\titans\light\titan_light_northstar_prime.mdl" for "ragdoll.smd". - If Double.IsNaN(angleVector.x) Then - angleVector.x = 0 - End If - If Double.IsNaN(angleVector.y) Then - angleVector.y = 0 - End If - If Double.IsNaN(angleVector.z) Then - angleVector.z = 0 - End If - - angleVector.debug_text = "raw48" - Return angleVector - ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT2) > 0 Then - 'angleVector.x = anAnimation.theRot64.xRadians - 'angleVector.y = anAnimation.theRot64.yRadians - 'angleVector.z = anAnimation.theRot64.zRadians - '------ + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT2) > 0 Then rot.x = anAnimation.theRot64bits.x rot.y = anAnimation.theRot64bits.y rot.z = anAnimation.theRot64bits.z @@ -1764,10 +1539,6 @@ Public Class SourceSmdFile53 rotationQuat.w = rot.w angleVector = MathModule.ToEulerAngles(rot) - ''TEST: Rotate z by -90 degrees. - ''TEST: Rotate y by -90 degrees. - 'angleVector.y += MathModule.DegreesToRadians(-90) - angleVector.debug_text = "raw64 (" + rot.x.ToString() + ", " + rot.y.ToString() + ", " + rot.z.ToString() + ", " + rot.w.ToString() + ")" Return angleVector End If @@ -1795,28 +1566,6 @@ Public Class SourceSmdFile53 Return angleVector End If - Dim rotV As SourceMdlAnimationValuePointer - - rotV = anAnimation.theRotV - - If rotV.animXValueOffset <= 0 Then - angleVector.x = 0 - Else - angleVector.x = Me.ExtractAnimValue(frameIndex, rotV.theAnimXValues, aBone.rotationScale.x) - End If - If rotV.animYValueOffset <= 0 Then - angleVector.y = 0 - Else - angleVector.y = Me.ExtractAnimValue(frameIndex, rotV.theAnimYValues, aBone.rotationScale.y) - End If - If rotV.animZValueOffset <= 0 Then - angleVector.z = 0 - Else - angleVector.z = Me.ExtractAnimValue(frameIndex, rotV.theAnimZValues, aBone.rotationScale.z) - End If - - angleVector.debug_text = "anim" - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) = 0 Then angleVector.x += aBone.rotation.x angleVector.y += aBone.rotation.y diff --git a/Crowbar/My Project/AssemblyInfo.vb b/Crowbar/My Project/AssemblyInfo.vb index 9e1426d..d3d5c21 100644 --- a/Crowbar/My Project/AssemblyInfo.vb +++ b/Crowbar/My Project/AssemblyInfo.vb @@ -33,7 +33,7 @@ Imports System.Runtime.InteropServices ' by using the '*' as shown below: ' - - + + \ No newline at end of file From 16a929cbea820cab1b758dabb0f04b2d7b477077 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Fri, 26 Aug 2022 21:17:51 -0400 Subject: [PATCH 11/39] more anim --- .../SourceMdlFileData/SourceMdlAnimation.vb | 16 ++++++++++++++++ .../GameModel/SourceModel53/SourceMdlFile53.vb | 7 ++----- Crowbar/My Project/AssemblyInfo.vb | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb index 73e9438..5a2ef88 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb @@ -32,6 +32,22 @@ Public Class SourceMdlAnimation ' short nextoffset; Public nextSourceMdlAnimationOffset As Short + 'MDL 53 stuff + Public TranslationScale As Double + Public Flags2 As Byte + Public Flags3 As Byte + 'Public OffsetX As Short + 'Public OffsetY As Short + 'Public OffsetZ As Short + 'Public OffsetL As Short + Public TranslationX As SourceFloat16bits + Public TranslationY As SourceFloat16bits + Public TranslationZ As SourceFloat16bits + Public ScaleX As SourceFloat16bits + Public ScaleY As SourceFloat16bits + Public ScaleZ As SourceFloat16bits + Public nextTitanfall2MdlAnimationOffset As Integer + ' Values for the field, flags: '#define STUDIO_ANIM_RAWPOS 0x01 // Vector48 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index e196e42..a84bb17 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1828,7 +1828,7 @@ Public Class SourceMdlFile53 anIkRule.attachmentNameOffset = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To anIkRule.unused.Length - 1 + For x As Integer = 0 To 3 anIkRule.unused(x) = Me.theInputFileReader.ReadInt32() Next @@ -2154,12 +2154,9 @@ Public Class SourceMdlFile53 aSeqDesc.activityModifierCount = 0 aSeqDesc.activityModifierOffset = Me.theInputFileReader.ReadInt32() aSeqDesc.activityModifierCount = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To 4 + For x As Integer = 0 To 9 aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() Next - For x As Integer = 0 To 4 - Me.theInputFileReader.ReadInt32() - Next Me.theMdlFileData.theSequenceDescs.Add(aSeqDesc) diff --git a/Crowbar/My Project/AssemblyInfo.vb b/Crowbar/My Project/AssemblyInfo.vb index 9e1426d..d3d5c21 100644 --- a/Crowbar/My Project/AssemblyInfo.vb +++ b/Crowbar/My Project/AssemblyInfo.vb @@ -33,7 +33,7 @@ Imports System.Runtime.InteropServices ' by using the '*' as shown below: ' - - + + \ No newline at end of file From 8b20d05f7ae9dab19cb5538627387ab356713e59 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Sun, 28 Aug 2022 21:48:44 -0400 Subject: [PATCH 12/39] fix ikchains and add bone flag for later use --- .../SourceModel53/SourceMdlFile53.vb | 22 ++++++++++++------- .../SourceMdlFileData/SourceMdlBone53.vb | 4 ++++ .../SourceMdlFileData/SourceMdlIkChain53.vb | 4 ++-- .../SourceMdlFileData/SourceMdlIkLink53.vb | 2 +- .../GameModel/SourceModel53/SourceQcFile53.vb | 6 ++--- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 60e6550..57e8be0 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -3215,12 +3215,17 @@ Public Class SourceMdlFile53 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.ReadSingle() - anIkChain.unk = 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() + + For j As Integer = 0 To 2 + anIkChain.unk = Me.theInputFileReader.ReadInt32() + Next Me.theMdlFileData.theIkChains.Add(anIkChain) @@ -3267,13 +3272,14 @@ Public Class SourceMdlFile53 'ikLinkInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anIkLink As New SourceMdlIkLink53() anIkLink.boneIndex = Me.theInputFileReader.ReadInt32() - anIkLink.unkVector.x = Me.theInputFileReader.ReadSingle() - anIkLink.unkVector.y = Me.theInputFileReader.ReadSingle() - anIkLink.unkVector.z = Me.theInputFileReader.ReadSingle() + anIkLink.idealBendingDirection.x = Me.theInputFileReader.ReadSingle() + anIkLink.idealBendingDirection.y = Me.theInputFileReader.ReadSingle() + anIkLink.idealBendingDirection.z = Me.theInputFileReader.ReadSingle() anIkLink.unused0.x = Me.theInputFileReader.ReadSingle() anIkLink.unused0.y = Me.theInputFileReader.ReadSingle() anIkLink.unused0.z = Me.theInputFileReader.ReadSingle() anIkChain.theLinks.Add(anIkLink) + anIkChain.theLinks.Add(anIkLink) 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb index deb8700..41abc66 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb @@ -134,6 +134,10 @@ Public Class SourceMdlBone53 '#define BONE_HAS_SAVEFRAME_ROT 0x00400000 Public Const BONE_SCREEN_ALIGN_SPHERE As Integer = &H8 Public Const BONE_SCREEN_ALIGN_CYLINDER As Integer = &H10 + ' No idea on the actual name for this one, but it's applied to all bones with IKLinks and their children. + ' New in V53, CSGO also has a bone flag here, however I am unsure if it's the same. + Public Const BONE_USED_BY_IKCHAIN As Integer = &H20 + Public Const BONE_USED_BY_VERTEX_LOD0 As Integer = &H400 Public Const BONE_USED_BY_VERTEX_LOD1 As Integer = &H800 Public Const BONE_USED_BY_VERTEX_LOD2 As Integer = &H1000 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb index afd4b5b..7ee1a97 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkChain53.vb @@ -22,9 +22,9 @@ Public Class SourceMdlIkChain53 ' int linkindex; Public linkOffset As Integer ' Vector kneeDir; // ideal bending direction (per link, if applicable) - Public idealBendingDirection As New SourceVector() + Public unk As Single ' int - Public unk As New Integer + Public unused(2) As Integer ' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; } Public theName As String diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb index 8550b24..deb4682 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkLink53.vb @@ -18,7 +18,7 @@ Public Class SourceMdlIkLink53 ' int bone; Public boneIndex As Integer ' Vector - Public unkVector As New SourceVector() + Public idealBendingDirection As New SourceVector() ' Vector unused0; // unused Public unused0 As New SourceVector() diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 09db800..638f0bf 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -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).idealBendingDirection.x, 3) - offsetY = Math.Round(Me.theMdlFileData.theIkChains(i).idealBendingDirection.y, 3) - offsetZ = Math.Round(Me.theMdlFileData.theIkChains(i).idealBendingDirection.z, 3) + 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) If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then line = "$IKChain """ From 9ff01c6b74146dc7c188c410fde8a1d7d1648654 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Sun, 28 Aug 2022 23:24:16 -0400 Subject: [PATCH 13/39] add $worldalign (this is actually a csgo thing) --- .../SourceMdlFileData/SourceMdlBone.vb | 1 + .../GameModel/SourceModel49/SourceQcFile49.vb | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlBone.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlBone.vb index ecf69fd..e309e42 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlBone.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlBone.vb @@ -144,6 +144,7 @@ Public Class SourceMdlBone '#define BONE_HAS_SAVEFRAME_ROT 0x00400000 Public Const BONE_SCREEN_ALIGN_SPHERE As Integer = &H8 Public Const BONE_SCREEN_ALIGN_CYLINDER As Integer = &H10 + Public Const BONE_WORLD_ALIGN As Integer = &H20 Public Const BONE_USED_BY_VERTEX_LOD0 As Integer = &H400 Public Const BONE_USED_BY_VERTEX_LOD1 As Integer = &H800 Public Const BONE_USED_BY_VERTEX_LOD2 As Integer = &H1000 diff --git a/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb b/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb index 7dadbb7..4cebd11 100644 --- a/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb +++ b/Crowbar/Core/GameModel/SourceModel49/SourceQcFile49.vb @@ -3973,6 +3973,8 @@ Public Class SourceQcFile49 Me.WriteBoneMergeCommand() Me.WriteLimitRotationCommand() + Me.WriteWorldAlignCommand() + Me.WriteProceduralBonesCommand() Me.WriteJiggleBoneCommand() End Sub @@ -4180,6 +4182,39 @@ Public Class SourceQcFile49 End If End Sub + Private Sub WriteWorldAlignCommand() + Dim line As String = "" + + ' used in CS:GO + '$worldalign "ValveBiped.Bip01_R_Hand" + If Me.theMdlFileData.theBones IsNot Nothing Then + Dim aBone As SourceMdlBone + Dim emptyLineIsAlreadyWritten As Boolean + + emptyLineIsAlreadyWritten = False + For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 + aBone = Me.theMdlFileData.theBones(i) + + If (aBone.flags And SourceMdlBone.BONE_WORLD_ALIGN) > 0 Then + If Not emptyLineIsAlreadyWritten Then + Me.theOutputFileStreamWriter.WriteLine() + emptyLineIsAlreadyWritten = True + End If + + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + line = "$WorldAlign " + Else + line = "$worldalign " + End If + line += """" + line += aBone.theName + line += """" + Me.theOutputFileStreamWriter.WriteLine(line) + End If + Next + End If + End Sub + Private Sub WriteJiggleBoneCommand() If Me.theMdlFileData.theBones Is Nothing Then Return From 1d13fd682cc61e7d70166a92351ee04d7101e41b Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Mon, 29 Aug 2022 00:23:47 -0400 Subject: [PATCH 14/39] removed duplicate line --- Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb | 1 - 1 file changed, 1 deletion(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 57e8be0..409697e 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -3279,7 +3279,6 @@ Public Class SourceMdlFile53 anIkLink.unused0.y = Me.theInputFileReader.ReadSingle() anIkLink.unused0.z = Me.theInputFileReader.ReadSingle() anIkChain.theLinks.Add(anIkLink) - anIkChain.theLinks.Add(anIkLink) 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position From 8a49963ba621961f5c03543d8ada64925aa57507 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Tue, 30 Aug 2022 15:46:57 -0400 Subject: [PATCH 15/39] add exporting some extra data even if it can't be used --- .../SourceMdlFileData/SourceMdlBone52.vb | 5 +++ .../SourceModel53/SourceMdlFile53.vb | 2 +- .../SourceMdlFileData/SourceMdlBone53.vb | 3 +- .../GameModel/SourceModel53/SourceQcFile53.vb | 45 +++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb index aa150a2..c2277f1 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb @@ -131,6 +131,11 @@ Public Class SourceMdlBone52 '#define BONE_HAS_SAVEFRAME_ROT 0x00400000 Public Const BONE_SCREEN_ALIGN_SPHERE As Integer = &H8 Public Const BONE_SCREEN_ALIGN_CYLINDER As Integer = &H10 + + ' No idea on the actual name for this one, but it's applied to all bones with IKLinks and their children. + ' New in V52, CSGO also has a bone flag here, however I don't know if it's the same. + Public Const BONE_USED_BY_IKCHAIN As Integer = &H20 + Public Const BONE_USED_BY_VERTEX_LOD0 As Integer = &H400 Public Const BONE_USED_BY_VERTEX_LOD1 As Integer = &H800 Public Const BONE_USED_BY_VERTEX_LOD2 As Integer = &H1000 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index a9b39e6..57e0d32 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -3198,7 +3198,7 @@ Public Class SourceMdlFile53 'anIkChain.idealBendingDirection.z = Me.theInputFileReader.ReadSingle() For j As Integer = 0 To 2 - anIkChain.unk = Me.theInputFileReader.ReadInt32() + anIkChain.unused(j) = Me.theInputFileReader.ReadInt32() Next Me.theMdlFileData.theIkChains.Add(anIkChain) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb index 41abc66..a993693 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb @@ -134,8 +134,9 @@ Public Class SourceMdlBone53 '#define BONE_HAS_SAVEFRAME_ROT 0x00400000 Public Const BONE_SCREEN_ALIGN_SPHERE As Integer = &H8 Public Const BONE_SCREEN_ALIGN_CYLINDER As Integer = &H10 + ' No idea on the actual name for this one, but it's applied to all bones with IKLinks and their children. - ' New in V53, CSGO also has a bone flag here, however I am unsure if it's the same. + ' New in V52, CSGO also has a bone flag here, however I don't know if it's the same. Public Const BONE_USED_BY_IKCHAIN As Integer = &H20 Public Const BONE_USED_BY_VERTEX_LOD0 As Integer = &H400 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 4ad60f7..60e1343 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -2804,6 +2804,8 @@ Public Class SourceQcFile53 Private Sub WriteIkChainCommand() Dim line As String = "" + Dim lineComment As String = "" + Dim unkFloat As Double Dim offsetX As Double Dim offsetY As Double Dim offsetZ As Double @@ -2819,11 +2821,19 @@ Public Class SourceQcFile53 Me.theOutputFileStreamWriter.WriteLine(line) 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 + + unkFloat = Math.Round(Me.theMdlFileData.theIkChains(i).unk, 3) + 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) + lineComment = "// extra float value " + lineComment += unkFloat.ToString("0.######", TheApp.InternalNumberFormat) + Me.theOutputFileStreamWriter.WriteLine(lineComment) + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then line = "$IKChain """ Else @@ -3313,6 +3323,8 @@ Public Class SourceQcFile53 Me.WriteProceduralBonesCommand() Me.WriteJiggleBoneCommand() + + Me.WriteIkFlagInfo() End Sub Private Sub WriteDefineBoneCommand() @@ -3726,6 +3738,39 @@ Public Class SourceQcFile53 line += "angle_constraint " line += MathModule.RadiansToDegrees(aBone.theJiggleBone.angleLimit).ToString("0.######", TheApp.InternalNumberFormat) Me.theOutputFileStreamWriter.WriteLine(line) + Me.theOutputFileStreamWriter.WriteLine() + End If + End Sub + + Public Sub WriteIkFlagInfo() + Dim lineHeader As String = "" + Dim line As String = "" + + If Me.theMdlFileData.theBones IsNot Nothing Then + 'lineHeader = "// bones using flag 0x20" + 'Me.theOutputFileStreamWriter.WriteLine(lineHeader) + + Dim aBone As SourceMdlBone53 + Dim emptyLineIsAlreadyWritten As Boolean + + emptyLineIsAlreadyWritten = False + For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 + aBone = Me.theMdlFileData.theBones(i) + + If (aBone.flags And SourceMdlBone53.BONE_USED_BY_IKCHAIN) > 0 Then + If Not emptyLineIsAlreadyWritten Then + Me.theOutputFileStreamWriter.WriteLine() + emptyLineIsAlreadyWritten = True + End If + + line = "// bone " + line += """" + line += aBone.theName + line += """" + line += " has ik flag (0x20)" + Me.theOutputFileStreamWriter.WriteLine(line) + End If + Next End If End Sub From 77d33651c888b8217b82cd09c25c546b7ec95ce5 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Wed, 31 Aug 2022 16:57:47 -0400 Subject: [PATCH 16/39] add aabb header, and comments --- .../SourceMdlFileData/RSourceAABBHeader52.vb | 10 ++++++ .../GameModel/SourceModel52/SourceQcFile52.vb | 35 +++++++++++++++++++ .../SourceModel53/SourceMdlFile53.vb | 34 ++++++++++++++++-- .../SourceMdlFileData/SourceMdlFileData53.vb | 5 +-- .../GameModel/SourceModel53/SourceModel53.vb | 11 +++--- Crowbar/Crowbar.vbproj | 1 + 6 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb new file mode 100644 index 0000000..61fa991 --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb @@ -0,0 +1,10 @@ +Public Class RSourceAABBHeader52 + + Public version As Integer + + Public bbMin As SourceVector + Public bbMax As SourceVector + + Public unused(7) As Integer + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb index fdffc19..849501f 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb @@ -3595,6 +3595,8 @@ Public Class SourceQcFile52 Me.WriteProceduralBonesCommand() Me.WriteJiggleBoneCommand() + + Me.WriteIkFlagInfo() End Sub Private Sub WriteDefineBoneCommand() @@ -3953,10 +3955,43 @@ Public Class SourceQcFile52 End If line = "}" Me.theOutputFileStreamWriter.WriteLine(line) + Me.theOutputFileStreamWriter.WriteLine() End If Next End Sub + Public Sub WriteIkFlagInfo() + Dim lineHeader As String = "" + Dim line As String = "" + + If Me.theMdlFileData.theBones IsNot Nothing Then + 'lineHeader = "// bones using flag 0x20" + 'Me.theOutputFileStreamWriter.WriteLine(lineHeader) + + Dim aBone As SourceMdlBone52 + Dim emptyLineIsAlreadyWritten As Boolean + + emptyLineIsAlreadyWritten = False + For i As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 + aBone = Me.theMdlFileData.theBones(i) + + If (aBone.flags And SourceMdlBone52.BONE_USED_BY_IKCHAIN) > 0 Then + If Not emptyLineIsAlreadyWritten Then + Me.theOutputFileStreamWriter.WriteLine() + emptyLineIsAlreadyWritten = True + End If + + line = "// bone " + line += """" + line += aBone.theName + line += """" + line += " has ik flag (0x20)" + Me.theOutputFileStreamWriter.WriteLine(line) + End If + Next + End If + End Sub + Private Sub WriteJiggleBoneConstraints(ByVal aBone As SourceMdlBone52) Dim line As String = "" diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 57e0d32..4fb9cc8 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -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.ReadSingle() + Me.theMdlFileData.fadeDistance = Me.theInputFileReader.ReadSingle() Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.flexControllerUiOffset = Me.theInputFileReader.ReadInt32() @@ -294,7 +294,7 @@ Public Class SourceMdlFile53 'Me.theMdlFileData.vertAnimFixedPointScale = Me.theInputFileReader.ReadSingle() 'Me.theMdlFileData.surfacePropLookup = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknownOffset01 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.aabbOffset = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.unknown01 = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.unknown02 = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.unknown03 = Me.theInputFileReader.ReadInt32() @@ -4039,6 +4039,36 @@ Public Class SourceMdlFile53 End If End Sub + ' TODO: this doesn't actually work lol. + Public Sub ReadAABBHeader() + 'Dim inputFileStreamPosition As Long + 'Dim fileOffsetStart As Long + + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.aabbOffset, SeekOrigin.Begin) + 'fileOffsetStart = Me.theInputFileReader.BaseStream.Position + + Dim theAABB As New RSourceAABBHeader52 + + theAABB.version = Me.theInputFileReader.ReadInt32() + + theAABB.bbMin = New SourceVector() + theAABB.bbMin.x = Me.theInputFileReader.ReadSingle() + theAABB.bbMin.y = Me.theInputFileReader.ReadSingle() + theAABB.bbMin.z = Me.theInputFileReader.ReadSingle() + + theAABB.bbMax = New SourceVector() + theAABB.bbMax.x = Me.theInputFileReader.ReadSingle() + theAABB.bbMax.y = Me.theInputFileReader.ReadSingle() + theAABB.bbMax.z = Me.theInputFileReader.ReadSingle() + + For k As Integer = 0 To 7 + theAABB.unused(k) = Me.theInputFileReader.ReadInt32() + Next + + 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + + End Sub + 'Public Sub ReadFinalBytesAlignment() ' Me.theMdlFileData.theFileSeekLog.LogAndAlignFromFileSeekLogEnd(Me.theInputFileReader, 4, "Final bytes alignment") 'End Sub diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index 16923de..2550e57 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -513,7 +513,7 @@ ' byte unused[1]; Public unused As Byte ' int unused4; // zero out if version < 47 - Public unkfloat As Single + Public fadeDistance As Single ' int numflexcontrollerui; Public flexControllerUiCount As Integer @@ -541,7 +541,7 @@ ' Both V52 and V53 have this section. ' Related to some block that appears when linear bone data is not present. - Public unknownOffset01 As Integer + Public aabbOffset As Integer Public unknown01 As Integer Public unknown02 As Integer Public unknown03 As Integer @@ -594,6 +594,7 @@ Public theSurfacePropName As String Public theTexturePaths As List(Of String) Public theTextures As List(Of SourceMdlTexture) + Public theAABB As RSourceAABBHeader52 Public theSectionFrameCount As Integer Public theSectionFrameMinFrameCount As Integer diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index 41b552d..845c569 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -350,9 +350,6 @@ Public Class SourceModel53 mdlFile.ReadMdlHeader00("MDL File Header 00") mdlFile.ReadMdlHeader01("MDL File Header 01") - 'If Me.theMdlFileData.studioHeader2Offset > 0 Then - ' mdlFile.ReadMdlHeader02("MDL File Header 02") - 'End If mdlFile.ReadBones() mdlFile.ReadBoneControllers() @@ -379,9 +376,9 @@ Public Class SourceModel53 'NOTE: Read flex descs before body parts so that flexes (within body parts) can add info to flex descs. mdlFile.ReadFlexDescs() mdlFile.ReadBodyParts() - mdlFile.ReadFlexControllers() + '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.ReadFlexRules() mdlFile.ReadIkChains() 'mdlFile.ReadIkLocks() 'mdlFile.ReadMouths() @@ -390,7 +387,7 @@ Public Class SourceModel53 ''TODO: Me.ReadAnimBlocks() ''TODO: Me.ReadAnimBlockName() - 'NOTE: V53 MDLs shouldn't really have more than one texture path due to how RPak materials work. + 'NOTE: V53 MDLs normally don't have more than one texture path due to how RPak materials work. mdlFile.ReadTexturePaths() 'NOTE: ReadTextures must be after ReadTexturePaths(), so it can compare with the texture paths. mdlFile.ReadTextures() @@ -401,6 +398,8 @@ Public Class SourceModel53 mdlFile.ReadBoneTransforms() mdlFile.ReadLinearBoneTable() + mdlFile.ReadAABBHeader() + ''TODO: ReadLocalIkAutoPlayLocks() 'mdlFile.ReadFlexControllerUis() diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 9dbb690..00abd83 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -127,6 +127,7 @@ + From ef0745272d56e2af9efe7706f6f086ca83a6a0f5 Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Wed, 31 Aug 2022 17:43:42 -0400 Subject: [PATCH 17/39] Progress on MDL 53 animation decompiling -- Anim values decompiled now. --- .../SourceMdlFileData/SourceMdlAnimation.vb | 3 + .../SourceGlobal/SourceQuaternion64bits.vb | 18 ++ .../SourceModel53/SourceMdlFile53.vb | 45 ++- .../SourceModel53/SourceSmdFile53.vb | 291 ++++++++++-------- 4 files changed, 221 insertions(+), 136 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb index 5a2ef88..1105f7d 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb @@ -62,6 +62,9 @@ Public Class SourceMdlAnimation Public Const STUDIO_ANIM_ANIMROT As Integer = &H8 Public Const STUDIO_ANIM_DELTA As Integer = &H10 Public Const STUDIO_ANIM_RAWROT2 As Integer = &H20 + 'MDL 53 values for flags: + Public Const MDL53_ANIM_TRANSLATION As Integer = &H2 + Public Const MDL53_ANIM_ROTATION As Integer = &H4 ' Do not use union, because it will have to rely on size of a .NET Framework data type. diff --git a/Crowbar/Core/GameModel/SourceGlobal/SourceQuaternion64bits.vb b/Crowbar/Core/GameModel/SourceGlobal/SourceQuaternion64bits.vb index 0f68799..92e495e 100644 --- a/Crowbar/Core/GameModel/SourceGlobal/SourceQuaternion64bits.vb +++ b/Crowbar/Core/GameModel/SourceGlobal/SourceQuaternion64bits.vb @@ -230,4 +230,22 @@ Public Class SourceQuaternion64bits Public s As Single End Structure + Public ReadOnly Property XOffset() As UInt16 + Get + Return BitConverter.ToUInt16(Me.theBytes, 0) + End Get + End Property + + Public ReadOnly Property YOffset() As UInt16 + Get + Return BitConverter.ToUInt16(Me.theBytes, 2) + End Get + End Property + + Public ReadOnly Property ZOffset() As UInt16 + Get + Return BitConverter.ToUInt16(Me.theBytes, 4) + End Get + End Property + End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 60ed918..9d1ae1f 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1315,8 +1315,8 @@ Public Class SourceMdlFile53 Dim animationInputFileStreamPosition As Long Dim nextAnimationInputFileStreamPosition As Long 'Dim animValuePointerInputFileStreamPosition As Long - 'Dim rotValuePointerInputFileStreamPosition As Long - 'Dim posValuePointerInputFileStreamPosition As Long + Dim rotValuePointerInputFileStreamPosition As Long + Dim posValuePointerInputFileStreamPosition As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long Dim anAnimation As SourceMdlAnimation @@ -1346,9 +1346,11 @@ Public Class SourceMdlFile53 'anAnimation.OffsetY = Me.theInputFileReader.ReadInt16() 'anAnimation.OffsetZ = Me.theInputFileReader.ReadInt16() 'anAnimation.OffsetL = Me.theInputFileReader.ReadInt16() + rotValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position anAnimation.theRot64bits = New SourceQuaternion64bits() anAnimation.theRot64bits.theBytes = Me.theInputFileReader.ReadBytes(8) + posValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position anAnimation.TranslationX = New SourceFloat16bits() anAnimation.TranslationY = New SourceFloat16bits() anAnimation.TranslationZ = New SourceFloat16bits() @@ -1364,7 +1366,6 @@ Public Class SourceMdlFile53 anAnimation.ScaleZ.the16BitValue = Me.theInputFileReader.ReadUInt16() anAnimation.nextTitanfall2MdlAnimationOffset = Me.theInputFileReader.ReadInt32() - 'TODO: Read in rest of struct. 'NOTE: If the offset is 0 then there are no more bone animation structures, so end the loop. If anAnimation.nextTitanfall2MdlAnimationOffset = 0 Then @@ -1377,10 +1378,48 @@ Public Class SourceMdlFile53 Exit For End If + If anAnimation.nextTitanfall2MdlAnimationOffset > 32 Then + If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) = 0 Then + anAnimation.theRotV = New SourceMdlAnimationValuePointer() + If anAnimation.theRot64bits.XOffset > 0 Then + anAnimation.theRotV.theAnimXValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.XOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimXValues, "anAnimation.theRotV.theAnimXValues") + End If + If anAnimation.theRot64bits.YOffset > 0 Then + anAnimation.theRotV.theAnimYValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.YOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimYValues, "anAnimation.theRotV.theAnimYValues") + End If + If anAnimation.theRot64bits.ZOffset > 0 Then + anAnimation.theRotV.theAnimZValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.ZOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimZValues, "anAnimation.theRotV.theAnimZValues") + End If + End If + + If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) = 0 Then + anAnimation.thePosV = New SourceMdlAnimationValuePointer() + If anAnimation.TranslationX.the16BitValue > 0 Then + anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationX.the16BitValue, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + End If + If anAnimation.TranslationY.the16BitValue > 0 Then + anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationY.the16BitValue, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + End If + If anAnimation.TranslationZ.the16BitValue > 0 Then + anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationZ.the16BitValue, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + End If + End If + End If + Me.theInputFileReader.BaseStream.Seek(nextAnimationInputFileStreamPosition, SeekOrigin.Begin) End If Next + 'NOTE: There is always an unused empty data structure at the end of the list. + fileOffsetStart = Me.theInputFileReader.BaseStream.Position + Me.theInputFileReader.ReadBytes(32) + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] (boneChangeCount = " + CStr(boneChangeCount) + ")") diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 538bcd5..1dd2653 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -398,10 +398,17 @@ Public Class SourceSmdFile53 boneIndex = Me.theAnimationFrameLines.Keys(i) aFrameLine = Me.theAnimationFrameLines.Values(i) + 'position = aFrameLine.position + 'rotation = aFrameLine.rotation + '------ Dim adjustedPosition As New SourceVector() Dim adjustedRotation As New SourceVector() - Me.AdjustPositionAndRotationByPiecewiseMovement(frameIndex, boneIndex, anAnimationDesc.theMovements, aFrameLine.position, aFrameLine.rotation, adjustedPosition, adjustedRotation) - Me.AdjustPositionAndRotation(boneIndex, adjustedPosition, adjustedRotation, position, rotation) + Me.AdjustPositionAndRotation(boneIndex, aFrameLine.position, aFrameLine.rotation, position, rotation) + '------ + 'Dim adjustedPosition As New SourceVector() + 'Dim adjustedRotation As New SourceVector() + 'Me.AdjustPositionAndRotationByPiecewiseMovement(frameIndex, boneIndex, anAnimationDesc.theMovements, aFrameLine.position, aFrameLine.rotation, adjustedPosition, adjustedRotation) + 'Me.AdjustPositionAndRotation(boneIndex, adjustedPosition, adjustedRotation, position, rotation) line = " " line += boneIndex.ToString(TheApp.InternalNumberFormat) @@ -458,15 +465,15 @@ Public Class SourceSmdFile53 ' oPosition.y = iPosition.y + aFirstAnimationDescFrameLine.position.y ' oPosition.z = iPosition.z + aFirstAnimationDescFrameLine.position.z 'Else - If aBone.parentBoneIndex = -1 Then - oPosition.x = iPosition.y - oPosition.y = -iPosition.x - oPosition.z = iPosition.z - Else - oPosition.x = iPosition.x - oPosition.y = iPosition.y - oPosition.z = iPosition.z - End If + 'If aBone.parentBoneIndex = -1 Then + ' oPosition.x = iPosition.y + ' oPosition.y = -iPosition.x + ' oPosition.z = iPosition.z + 'Else + oPosition.x = iPosition.x + oPosition.y = iPosition.y + oPosition.z = iPosition.z + 'End If 'If iRotation.debug_text = "desc_delta" OrElse iRotation.debug_text.StartsWith("delta") Then ' Dim aFirstAnimationDescFrameLine As AnimationFrameLine @@ -499,15 +506,33 @@ Public Class SourceSmdFile53 ' oRotation.y = tempRotation.z ' oRotation.z = tempRotation.x 'Else - If aBone.parentBoneIndex = -1 Then - oRotation.x = iRotation.x - oRotation.y = iRotation.y - oRotation.z = iRotation.z + MathModule.DegreesToRadians(-90) - Else - oRotation.x = iRotation.x - oRotation.y = iRotation.y - oRotation.z = iRotation.z - End If + 'If aBone.parentBoneIndex = -1 Then + ' oRotation.x = iRotation.x + ' oRotation.y = iRotation.y + ' oRotation.z = iRotation.z + MathModule.DegreesToRadians(-90) + 'Else + ' oRotation.x = iRotation.x + ' oRotation.y = iRotation.y + ' oRotation.z = iRotation.z + 'End If + '------ + oRotation.x = iRotation.x + oRotation.y = iRotation.y + oRotation.z = iRotation.z + '------ + 'oRotation.x = iRotation.y + 'oRotation.y = iRotation.x + 'oRotation.z = iRotation.z + '------ + 'If aBone.parentBoneIndex = -1 Then + ' oRotation.x = iRotation.x + ' oRotation.y = iRotation.y + ' oRotation.z = iRotation.z + 'Else + ' oRotation.x = iRotation.y + ' oRotation.y = iRotation.x + ' oRotation.z = iRotation.z + 'End If End Sub Private Sub AdjustPositionAndRotationByPiecewiseMovement(ByVal frameIndex As Integer, ByVal boneIndex As Integer, ByVal movements As List(Of SourceMdlMovement), ByVal iPosition As SourceVector, ByVal iRotation As SourceVector, ByRef oPosition As SourceVector, ByRef oRotation As SourceVector) @@ -1205,8 +1230,8 @@ Public Class SourceSmdFile53 Dim aBone As SourceMdlBone53 Dim aWeight As Double Dim anAnimation As SourceMdlAnimation - Dim rot As SourceQuaternion - 'Dim pos As SourceVector + Dim rot As SourceVector + Dim pos As SourceVector Dim aFrameLine As AnimationFrameLine Dim sectionFrameIndex As Integer @@ -1254,41 +1279,53 @@ Public Class SourceSmdFile53 aFrameLine.rotationQuat = New SourceQuaternion() - 'rot = CalcBoneRotation(sectionFrameIndex, s, aBone, anAnimation, aFrameLine.rotationQuat) - Dim angleVector As New SourceVector() - If (anAnimation.flags And &H4) > 0 Then - rot = New SourceQuaternion() - rot.x = anAnimation.theRot64bits.x - rot.y = anAnimation.theRot64bits.y - rot.z = anAnimation.theRot64bits.z - rot.w = anAnimation.theRot64bits.w - angleVector = MathModule.ToEulerAngles(rot) - angleVector.debug_text = "raw64 (" + rot.x.ToString() + ", " + rot.y.ToString() + ", " + rot.z.ToString() + ", " + rot.w.ToString() + ")" - Else - angleVector.x = aBone.rotation.x - angleVector.y = aBone.rotation.y - angleVector.z = aBone.rotation.z - angleVector.debug_text = "bone" - End If + rot = CalcBoneRotation(sectionFrameIndex, s, aBone, anAnimation, aFrameLine.rotationQuat) aFrameLine.rotation = New SourceVector() - aFrameLine.rotation.x = angleVector.x - aFrameLine.rotation.y = angleVector.y - aFrameLine.rotation.z = angleVector.z - aFrameLine.rotation.debug_text = angleVector.debug_text - - 'pos = Me.CalcBonePosition(sectionFrameIndex, s, aBone, anAnimation) + aFrameLine.rotation.x = rot.x + aFrameLine.rotation.y = rot.y + aFrameLine.rotation.z = rot.z + aFrameLine.rotation.debug_text = rot.debug_text + '------ + 'Dim angleVector As New SourceVector() + 'If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) > 0 Then + ' rot = New SourceQuaternion() + ' rot.x = anAnimation.theRot64bits.x + ' rot.y = anAnimation.theRot64bits.y + ' rot.z = anAnimation.theRot64bits.z + ' rot.w = anAnimation.theRot64bits.w + ' angleVector = MathModule.ToEulerAngles(rot) + ' angleVector.debug_text = "raw64 (" + rot.x.ToString() + ", " + rot.y.ToString() + ", " + rot.z.ToString() + ", " + rot.w.ToString() + ")" + 'Else + ' angleVector.x = aBone.rotation.x + ' angleVector.y = aBone.rotation.y + ' angleVector.z = aBone.rotation.z + ' angleVector.debug_text = "bone" + 'End If + 'aFrameLine.rotation = New SourceVector() + 'aFrameLine.rotation.x = angleVector.x + 'aFrameLine.rotation.y = angleVector.y + 'aFrameLine.rotation.z = angleVector.z + 'aFrameLine.rotation.debug_text = angleVector.debug_text + + pos = Me.CalcBonePosition(sectionFrameIndex, s, aBone, anAnimation) aFrameLine.position = New SourceVector() - If (anAnimation.flags And &H2) > 0 Then - aFrameLine.position.x = anAnimation.TranslationX.TheFloatValue - aFrameLine.position.y = anAnimation.TranslationY.TheFloatValue - aFrameLine.position.z = anAnimation.TranslationZ.TheFloatValue - aFrameLine.position.debug_text = "anim" - Else - aFrameLine.position.x = aBone.position.x - aFrameLine.position.y = aBone.position.y - aFrameLine.position.z = aBone.position.z - aFrameLine.position.debug_text = "bone" - End If + aFrameLine.position.x = pos.x + aFrameLine.position.y = pos.y + aFrameLine.position.z = pos.z + aFrameLine.position.debug_text = pos.debug_text + '------ + 'aFrameLine.position = New SourceVector() + 'If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) > 0 Then + ' aFrameLine.position.x = anAnimation.TranslationX.TheFloatValue + ' aFrameLine.position.y = anAnimation.TranslationY.TheFloatValue + ' aFrameLine.position.z = anAnimation.TranslationZ.TheFloatValue + ' aFrameLine.position.debug_text = "anim" + 'Else + ' aFrameLine.position.x = aBone.position.x + ' aFrameLine.position.y = aBone.position.y + ' aFrameLine.position.z = aBone.position.z + ' aFrameLine.position.debug_text = "bone" + 'End If End If animIndex += 1 @@ -1528,7 +1565,7 @@ Public Class SourceSmdFile53 Dim rot As New SourceQuaternion() Dim angleVector As New SourceVector() - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT2) > 0 Then + If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) > 0 Then rot.x = anAnimation.theRot64bits.x rot.y = anAnimation.theRot64bits.y rot.z = anAnimation.theRot64bits.z @@ -1543,16 +1580,37 @@ Public Class SourceSmdFile53 Return angleVector End If - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMROT) = 0 Then - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then - angleVector.x = 0 - angleVector.y = 0 - angleVector.z = 0 - rotationQuat.x = 0 - rotationQuat.y = 0 - rotationQuat.z = 0 - rotationQuat.w = 0 - angleVector.debug_text = "delta" + Try + If anAnimation.theRotV IsNot Nothing Then + Dim rotV As SourceMdlAnimationValuePointer = anAnimation.theRotV + If anAnimation.theRot64bits.XOffset <= 0 Then + angleVector.x = 0 + Else + angleVector.x = Me.ExtractAnimValue(frameIndex, rotV.theAnimXValues, aBone.rotationScale.x) + angleVector.x += aBone.rotation.x + End If + If anAnimation.theRot64bits.YOffset <= 0 Then + angleVector.y = 0 + Else + angleVector.y = Me.ExtractAnimValue(frameIndex, rotV.theAnimYValues, aBone.rotationScale.y) + angleVector.y += aBone.rotation.y + End If + If anAnimation.theRot64bits.ZOffset <= 0 Then + angleVector.z = 0 + Else + angleVector.z = Me.ExtractAnimValue(frameIndex, rotV.theAnimZValues, aBone.rotationScale.z) + angleVector.z += aBone.rotation.z + End If + angleVector.debug_text = "anim" + 'ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then + ' angleVector.x = 0 + ' angleVector.y = 0 + ' angleVector.z = 0 + ' rotationQuat.x = 0 + ' rotationQuat.y = 0 + ' rotationQuat.z = 0 + ' rotationQuat.w = 0 + ' angleVector.debug_text = "delta" Else angleVector.x = aBone.rotation.x angleVector.y = aBone.rotation.y @@ -1563,15 +1621,9 @@ Public Class SourceSmdFile53 rotationQuat.w = 0 angleVector.debug_text = "bone" End If - Return angleVector - End If - - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) = 0 Then - angleVector.x += aBone.rotation.x - angleVector.y += aBone.rotation.y - angleVector.z += aBone.rotation.z - angleVector.debug_text += "+bone" - End If + Catch ex As Exception + Dim debug As Integer = 4242 + End Try rotationQuat = MathModule.EulerAnglesToQuaternion(angleVector) Return angleVector @@ -1639,72 +1691,45 @@ Public Class SourceSmdFile53 Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation) As SourceVector Dim pos As New SourceVector() - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS) > 0 Then - 'If aBone.parentBoneIndex = -1 Then - ' pos.x = anAnimation.thePos.y - ' pos.y = -anAnimation.thePos.x - ' pos.z = anAnimation.thePos.z - 'Else - pos.x = anAnimation.thePos.x - pos.y = anAnimation.thePos.y - pos.z = anAnimation.thePos.z - ' '------ - ' 'pos.y = anAnimation.thePos.z - ' 'pos.z = anAnimation.thePos.y - ' '------ - ' 'pos.x = anAnimation.thePos.y - ' 'pos.y = -anAnimation.thePos.x - ' 'pos.z = anAnimation.thePos.z - 'End If - + If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) > 0 Then + pos.x = anAnimation.TranslationX.TheFloatValue + pos.y = anAnimation.TranslationY.TheFloatValue + pos.z = anAnimation.TranslationZ.TheFloatValue pos.debug_text = "raw" Return pos - ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_ANIMPOS) = 0 Then - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then + End If + + If anAnimation.thePosV IsNot Nothing Then + Dim posV As SourceMdlAnimationValuePointer = anAnimation.thePosV + If anAnimation.TranslationX.the16BitValue <= 0 Then pos.x = 0 + Else + pos.x = Me.ExtractAnimValue(frameIndex, posV.theAnimXValues, anAnimation.TranslationScale) + pos.x += aBone.position.x + End If + If anAnimation.TranslationY.the16BitValue <= 0 Then pos.y = 0 + Else + pos.y = Me.ExtractAnimValue(frameIndex, posV.theAnimYValues, anAnimation.TranslationScale) + pos.y += aBone.position.y + End If + If anAnimation.TranslationZ.the16BitValue <= 0 Then pos.z = 0 - pos.debug_text = "delta" Else - pos.x = aBone.position.x - pos.y = aBone.position.y - pos.z = aBone.position.z - 'pos.y = aBone.positionZ - 'pos.z = -aBone.positionY - pos.debug_text = "bone" + pos.z = Me.ExtractAnimValue(frameIndex, posV.theAnimZValues, anAnimation.TranslationScale) + pos.z += aBone.position.z End If - Return pos - End If - - Dim posV As SourceMdlAnimationValuePointer - - posV = anAnimation.thePosV - - If posV.animXValueOffset <= 0 Then - pos.x = 0 + pos.debug_text = "anim" + 'ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then + ' pos.x = 0 + ' pos.y = 0 + ' pos.z = 0 + ' pos.debug_text = "delta" Else - pos.x = Me.ExtractAnimValue(frameIndex, posV.theAnimXValues, aBone.positionScale.x) - End If - - If posV.animYValueOffset <= 0 Then - pos.y = 0 - Else - pos.y = Me.ExtractAnimValue(frameIndex, posV.theAnimYValues, aBone.positionScale.y) - End If - - If posV.animZValueOffset <= 0 Then - pos.z = 0 - Else - pos.z = Me.ExtractAnimValue(frameIndex, posV.theAnimZValues, aBone.positionScale.z) - End If - - pos.debug_text = "anim" - - If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) = 0 Then - pos.x += aBone.position.x - pos.y += aBone.position.y - pos.z += aBone.position.z - pos.debug_text += "+bone" + pos.x = aBone.position.x + pos.y = aBone.position.y + pos.z = aBone.position.z + pos.debug_text = "bone" End If Return pos From c679f48398fef5e28cd5638fac6b4ea06220cdb7 Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Wed, 31 Aug 2022 19:21:46 -0400 Subject: [PATCH 18/39] Fix size of ikrule struct. --- .../GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb index aa6ffad..e55c1cc 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb @@ -87,7 +87,7 @@ Public Class SourceMdlIkRule Public attachmentNameOffset As Integer - Public unused(6) As Integer + Public unused(3) As Integer From 60c2c58f28ee430d00706cb423c50a4df8a87141 Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Wed, 31 Aug 2022 19:23:51 -0400 Subject: [PATCH 19/39] Fix reading of empty struct at end of list of SourceMdlAnimation. Fix the writing of log for some anim data. --- .../SourceModel53/SourceMdlFile53.vb | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 9d1ae1f..bf57692 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1028,7 +1028,7 @@ Public Class SourceMdlFile53 Me.ReadMdlAnimation(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, anAnimationDesc.theSectionsOfAnimations(0), True) 'If anAnimationDesc.animBlock = 0 Then - ' Me.ReadMdlIkRules(animInputFileStreamPosition, anAnimationDesc) + Me.ReadMdlIkRules(animInputFileStreamPosition, anAnimationDesc) ' Me.ReadLocalHierarchies(animInputFileStreamPosition, anAnimationDesc) 'End If @@ -1325,7 +1325,7 @@ Public Class SourceMdlFile53 Dim boneChangeCount As Integer Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition, SeekOrigin.Begin) - fileOffsetStart = Me.theInputFileReader.BaseStream.Position + 'fileOffsetStart = Me.theInputFileReader.BaseStream.Position boneCount = Me.theMdlFileData.theBones.Count boneChangeCount = 0 @@ -1367,8 +1367,12 @@ Public Class SourceMdlFile53 anAnimation.nextTitanfall2MdlAnimationOffset = Me.theInputFileReader.ReadInt32() + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(animationInputFileStreamPosition, fileOffsetEnd, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] (boneIndex = " + CStr(anAnimation.boneIndex) + ")") + 'NOTE: If the offset is 0 then there are no more bone animation structures, so end the loop. If anAnimation.nextTitanfall2MdlAnimationOffset = 0 Then + ReadMdlAnimationAnimValues(anAnimation, rotValuePointerInputFileStreamPosition, posValuePointerInputFileStreamPosition, sectionFrameCount, lastSectionIsBeingRead) Exit For Else nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + anAnimation.nextTitanfall2MdlAnimationOffset @@ -1379,37 +1383,7 @@ Public Class SourceMdlFile53 End If If anAnimation.nextTitanfall2MdlAnimationOffset > 32 Then - If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) = 0 Then - anAnimation.theRotV = New SourceMdlAnimationValuePointer() - If anAnimation.theRot64bits.XOffset > 0 Then - anAnimation.theRotV.theAnimXValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.XOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimXValues, "anAnimation.theRotV.theAnimXValues") - End If - If anAnimation.theRot64bits.YOffset > 0 Then - anAnimation.theRotV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.YOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimYValues, "anAnimation.theRotV.theAnimYValues") - End If - If anAnimation.theRot64bits.ZOffset > 0 Then - anAnimation.theRotV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.ZOffset, sectionFrameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimZValues, "anAnimation.theRotV.theAnimZValues") - End If - End If - - If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) = 0 Then - anAnimation.thePosV = New SourceMdlAnimationValuePointer() - If anAnimation.TranslationX.the16BitValue > 0 Then - anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationX.the16BitValue, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") - End If - If anAnimation.TranslationY.the16BitValue > 0 Then - anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationY.the16BitValue, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") - End If - If anAnimation.TranslationZ.the16BitValue > 0 Then - anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationZ.the16BitValue, sectionFrameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") - End If - End If + ReadMdlAnimationAnimValues(anAnimation, rotValuePointerInputFileStreamPosition, posValuePointerInputFileStreamPosition, sectionFrameCount, lastSectionIsBeingRead) End If Me.theInputFileReader.BaseStream.Seek(nextAnimationInputFileStreamPosition, SeekOrigin.Begin) @@ -1419,13 +1393,46 @@ Public Class SourceMdlFile53 'NOTE: There is always an unused empty data structure at the end of the list. fileOffsetStart = Me.theInputFileReader.BaseStream.Position Me.theInputFileReader.ReadBytes(32) - fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] (boneChangeCount = " + CStr(boneChangeCount) + ")") + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] (Empty last struct; boneChangeCount = " + CStr(boneChangeCount) + ")") 'Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] alignment") End Sub + Private Sub ReadMdlAnimationAnimValues(ByVal anAnimation As SourceMdlAnimation, ByVal rotValuePointerInputFileStreamPosition As Long, ByVal posValuePointerInputFileStreamPosition As Long, ByVal frameCount As Integer, ByVal lastSectionIsBeingRead As Boolean) + If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) = 0 Then + anAnimation.theRotV = New SourceMdlAnimationValuePointer() + If anAnimation.theRot64bits.XOffset > 0 Then + anAnimation.theRotV.theAnimXValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.XOffset, frameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimXValues, "anAnimation.theRotV.theAnimXValues") + End If + If anAnimation.theRot64bits.YOffset > 0 Then + anAnimation.theRotV.theAnimYValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.YOffset, frameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimYValues, "anAnimation.theRotV.theAnimYValues") + End If + If anAnimation.theRot64bits.ZOffset > 0 Then + anAnimation.theRotV.theAnimZValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(rotValuePointerInputFileStreamPosition + anAnimation.theRot64bits.ZOffset, frameCount, lastSectionIsBeingRead, anAnimation.theRotV.theAnimZValues, "anAnimation.theRotV.theAnimZValues") + End If + End If + + If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) = 0 Then + anAnimation.thePosV = New SourceMdlAnimationValuePointer() + If anAnimation.TranslationX.the16BitValue > 0 Then + anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationX.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + End If + If anAnimation.TranslationY.the16BitValue > 0 Then + anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationY.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + End If + If anAnimation.TranslationZ.the16BitValue > 0 Then + anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationZ.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + End If + End If + End Sub + '========================================================== 'FROM: SourceEngine2007_source\utils\studiomdl\simplify.cpp ' Section within: static void CompressAnimations( ). From 8d7ff8e6988b335c97261da16c9fe2f0e32ef5fb Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Wed, 31 Aug 2022 19:27:39 -0400 Subject: [PATCH 20/39] fixes v52 bone --- .../SourceModel52/SourceMdlFile52.vb | 55 ++++++++++++++----- .../SourceMdlFileData/SourceMdlBone52.vb | 7 ++- .../SourceModel53/SourceMdlFile53.vb | 2 +- .../SourceMdlFileData/SourceMdlBone53.vb | 2 +- Crowbar/Crowbar.vbproj | 2 +- CrowbarLauncher/CrowbarLauncher.vbproj | 2 +- CrowbarSteamPipe/CrowbarSteamPipe.vbproj | 2 +- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 4826c76..8c533c2 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -394,12 +394,10 @@ Public Class SourceMdlFile52 aBone.rotation.x = Me.theInputFileReader.ReadSingle() aBone.rotation.y = Me.theInputFileReader.ReadSingle() aBone.rotation.z = Me.theInputFileReader.ReadSingle() - - aBone.unkVector = New SourceVector() - aBone.unkVector.x = Me.theInputFileReader.ReadSingle() - aBone.unkVector.y = Me.theInputFileReader.ReadSingle() - aBone.unkVector.z = Me.theInputFileReader.ReadSingle() - + aBone.positionScale = New SourceVector() + aBone.positionScale.x = Me.theInputFileReader.ReadSingle() + aBone.positionScale.y = Me.theInputFileReader.ReadSingle() + aBone.positionScale.z = Me.theInputFileReader.ReadSingle() aBone.rotationScale = New SourceVector() aBone.rotationScale.x = Me.theInputFileReader.ReadSingle() aBone.rotationScale.y = Me.theInputFileReader.ReadSingle() @@ -429,20 +427,44 @@ Public Class SourceMdlFile52 aBone.qAlignment.w = Me.theInputFileReader.ReadSingle() aBone.flags = Me.theInputFileReader.ReadInt32() + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD0) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD1) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD2) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD3) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD4) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD5) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD6) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If + 'If (aBone.flags And SourceMdlBone.BONE_USED_BY_VERTEX_LOD7) <> 0 Then + ' Dim debug As Integer = 4242 + 'End If aBone.proceduralRuleType = Me.theInputFileReader.ReadInt32() aBone.proceduralRuleOffset = Me.theInputFileReader.ReadInt32() aBone.physicsBoneIndex = Me.theInputFileReader.ReadInt32() aBone.surfacePropNameOffset = Me.theInputFileReader.ReadInt32() aBone.contents = Me.theInputFileReader.ReadInt32() + aBone.surfacepropLookup = Me.theInputFileReader.ReadInt32() - aBone.unk = Me.theInputFileReader.ReadInt32() - - aBone.positionScale = New SourceVector() - aBone.positionScale.x = Me.theInputFileReader.ReadSingle() - aBone.positionScale.y = Me.theInputFileReader.ReadSingle() - aBone.positionScale.z = Me.theInputFileReader.ReadSingle() + 'If Me.theMdlFileData.version <> 2531 Then + aBone.unkVector = New SourceVector() + aBone.unkVector.x = Me.theInputFileReader.ReadSingle() + aBone.unkVector.y = Me.theInputFileReader.ReadSingle() + aBone.unkVector.z = Me.theInputFileReader.ReadSingle() aBone.unkVector1 = New SourceVector() aBone.unkVector1.x = Me.theInputFileReader.ReadSingle() aBone.unkVector1.y = Me.theInputFileReader.ReadSingle() @@ -450,6 +472,9 @@ Public Class SourceMdlFile52 aBone.unused = Me.theInputFileReader.ReadInt32() + 'End If + 'End If + Me.theMdlFileData.theBones.Add(aBone) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position @@ -468,12 +493,12 @@ Public Class SourceMdlFile52 aBone.theName = "" End If If aBone.proceduralRuleOffset <> 0 Then - If aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_AXISINTERP Then + If aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_AXISINTERP Then Me.ReadAxisInterpBone(boneInputFileStreamPosition, aBone) - ElseIf aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_QUATINTERP Then + ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_QUATINTERP Then Me.theMdlFileData.theProceduralBonesCommandIsUsed = True Me.ReadQuatInterpBone(boneInputFileStreamPosition, aBone) - ElseIf aBone.proceduralRuleType = SourceMdlBone52.STUDIO_PROC_JIGGLE Then + ElseIf aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_JIGGLE Then Me.ReadJiggleBone(boneInputFileStreamPosition, aBone) End If End If diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb index aa150a2..89a1e6b 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb @@ -1,4 +1,5 @@ Public Class SourceMdlBone52 + 'Inherits SourceMdlBone 'FROM: SourceEngineXXXX_source\public\studio.h '// bones @@ -55,7 +56,7 @@ Public Class SourceMdlBone52 ' RadianEuler rot; Public rotation As SourceVector ' Vector - Public unkVector As SourceVector + Public positionScale As SourceVector ' Vector rotscale; Public rotationScale As SourceVector @@ -81,9 +82,9 @@ Public Class SourceMdlBone52 ' int contents; // See BSPFlags.h for the contents flags Public contents As Integer ' int surfacepropLookup; (this is in normal V49s) - Public unk As Integer + Public surfacepropLookup As Integer ' Vector posscale; - Public positionScale As SourceVector + Public unkVector As SourceVector ' Vector Public unkVector1 As SourceVector diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 409697e..fbafffb 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -414,8 +414,8 @@ Public Class SourceMdlFile53 aBone.physicsBoneIndex = Me.theInputFileReader.ReadInt32() aBone.surfacePropNameOffset = Me.theInputFileReader.ReadInt32() aBone.contents = Me.theInputFileReader.ReadInt32() + aBone.surfacepropLookup = Me.theInputFileReader.ReadInt32() - aBone.unk = Me.theInputFileReader.ReadInt32() aBone.unk1 = Me.theInputFileReader.ReadInt32() For k As Integer = 0 To 6 diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb index 41abc66..959509a 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlBone53.vb @@ -86,7 +86,7 @@ Public Class SourceMdlBone53 ' int contents; // See BSPFlags.h for the contents flags Public contents As Integer ' int surfacepropLookup; (this is in normal V49s) - Public unk As Integer + Public surfacepropLookup As Integer ' int unknown offset for something. Public unk1 As Integer diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 49a49dd..dc44a69 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -13,7 +13,7 @@ WindowsFormsWithCustomSubMain On Resources\crowbar_icon.ico - v4.0 + v4.8 diff --git a/CrowbarLauncher/CrowbarLauncher.vbproj b/CrowbarLauncher/CrowbarLauncher.vbproj index dcbdbc4..0cd21b7 100644 --- a/CrowbarLauncher/CrowbarLauncher.vbproj +++ b/CrowbarLauncher/CrowbarLauncher.vbproj @@ -11,7 +11,7 @@ CrowbarLauncher 512 WindowsFormsWithCustomSubMain - v4.0 + v4.8 true diff --git a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj index fadfb6b..c4ef19b 100644 --- a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj +++ b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj @@ -11,7 +11,7 @@ CrowbarSteamPipe 512 Console - v4.0 + v4.8 true From 506766d9fd28bb1c1ecf5e9ed062e6d457a513bb Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Wed, 31 Aug 2022 20:53:40 -0400 Subject: [PATCH 21/39] fade distance v52 --- Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb | 2 +- .../SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 8c533c2..32a5198 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -263,7 +263,7 @@ Public Class SourceMdlFile52 Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte() - Me.theMdlFileData.unkFloat = Me.theInputFileReader.ReadSingle() + Me.theMdlFileData.fadeDistance = Me.theInputFileReader.ReadSingle() Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.flexControllerUiOffset = Me.theInputFileReader.ReadInt32() diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb index 0967ea7..9f66afa 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb @@ -517,7 +517,7 @@ ' byte unused[1]; Public unused As Byte ' int unused4; // zero out if version < 47 - Public unkFloat As Single + Public fadeDistance As Single ' int numflexcontrollerui; Public flexControllerUiCount As Integer From 809cf3bec0fc561215c74e1c649d17a071837e77 Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Thu, 1 Sep 2022 05:52:49 -0400 Subject: [PATCH 22/39] FIXED: MDL53 animation position xyz from "anim values" are all read into x. --- Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index bf57692..bfb57b5 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1424,11 +1424,11 @@ Public Class SourceMdlFile53 End If If anAnimation.TranslationY.the16BitValue > 0 Then anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationY.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationY.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimYValues, "anAnimation.thePosV.theAnimYValues") End If If anAnimation.TranslationZ.the16BitValue > 0 Then anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationZ.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationZ.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimZValues, "anAnimation.thePosV.theAnimZValues") End If End If End Sub From a86bcc9a610ee9374294afd47b93b1bfa9dc124d Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Thu, 1 Sep 2022 10:30:19 -0400 Subject: [PATCH 23/39] Adjust MDL53 anim rotation to match MDL52 example model, ogre_titan. --- .../SourceModel53/SourceSmdFile53.vb | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 1dd2653..7ad95c2 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -465,15 +465,15 @@ Public Class SourceSmdFile53 ' oPosition.y = iPosition.y + aFirstAnimationDescFrameLine.position.y ' oPosition.z = iPosition.z + aFirstAnimationDescFrameLine.position.z 'Else - 'If aBone.parentBoneIndex = -1 Then - ' oPosition.x = iPosition.y - ' oPosition.y = -iPosition.x - ' oPosition.z = iPosition.z - 'Else - oPosition.x = iPosition.x - oPosition.y = iPosition.y - oPosition.z = iPosition.z - 'End If + If aBone.parentBoneIndex = -1 Then + oPosition.x = iPosition.y + oPosition.y = -iPosition.x + oPosition.z = iPosition.z + Else + oPosition.x = iPosition.x + oPosition.y = iPosition.y + oPosition.z = iPosition.z + End If 'If iRotation.debug_text = "desc_delta" OrElse iRotation.debug_text.StartsWith("delta") Then ' Dim aFirstAnimationDescFrameLine As AnimationFrameLine @@ -516,23 +516,23 @@ Public Class SourceSmdFile53 ' oRotation.z = iRotation.z 'End If '------ - oRotation.x = iRotation.x - oRotation.y = iRotation.y - oRotation.z = iRotation.z + 'oRotation.x = iRotation.x + 'oRotation.y = iRotation.y + 'oRotation.z = iRotation.z '------ 'oRotation.x = iRotation.y 'oRotation.y = iRotation.x 'oRotation.z = iRotation.z '------ - 'If aBone.parentBoneIndex = -1 Then - ' oRotation.x = iRotation.x - ' oRotation.y = iRotation.y - ' oRotation.z = iRotation.z - 'Else - ' oRotation.x = iRotation.y - ' oRotation.y = iRotation.x - ' oRotation.z = iRotation.z - 'End If + If aBone.parentBoneIndex = -1 Then + oRotation.x = iRotation.x + oRotation.y = iRotation.y + oRotation.z = iRotation.z + MathModule.DegreesToRadians(-90) + Else + oRotation.x = iRotation.x + oRotation.y = iRotation.y + oRotation.z = iRotation.z + End If End Sub Private Sub AdjustPositionAndRotationByPiecewiseMovement(ByVal frameIndex As Integer, ByVal boneIndex As Integer, ByVal movements As List(Of SourceMdlMovement), ByVal iPosition As SourceVector, ByVal iRotation As SourceVector, ByRef oPosition As SourceVector, ByRef oRotation As SourceVector) @@ -1794,6 +1794,7 @@ Public Class SourceSmdFile53 v1 = animValues(animValueIndex + animValues(animValueIndex).valid).value * scale End If Catch ex As Exception + Dim debug As Integer = 4242 End Try Return v1 From 166d0fdfaa6ea6aae831ade2dcaf9540e987ed09 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Fri, 2 Sep 2022 23:10:49 -0400 Subject: [PATCH 24/39] minor changes --- .../SourceMdlFileData/SourceMdlIkRule.vb | 2 +- .../SourceModel52/SourceMdlFile52.vb | 18 +- .../SourceMdlAnimationDesc52.vb | 4 +- .../SourceMdlFileData/SourceMdlBone52.vb | 4 +- .../SourceModel53/SourceMdlFile53.vb | 63 +++--- .../SourceMdlAnimationDesc53.vb | 205 ++++++++++++++++++ .../SourceMdlFileData/SourceMdlFileData53.vb | 4 +- .../SourceMdlFileData/SourceMdlIkRule53.vb | 109 ++++++++++ .../GameModel/SourceModel53/SourceModel53.vb | 2 +- .../GameModel/SourceModel53/SourceQcFile53.vb | 30 +-- .../SourceModel53/SourceSmdFile53.vb | 10 +- Crowbar/Crowbar.vbproj | 4 +- CrowbarLauncher/CrowbarLauncher.vbproj | 2 +- CrowbarSteamPipe/CrowbarSteamPipe.vbproj | 2 +- 14 files changed, 385 insertions(+), 74 deletions(-) create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkRule53.vb diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb index e55c1cc..aa6ffad 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb @@ -87,7 +87,7 @@ Public Class SourceMdlIkRule Public attachmentNameOffset As Integer - Public unused(3) As Integer + Public unused(6) As Integer diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 4826c76..600bc86 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -395,10 +395,10 @@ Public Class SourceMdlFile52 aBone.rotation.y = Me.theInputFileReader.ReadSingle() aBone.rotation.z = Me.theInputFileReader.ReadSingle() - aBone.unkVector = New SourceVector() - aBone.unkVector.x = Me.theInputFileReader.ReadSingle() - aBone.unkVector.y = Me.theInputFileReader.ReadSingle() - aBone.unkVector.z = Me.theInputFileReader.ReadSingle() + aBone.positionScale = New SourceVector() + aBone.positionScale.x = Me.theInputFileReader.ReadSingle() + aBone.positionScale.y = Me.theInputFileReader.ReadSingle() + aBone.positionScale.z = Me.theInputFileReader.ReadSingle() aBone.rotationScale = New SourceVector() aBone.rotationScale.x = Me.theInputFileReader.ReadSingle() @@ -438,10 +438,10 @@ Public Class SourceMdlFile52 aBone.unk = Me.theInputFileReader.ReadInt32() - aBone.positionScale = New SourceVector() - aBone.positionScale.x = Me.theInputFileReader.ReadSingle() - aBone.positionScale.y = Me.theInputFileReader.ReadSingle() - aBone.positionScale.z = Me.theInputFileReader.ReadSingle() + aBone.unkVector = New SourceVector() + aBone.unkVector.x = Me.theInputFileReader.ReadSingle() + aBone.unkVector.y = Me.theInputFileReader.ReadSingle() + aBone.unkVector.z = Me.theInputFileReader.ReadSingle() aBone.unkVector1 = New SourceVector() aBone.unkVector1.x = Me.theInputFileReader.ReadSingle() @@ -970,6 +970,8 @@ Public Class SourceMdlFile52 anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.compressedIkErrorOffset = Me.theInputFileReader.ReadInt32() + For x As Integer = 0 To anAnimationDesc.unused1.Length - 1 anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() Next diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlAnimationDesc52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlAnimationDesc52.vb index 6466c01..27a5e79 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlAnimationDesc52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlAnimationDesc52.vb @@ -89,8 +89,10 @@ Public Class SourceMdlAnimationDesc52 ' mstudioikrulezeroframe_t *pIKRuleZeroFrame( int i ) const { if (ikrulezeroframeindex) return (mstudioikrulezeroframe_t *)(((byte *)this) + ikrulezeroframeindex) + i; else return NULL; }; Public ikRuleZeroFrameOffset As Integer + Public compressedIkErrorOffset As Integer + ' int unused1[5]; // remove as appropriate (and zero if loading older versions) - Public unused1(4) As Integer + Public unused1(3) As Integer ' int animblock; Public animBlock As Integer diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb index aa150a2..eada9f0 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlBone52.vb @@ -55,7 +55,7 @@ Public Class SourceMdlBone52 ' RadianEuler rot; Public rotation As SourceVector ' Vector - Public unkVector As SourceVector + Public positionScale As SourceVector ' Vector rotscale; Public rotationScale As SourceVector @@ -83,7 +83,7 @@ Public Class SourceMdlBone52 ' int surfacepropLookup; (this is in normal V49s) Public unk As Integer ' Vector posscale; - Public positionScale As SourceVector + Public unkVector As SourceVector ' Vector Public unkVector1 As SourceVector diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index bfb57b5..6d47c9d 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -926,10 +926,10 @@ Public Class SourceMdlFile53 fileOffsetStart = Me.theInputFileReader.BaseStream.Position Try - Me.theMdlFileData.theAnimationDescs = New List(Of SourceMdlAnimationDesc52)(Me.theMdlFileData.localAnimationCount) + Me.theMdlFileData.theAnimationDescs = New List(Of SourceMdlAnimationDesc53)(Me.theMdlFileData.localAnimationCount) For i As Integer = 0 To Me.theMdlFileData.localAnimationCount - 1 animInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim anAnimationDesc As New SourceMdlAnimationDesc52() + Dim anAnimationDesc As New SourceMdlAnimationDesc53() anAnimationDesc.theOffsetStart = Me.theInputFileReader.BaseStream.Position @@ -941,11 +941,11 @@ Public Class SourceMdlFile53 anAnimationDesc.movementCount = Me.theInputFileReader.ReadInt32() anAnimationDesc.movementOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.animBlock = Me.theInputFileReader.ReadInt32() + anAnimationDesc.compressedIkErrorOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.animOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() anAnimationDesc.ikRuleOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.animblockIkRuleOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.localHierarchyCount = Me.theInputFileReader.ReadInt32() anAnimationDesc.localHierarchyOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.sectionOffset = Me.theInputFileReader.ReadInt32() @@ -953,10 +953,10 @@ Public Class SourceMdlFile53 anAnimationDesc.spanFrameCount = Me.theInputFileReader.ReadInt16() anAnimationDesc.spanCount = Me.theInputFileReader.ReadInt16() - 'anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() - 'anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() + anAnimationDesc.spanOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() - anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() + 'anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() For x As Integer = 0 To anAnimationDesc.unused1.Length - 1 anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() @@ -981,7 +981,7 @@ Public Class SourceMdlFile53 Public Sub ReadAnimationSections() If Me.theMdlFileData.theAnimationDescs IsNot Nothing Then - For Each anAnimationDesc As SourceMdlAnimationDesc52 In Me.theMdlFileData.theAnimationDescs + For Each anAnimationDesc As SourceMdlAnimationDesc53 In Me.theMdlFileData.theAnimationDescs If anAnimationDesc.sectionOffset <> 0 AndAlso anAnimationDesc.sectionFrameCount > 0 Then Dim sectionCount As Integer @@ -1010,7 +1010,7 @@ Public Class SourceMdlFile53 Public Sub ReadAnimationMdlBlocks() If Me.theMdlFileData.theAnimationDescs IsNot Nothing Then Dim animInputFileStreamPosition As Long - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 Dim aSectionOfAnimation As List(Of SourceMdlAnimation) For anAnimDescIndex As Integer = 0 To Me.theMdlFileData.theAnimationDescs.Count - 1 @@ -1037,7 +1037,7 @@ Public Class SourceMdlFile53 End If End Sub - Protected Sub ReadAnimationDescName(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Sub ReadAnimationDescName(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) If anAnimationDesc.nameOffset <> 0 Then Dim fileOffsetStart As Long Dim fileOffsetEnd As Long @@ -1063,7 +1063,7 @@ Public Class SourceMdlFile53 End If End Sub - Protected Function ReadAnimationDescSpanData(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) As Long + Protected Function ReadAnimationDescSpanData(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long = 0 @@ -1110,7 +1110,7 @@ Public Class SourceMdlFile53 End Function 'TODO: Should this be the same as SourceAniFile49.ReadAniAnimation()? - 'Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation)) + 'Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation)) ' Dim animationInputFileStreamPosition As Long ' 'Dim inputFileStreamPosition As Long ' 'Dim fileOffsetStart As Long @@ -1143,7 +1143,7 @@ Public Class SourceMdlFile53 ' 'Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.anAnimation [ReadAnimationFrameByBone()] alignment") 'End Sub '====== - Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal sectionFrameCount As Integer, ByVal sectionIndex As Integer, ByVal lastSectionIsBeingRead As Boolean) + Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal sectionFrameCount As Integer, ByVal sectionIndex As Integer, ByVal lastSectionIsBeingRead As Boolean) Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition, SeekOrigin.Begin) Dim animFrameInputFileStreamPosition As Long @@ -1311,7 +1311,7 @@ Public Class SourceMdlFile53 End Try End Sub - Protected Sub ReadMdlAnimation(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation), ByVal lastSectionIsBeingRead As Boolean) + Protected Sub ReadMdlAnimation(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal sectionFrameCount As Integer, ByVal aSectionOfAnimation As List(Of SourceMdlAnimation), ByVal lastSectionIsBeingRead As Boolean) Dim animationInputFileStreamPosition As Long Dim nextAnimationInputFileStreamPosition As Long 'Dim animValuePointerInputFileStreamPosition As Long @@ -1646,7 +1646,7 @@ Public Class SourceMdlFile53 'End Sub - Protected Sub ReadMdlIkRules(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Sub ReadMdlIkRules(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) If anAnimationDesc.ikRuleCount > 0 Then Dim ikRuleInputFileStreamPosition As Long Dim inputFileStreamPosition As Long @@ -1658,19 +1658,15 @@ Public Class SourceMdlFile53 Dim fileOffsetOfLastEndOfIkRuleExtraData As Long - If anAnimationDesc.animBlock > 0 AndAlso anAnimationDesc.animblockIkRuleOffset = 0 Then - 'Return 0 - Else - Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition + anAnimationDesc.ikRuleOffset, SeekOrigin.Begin) - End If + Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition + anAnimationDesc.ikRuleOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position fileOffsetOfLastEndOfIkRuleExtraData = 0 - anAnimationDesc.theIkRules = New List(Of SourceMdlIkRule)(anAnimationDesc.ikRuleCount) + anAnimationDesc.theIkRules = New List(Of SourceMdlIkRule53)(anAnimationDesc.ikRuleCount) For ikRuleIndex As Integer = 0 To anAnimationDesc.ikRuleCount - 1 ikRuleInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim anIkRule As New SourceMdlIkRule() + Dim anIkRule As New SourceMdlIkRule53() anIkRule.index = Me.theInputFileReader.ReadInt32() anIkRule.type = Me.theInputFileReader.ReadInt32() @@ -1693,7 +1689,7 @@ Public Class SourceMdlFile53 anIkRule.q.w = Me.theInputFileReader.ReadSingle() anIkRule.compressedIkErrorOffset = Me.theInputFileReader.ReadInt32() - anIkRule.unused2 = Me.theInputFileReader.ReadInt32() + anIkRule.ikErrorIndexStart = Me.theInputFileReader.ReadInt32() anIkRule.ikErrorOffset = Me.theInputFileReader.ReadInt32() @@ -1702,15 +1698,10 @@ Public Class SourceMdlFile53 anIkRule.influenceTail = Me.theInputFileReader.ReadSingle() anIkRule.influenceEnd = Me.theInputFileReader.ReadSingle() - anIkRule.unused3 = Me.theInputFileReader.ReadSingle() anIkRule.contact = Me.theInputFileReader.ReadSingle() anIkRule.drop = Me.theInputFileReader.ReadSingle() anIkRule.top = Me.theInputFileReader.ReadSingle() - anIkRule.unused6 = Me.theInputFileReader.ReadInt32() - anIkRule.unused7 = Me.theInputFileReader.ReadInt32() - anIkRule.unused8 = Me.theInputFileReader.ReadInt32() - anIkRule.attachmentNameOffset = Me.theInputFileReader.ReadInt32() For x As Integer = 0 To anIkRule.unused.Length - 1 @@ -1767,9 +1758,7 @@ Public Class SourceMdlFile53 fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Dim description As String description = "anAnimationDesc.theIkRules " + anAnimationDesc.theIkRules.Count.ToString() - If anAnimationDesc.animBlock > 0 AndAlso anAnimationDesc.animblockIkRuleOffset = 0 Then - description += " [animblockIkRuleOffset = 0]" - End If + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, description) Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.theIkRules alignment") @@ -1782,8 +1771,8 @@ Public Class SourceMdlFile53 End If End Sub - Private Function ReadCompressedIkErrors(ByVal ikRuleInputFileStreamPosition As Long, ByVal ikRuleIndex As Integer, ByVal anAnimationDesc As SourceMdlAnimationDesc52) As Long - Dim anIkRule As SourceMdlIkRule + Private Function ReadCompressedIkErrors(ByVal ikRuleInputFileStreamPosition As Long, ByVal ikRuleIndex As Integer, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long + Dim anIkRule As SourceMdlIkRule53 anIkRule = anAnimationDesc.theIkRules(ikRuleIndex) Dim compressedIkErrorInputFileStreamPosition As Long @@ -1843,7 +1832,7 @@ Public Class SourceMdlFile53 Return Me.theInputFileReader.BaseStream.Position - 1 End Function - Protected Sub ReadMdlAnimationSection(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal aFileSeekLog As FileSeekLog) + Protected Sub ReadMdlAnimationSection(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal aFileSeekLog As FileSeekLog) 'Dim animSectionInputFileStreamPosition As Long 'Dim inputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -1868,7 +1857,7 @@ Public Class SourceMdlFile53 aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theSections") End Sub - Protected Sub ReadMdlMovements(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Sub ReadMdlMovements(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) If anAnimationDesc.movementCount > 0 Then Dim movementInputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -1905,7 +1894,7 @@ Public Class SourceMdlFile53 End If End Sub - Protected Sub ReadLocalHierarchies(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Protected Sub ReadLocalHierarchies(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) If anAnimationDesc.localHierarchyCount > 0 Then Dim localHieararchyInputFileStreamPosition As Long Dim fileOffsetStart As Long @@ -2018,9 +2007,11 @@ Public Class SourceMdlFile53 aSeqDesc.activityModifierCount = 0 aSeqDesc.activityModifierOffset = Me.theInputFileReader.ReadInt32() aSeqDesc.activityModifierCount = Me.theInputFileReader.ReadInt32() + For x As Integer = 0 To 4 aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() Next + For x As Integer = 0 To 4 Me.theInputFileReader.ReadInt32() Next diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb new file mode 100644 index 0000000..8cd67fa --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimationDesc53.vb @@ -0,0 +1,205 @@ +Public Class SourceMdlAnimationDesc53 + Inherits SourceMdlAnimationDescBase + + Public Sub New() + Me.theLinkedSequences = New List(Of SourceMdlSequenceDesc)() + End Sub + + 'FROM: AlienSwarm_source\src\public\studio.h + 'struct mstudioanimdesc_t + '{ + ' DECLARE_BYTESWAP_DATADESC(); + ' int baseptr; + ' inline studiohdr_t *pStudiohdr( void ) const { return (studiohdr_t *)(((byte *)this) + baseptr); } + ' + ' int sznameindex; + ' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; } + ' + ' float fps; // frames per second + ' int flags; // looping/non-looping flags + ' + ' int numframes; + ' + ' // piecewise movement + ' int nummovements; + ' int movementindex; + ' inline mstudiomovement_t * const pMovement( int i ) const { return (mstudiomovement_t *)(((byte *)this) + movementindex) + i; }; + ' + ' int ikrulezeroframeindex; + ' mstudioikrulezeroframe_t *pIKRuleZeroFrame( int i ) const { if (ikrulezeroframeindex) return (mstudioikrulezeroframe_t *)(((byte *)this) + ikrulezeroframeindex) + i; else return NULL; }; + ' + ' int unused1[5]; // remove as appropriate (and zero if loading older versions) + ' + ' int animblock; + ' int animindex; // non-zero when anim data isn't in sections + ' byte *pAnimBlock( int block, int index ) const; // returns pointer to a specific anim block (local or external) + ' byte *pAnim( int *piFrame, float &flStall ) const; // returns pointer to data and new frame index + ' byte *pAnim( int *piFrame ) const; // returns pointer to data and new frame index + ' + ' int numikrules; + ' int ikruleindex; // non-zero when IK rule is stored in the mdl + ' int animblockikruleindex; // non-zero when IK data is stored in animblock file + ' mstudioikrule_t *pIKRule( int i ) const; + ' + ' int numlocalhierarchy; + ' int localhierarchyindex; + ' mstudiolocalhierarchy_t *pHierarchy( int i ) const; + ' + ' int sectionindex; + ' int sectionframes; // number of frames used in each fast lookup section, zero if not used + ' inline mstudioanimsections_t * const pSection( int i ) const { return (mstudioanimsections_t *)(((byte *)this) + sectionindex) + i; } + ' + ' short zeroframespan; // frames per span + ' short zeroframecount; // number of spans + ' int zeroframeindex; + ' byte *pZeroFrameData( ) const { if (zeroframeindex) return (((byte *)this) + zeroframeindex); else return NULL; }; + ' mutable float zeroframestalltime; // saved during read stalls + ' + ' mstudioanimdesc_t(){} + 'private: + ' // No copy constructors allowed + ' mstudioanimdesc_t(const mstudioanimdesc_t& vOther); + '}; + + 'NOTE: Size of this struct: 100 bytes. + + ' int baseptr; + ' inline studiohdr_t *pStudiohdr( void ) const { return (studiohdr_t *)(((byte *)this) + baseptr); } + Public baseHeaderOffset As Integer + + ' int sznameindex; + Public nameOffset As Integer + + ' float fps; // frames per second + Public fps As Single + ' int flags; // looping/non-looping flags + Public flags As Integer + + ' int numframes; + Public frameCount As Integer + + ' // piecewise movement + ' int nummovements; + Public movementCount As Integer + ' int movementindex; + Public movementOffset As Integer + ' inline mstudiomovement_t * const pMovement( int i ) const { return (mstudiomovement_t *)(((byte *)this) + movementindex) + i; }; + + ' int ikrulezeroframeindex; + ' mstudioikrulezeroframe_t *pIKRuleZeroFrame( int i ) const { if (ikrulezeroframeindex) return (mstudioikrulezeroframe_t *)(((byte *)this) + ikrulezeroframeindex) + i; else return NULL; }; + 'Public ikRuleZeroFrameOffset As Integer + + ' int unused1[5]; // remove as appropriate (and zero if loading older versions) + 'Public unused1(4) As Integer + + ' int animblock; + 'Public animBlock As Integer + + Public compressedIkErrorOffset As Integer + + ' int animindex; // non-zero when anim data isn't in sections + Public animOffset As Integer + ' mstudioanim_t *pAnimBlock( int block, int index ) const; // returns pointer to a specific anim block (local or external) + ' mstudioanim_t *pAnim( int *piFrame, float &flStall ) const; // returns pointer to data and new frame index + ' mstudioanim_t *pAnim( int *piFrame ) const; // returns pointer to data and new frame index + + ' int numikrules; + Public ikRuleCount As Integer + ' int ikruleindex; // non-zero when IK data is stored in the mdl + Public ikRuleOffset As Integer + ' int animblockikruleindex; // non-zero when IK data is stored in animblock file + + ' int numlocalhierarchy; + Public localHierarchyCount As Integer + ' int localhierarchyindex; + Public localHierarchyOffset As Integer + ' mstudiolocalhierarchy_t *pHierarchy( int i ) const; + + ' int sectionindex; + Public sectionOffset As Integer + ' int sectionframes; // number of frames used in each fast lookup section, zero if not used + Public sectionFrameCount As Integer + ' inline mstudioanimsections_t * const pSection( int i ) const { return (mstudioanimsections_t *)(((byte *)this) + sectionindex) + i; } + + ' short zeroframespan; // frames per span + Public spanFrameCount As Short + ' short zeroframecount; // number of spans + Public spanCount As Short + ' int zeroframeindex; + Public spanOffset As Integer + ' byte *pZeroFrameData( ) const { if (zeroframeindex) return (((byte *)this) + zeroframeindex); else return NULL; }; + ' mutable float zeroframestalltime; // saved during read stalls + Public spanStallTime As Single + + Public unused1(4) As Integer + + + ' Moved to SourceMdlAnimationDescBase + '' inline char * const pszName( void ) const { return ((char *)this) + sznameindex; } + 'Public theName As String + + Public theSectionsOfAnimations As List(Of List(Of SourceMdlAnimation)) + Public theSectionsOfFrameAnim As List(Of SourceAniFrameAnim52) + Public theIkRules As List(Of SourceMdlIkRule53) + Public theSections As List(Of SourceMdlAnimationSection) + Public theMovements As List(Of SourceMdlMovement) + Public theLocalHierarchies As List(Of SourceMdlLocalHierarchy) + + Public theAnimIsLinkedToSequence As Boolean + Public theLinkedSequences As List(Of SourceMdlSequenceDesc) + Public theOffsetStart As Long + + + + ' Values for the field, flags: + 'FROM: SourceEngineXXXX_source\public\studio.h + '// sequence and autolayer flags + '#define STUDIO_LOOPING 0x0001 // ending frame should be the same as the starting frame + '#define STUDIO_SNAP 0x0002 // do not interpolate between previous animation and this one + '#define STUDIO_DELTA 0x0004 // this sequence "adds" to the base sequences, not slerp blends + '#define STUDIO_AUTOPLAY 0x0008 // temporary flag that forces the sequence to always play + '#define STUDIO_POST 0x0010 // + '#define STUDIO_ALLZEROS 0x0020 // this animation/sequence has no real animation data + '// 0x0040 + '#define STUDIO_CYCLEPOSE 0x0080 // cycle index is taken from a pose parameter index + '#define STUDIO_REALTIME 0x0100 // cycle index is taken from a real-time clock, not the animations cycle index + '#define STUDIO_LOCAL 0x0200 // sequence has a local context sequence + '#define STUDIO_HIDDEN 0x0400 // don't show in default selection views + '#define STUDIO_OVERRIDE 0x0800 // a forward declared sequence (empty) + '#define STUDIO_ACTIVITY 0x1000 // Has been updated at runtime to activity index + '#define STUDIO_EVENT 0x2000 // Has been updated at runtime to event index + '#define STUDIO_WORLD 0x4000 // sequence blends in worldspace + '------ + 'VERSION 49 + 'FROM: AlienSwarm_source\src\public\studio.h + ' Adds these to the above. + '#define STUDIO_FRAMEANIM 0x0040 // animation is encoded as by frame x bone instead of RLE bone x frame + '#define STUDIO_NOFORCELOOP 0x8000 // do not force the animation loop + '#define STUDIO_EVENT_CLIENT 0x10000 // Has been updated at runtime to event index on client + + + Public Const STUDIO_LOOPING As Integer = &H1 + Public Const STUDIO_SNAP As Integer = &H2 + Public Const STUDIO_DELTA As Integer = &H4 + Public Const STUDIO_AUTOPLAY As Integer = &H8 + Public Const STUDIO_POST As Integer = &H10 + Public Const STUDIO_ALLZEROS As Integer = &H20 + ' &H40 + Public Const STUDIO_CYCLEPOSE As Integer = &H80 + Public Const STUDIO_REALTIME As Integer = &H100 + 'NOTE: STUDIO_LOCAL used internally by studiomdl and not needed by Crowbar. + Public Const STUDIO_LOCAL As Integer = &H200 + Public Const STUDIO_HIDDEN As Integer = &H400 + Public Const STUDIO_OVERRIDE As Integer = &H800 + 'NOTE: STUDIO_ACTIVITY used internally by game engine and not needed by Crowbar. + Public Const STUDIO_ACTIVITY As Integer = &H1000 + 'NOTE: STUDIO_EVENT used internally by game engine and not needed by Crowbar. + Public Const STUDIO_EVENT As Integer = &H2000 + Public Const STUDIO_WORLD As Integer = &H4000 + '------ + 'VERSION 49 + Public Const STUDIO_FRAMEANIM As Integer = &H40 + Public Const STUDIO_NOFORCELOOP As Integer = &H8000 + Public Const STUDIO_EVENT_CLIENT As Integer = &H10000 + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index 1e80b83..16923de 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -569,7 +569,7 @@ 'Public theName As String Public theNameCopy As String - Public theAnimationDescs As List(Of SourceMdlAnimationDesc52) + Public theAnimationDescs As List(Of SourceMdlAnimationDesc53) Public theAnimBlocks As List(Of SourceMdlAnimBlock) Public theAnimBlockRelativePathFileName As String Public theAttachments As List(Of SourceMdlAttachment) @@ -606,7 +606,7 @@ 'Public theUpperEyelidFlexFrameIndexes As List(Of Integer) Public theBoneNameToBoneIndexMap As New SortedList(Of String, Integer)() - Public theFirstAnimationDesc As SourceMdlAnimationDesc52 + Public theFirstAnimationDesc As SourceMdlAnimationDesc53 Public theFirstAnimationDescFrameLines As SortedList(Of Integer, AnimationFrameLine) 'Public theMdlFileOnlyHasAnimations As Boolean Public theProceduralBonesCommandIsUsed As Boolean diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkRule53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkRule53.vb new file mode 100644 index 0000000..ec7f6be --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlIkRule53.vb @@ -0,0 +1,109 @@ +Public Class SourceMdlIkRule53 + + 'FROM: SourceEngine2006+_source\public\studio.h + 'struct mstudioikrule_t + '{ + ' DECLARE_BYTESWAP_DATADESC(); + ' int index; + + ' int type; + ' int chain; + + ' int bone; + + ' int slot; // iktarget slot. Usually same as chain. + ' float height; + ' float radius; + ' float floor; + ' Vector pos; + ' Quaternion q; + + ' int compressedikerrorindex; + ' inline mstudiocompressedikerror_t *pCompressedError() const { return (mstudiocompressedikerror_t *)(((byte *)this) + compressedikerrorindex); }; + ' int unused2; + + ' int iStart; + ' int ikerrorindex; + ' inline mstudioikerror_t *pError( int i ) const { return (ikerrorindex) ? (mstudioikerror_t *)(((byte *)this) + ikerrorindex) + (i - iStart) : NULL; }; + + ' float start; // beginning of influence + ' float peak; // start of full influence + ' float tail; // end of full influence + ' float end; // end of all influence + + ' float unused3; // + ' float contact; // frame footstep makes ground concact + ' float drop; // how far down the foot should drop when reaching for IK + ' float top; // top of the foot box + + ' int unused6; + ' int unused7; + ' int unused8; + + ' int szattachmentindex; // name of world attachment + ' inline char * const pszAttachment( void ) const { return ((char *)this) + szattachmentindex; } + + ' int unused[7]; + + ' mstudioikrule_t() {} + + 'private: + ' // No copy constructors allowed + ' mstudioikrule_t(const mstudioikrule_t& vOther); + '}; + + + + Public index As Integer + Public type As Integer + Public chain As Integer + Public bone As Integer + + Public slot As Integer + Public height As Double + Public radius As Double + Public floor As Double + Public pos As SourceVector + Public q As SourceQuaternion + + Public compressedIkErrorOffset As Integer + + Public ikErrorIndexStart As Integer + Public ikErrorOffset As Integer + + Public influenceStart As Double + Public influencePeak As Double + Public influenceTail As Double + Public influenceEnd As Double + + Public contact As Double + Public drop As Double + Public top As Double + + Public attachmentNameOffset As Integer + + Public unused(8) As Integer + + + + Public theAttachmentName As String + Public theCompressedIkError As SourceMdlCompressedIkError + + + + ' For the 'type' field: + 'FROM: se2007_src\src_main\public\studio.h + '#define IK_SELF 1 + '#define IK_WORLD 2 + '#define IK_GROUND 3 + '#define IK_RELEASE 4 + '#define IK_ATTACHMENT 5 + '#define IK_UNLATCH 6 + Public Const IK_SELF As Integer = 1 + Public Const IK_WORLD As Integer = 2 + Public Const IK_GROUND As Integer = 3 + Public Const IK_RELEASE As Integer = 4 + Public Const IK_ATTACHMENT As Integer = 5 + Public Const IK_UNLATCH As Integer = 6 + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index 96f93a7..41b552d 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -191,7 +191,7 @@ Public Class SourceModel53 Public Overrides Function WriteBoneAnimationSmdFiles(ByVal modelOutputPath As String) As AppEnums.StatusMessage Dim status As AppEnums.StatusMessage = StatusMessage.Success - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 Dim smdPath As String 'Dim smdFileName As String Dim smdPathFileName As String diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 09db800..f4e6aff 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -2104,7 +2104,7 @@ Public Class SourceQcFile53 Private Sub WriteAnimationOrDeclareAnimationCommand() If Me.theMdlFileData.theAnimationDescs IsNot Nothing Then For i As Integer = 0 To Me.theMdlFileData.theAnimationDescs.Count - 1 - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 anAnimationDesc = Me.theMdlFileData.theAnimationDescs(i) If anAnimationDesc.theName(0) <> "@" Then @@ -2114,7 +2114,7 @@ Public Class SourceQcFile53 End If End Sub - Private Sub WriteAnimationLine(ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Private Sub WriteAnimationLine(ByVal anAnimationDesc As SourceMdlAnimationDesc53) Dim line As String = "" Me.theOutputFileStreamWriter.WriteLine() @@ -2242,9 +2242,9 @@ Public Class SourceQcFile53 Private Sub WriteSequenceOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc) Dim line As String = "" Dim valueString As String - Dim impliedAnimDesc As SourceMdlAnimationDesc52 = Nothing + Dim impliedAnimDesc As SourceMdlAnimationDesc53 = Nothing - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 Dim name As String For j As Integer = 0 To aSequenceDesc.theAnimDescIndexes.Count - 1 anAnimationDesc = Me.theMdlFileData.theAnimationDescs(aSequenceDesc.theAnimDescIndexes(j)) @@ -2405,7 +2405,7 @@ Public Class SourceQcFile53 ' Me.theOutputFileStreamWriter.WriteLine(line) 'End If - Dim firstAnimDesc As SourceMdlAnimationDesc52 + Dim firstAnimDesc As SourceMdlAnimationDesc53 firstAnimDesc = Me.theMdlFileData.theAnimationDescs(aSequenceDesc.theAnimDescIndexes(0)) Me.WriteAnimationOptions(aSequenceDesc, firstAnimDesc, impliedAnimDesc) End Sub @@ -2432,7 +2432,7 @@ Public Class SourceQcFile53 'ParseCmdlistToken( panim->numcmds, panim->cmds ) 'TODO: All these options (LX, LY, etc.) seem to be baked-in, but might need to be calculated for anims that have movement. 'lookupControl( token ) - Private Sub WriteAnimationOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal impliedAnimDesc As SourceMdlAnimationDesc52) + Private Sub WriteAnimationOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal impliedAnimDesc As SourceMdlAnimationDesc53) Dim line As String = "" line = vbTab @@ -2484,17 +2484,17 @@ Public Class SourceQcFile53 'weightlist // done 'worldspaceblend // 'worldspaceblendloop // - Private Sub WriteCmdListOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal impliedAnimDesc As SourceMdlAnimationDesc52) + Private Sub WriteCmdListOptions(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal impliedAnimDesc As SourceMdlAnimationDesc53) Dim line As String = "" If anAnimationDesc.theIkRules IsNot Nothing Then - For Each anIkRule As SourceMdlIkRule In anAnimationDesc.theIkRules + For Each anIkRule As SourceMdlIkRule53 In anAnimationDesc.theIkRules line = vbTab line += "ikrule" line += " """ line += Me.theMdlFileData.theIkChains(anIkRule.chain).theName line += """" - If anIkRule.type = SourceMdlIkRule.IK_SELF Then + If anIkRule.type = SourceMdlIkRule53.IK_SELF Then line += " " line += "touch" line += " """ @@ -2502,22 +2502,22 @@ Public Class SourceQcFile53 line += Me.theMdlFileData.theBones(anIkRule.bone).theName End If line += """" - 'ElseIf anIkRule.type = SourceMdlIkRule.IK_WORLD Then + 'ElseIf anIkRule.type = SourceMdlIkRule53.IK_WORLD Then 'line += " " 'line += "world" - ElseIf anIkRule.type = SourceMdlIkRule.IK_GROUND Then + ElseIf anIkRule.type = SourceMdlIkRule53.IK_GROUND Then line += " " line += "footstep" - ElseIf anIkRule.type = SourceMdlIkRule.IK_RELEASE Then + ElseIf anIkRule.type = SourceMdlIkRule53.IK_RELEASE Then line += " " line += "release" - ElseIf anIkRule.type = SourceMdlIkRule.IK_ATTACHMENT Then + ElseIf anIkRule.type = SourceMdlIkRule53.IK_ATTACHMENT Then line += " " line += "attachment" line += " """ line += anIkRule.theAttachmentName line += """" - ElseIf anIkRule.type = SourceMdlIkRule.IK_UNLATCH Then + ElseIf anIkRule.type = SourceMdlIkRule53.IK_UNLATCH Then line += " " line += "unlatch" End If @@ -2760,7 +2760,7 @@ Public Class SourceQcFile53 End If End Sub - Private Sub WriteCmdListLocalHierarchyOption(ByVal anAnimationDesc As SourceMdlAnimationDesc52) + Private Sub WriteCmdListLocalHierarchyOption(ByVal anAnimationDesc As SourceMdlAnimationDesc53) Dim line As String = "" If anAnimationDesc.theLocalHierarchies IsNot Nothing Then diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 7ad95c2..823d363 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -310,7 +310,7 @@ Public Class SourceSmdFile53 Dim aFrameLine As AnimationFrameLine Dim frameIndex As Integer Dim aSequenceDesc As SourceMdlSequenceDesc - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 aSequenceDesc = Nothing anAnimationDesc = Me.theMdlFileData.theFirstAnimationDesc @@ -370,10 +370,10 @@ Public Class SourceSmdFile53 Dim rotation As New SourceVector() 'Dim tempRotation As New SourceVector() Dim aSequenceDesc As SourceMdlSequenceDesc - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 aSequenceDesc = CType(aSequenceDescBase, SourceMdlSequenceDesc) - anAnimationDesc = CType(anAnimationDescBase, SourceMdlAnimationDesc52) + anAnimationDesc = CType(anAnimationDescBase, SourceMdlAnimationDesc53) 'skeleton line = "skeleton" @@ -594,7 +594,7 @@ Public Class SourceSmdFile53 Dim frameIndex As Integer Dim frameLineIndex As Integer Dim aSequenceDesc As SourceMdlSequenceDesc - Dim anAnimationDesc As SourceMdlAnimationDesc52 + Dim anAnimationDesc As SourceMdlAnimationDesc53 aSequenceDesc = Nothing anAnimationDesc = Me.theMdlFileData.theAnimationDescs(0) @@ -1224,7 +1224,7 @@ Public Class SourceSmdFile53 Return aVectorTransformed End Function - Private Sub CalcAnimation(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc52, ByVal frameIndex As Integer) + Private Sub CalcAnimation(ByVal aSequenceDesc As SourceMdlSequenceDesc, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal frameIndex As Integer) Dim s As Double Dim animIndex As Integer Dim aBone As SourceMdlBone53 diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 49a49dd..b81f081 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -13,7 +13,7 @@ WindowsFormsWithCustomSubMain On Resources\crowbar_icon.ico - v4.0 + v4.8 @@ -128,9 +128,11 @@ + + diff --git a/CrowbarLauncher/CrowbarLauncher.vbproj b/CrowbarLauncher/CrowbarLauncher.vbproj index dcbdbc4..0cd21b7 100644 --- a/CrowbarLauncher/CrowbarLauncher.vbproj +++ b/CrowbarLauncher/CrowbarLauncher.vbproj @@ -11,7 +11,7 @@ CrowbarLauncher 512 WindowsFormsWithCustomSubMain - v4.0 + v4.8 true diff --git a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj index fadfb6b..c4ef19b 100644 --- a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj +++ b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj @@ -11,7 +11,7 @@ CrowbarSteamPipe 512 Console - v4.0 + v4.8 true From 1a5a86515d4b26e2290d77335b7edb3e69c6e7b0 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Sat, 3 Sep 2022 01:32:12 -0400 Subject: [PATCH 25/39] merge cleanup --- .../SourceModel53/SourceMdlFile53.vb | 108 +-- .../SourceMdlFileData/SourceMdlAnimation53.vb | 72 -- .../SourceModel53/SourceSmdFile53.vb | 623 +++++++++--------- Crowbar/Crowbar.vbproj | 1 - 4 files changed, 340 insertions(+), 464 deletions(-) delete mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index dbe080a..cb209a6 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1062,7 +1062,7 @@ Public Class SourceMdlFile53 anAnimationDesc.theName = "" End If End Sub - + Protected Function ReadAnimationDescSpanData(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long = 0 @@ -1143,7 +1143,6 @@ Public Class SourceMdlFile53 ' 'Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.anAnimation [ReadAnimationFrameByBone()] alignment") 'End Sub '====== - Protected Sub ReadAnimationFrameByBone(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53, ByVal sectionFrameCount As Integer, ByVal sectionIndex As Integer, ByVal lastSectionIsBeingRead As Boolean) Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition, SeekOrigin.Begin) @@ -1199,44 +1198,6 @@ Public Class SourceMdlFile53 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "aSectionOfAnimation.theBoneFlags " + aSectionOfAnimation.theBoneFlags.Count.ToString()) Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "aSectionOfAnimation.theBoneFlags alignment") - 'fileOffsetStart = Me.theInputFileReader.BaseStream.Position - - ''Dim unknownByte As Byte - ''aSectionOfAnimation.theUnknownBytes01 = New List(Of Byte)(boneCount) - ''aSectionOfAnimation.theUnknownBytes02 = New List(Of Byte)(boneCount) - ''aSectionOfAnimation.theUnknownBytes03 = New List(Of Byte)(boneCount) - ''For boneIndex As Integer = 0 To boneCount - 1 - '' unknownByte = Me.theInputFileReader.ReadByte() - '' aSectionOfAnimation.theUnknownBytes01.Add(unknownByte) - ''Next - ''For boneIndex As Integer = 0 To boneCount - 1 - '' unknownByte = Me.theInputFileReader.ReadByte() - '' aSectionOfAnimation.theUnknownBytes02.Add(unknownByte) - ''Next - ''For boneIndex As Integer = 0 To boneCount - 1 - '' unknownByte = Me.theInputFileReader.ReadByte() - '' aSectionOfAnimation.theUnknownBytes03.Add(unknownByte) - ''Next - ' ''------ - ''Dim unknownBytes As Integer - ''aSectionOfAnimation.theUnknownBytes = New List(Of Integer)(boneCount) - ''For boneIndex As Integer = 0 To boneCount - 1 - '' unknownBytes = Me.theInputFileReader.ReadInt32() - '' 'unknownBytes = Me.theInputFileReader.ReadInt16() - '' aSectionOfAnimation.theUnknownBytes.Add(unknownBytes) - ''Next - ''------ - 'Dim unknownBytes As Integer - 'aSectionOfAnimation.theUnknownBytes = New List(Of Integer)(aSectionOfAnimation.unused(1)) - 'For boneIndex As Integer = 0 To aSectionOfAnimation.unused(1) - 1 - ' unknownBytes = Me.theInputFileReader.ReadInt32() - ' 'unknownBytes = Me.theInputFileReader.ReadInt16() - ' aSectionOfAnimation.theUnknownBytes.Add(unknownBytes) - 'Next - - 'fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - 'Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAniFrameAnim.theUnknownBytes") - If aSectionOfAnimation.constantsOffset <> 0 Then Me.theInputFileReader.BaseStream.Seek(animFrameInputFileStreamPosition + aSectionOfAnimation.constantsOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position @@ -1272,7 +1233,7 @@ Public Class SourceMdlFile53 End If End If - If aSectionOfAnimation.frameLength > 0 AndAlso aSectionOfAnimation.frameOffset <> 0 Then + If aSectionOfAnimation.frameOffset <> 0 Then Me.theInputFileReader.BaseStream.Seek(animFrameInputFileStreamPosition + aSectionOfAnimation.frameOffset, SeekOrigin.Begin) fileOffsetStart = Me.theInputFileReader.BaseStream.Position @@ -1286,7 +1247,7 @@ Public Class SourceMdlFile53 adjustedFrameCount = sectionFrameCount + 1 End If - For frameIndex As Integer = 0 To adjustedFrameCount - 1 + For frameIndex As Integer = 0 To sectionFrameCount - 1 aBoneFrameDataInfoList = New List(Of BoneFrameDataInfo49)(boneCount) If lastSectionIsBeingRead OrElse (frameIndex < (adjustedFrameCount - 1)) Then aSectionOfAnimation.theBoneFrameDataInfos.Add(aBoneFrameDataInfoList) @@ -1358,7 +1319,7 @@ Public Class SourceMdlFile53 Dim posValuePointerInputFileStreamPosition As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long - Dim anAnimation As SourceMdlAnimation53 + Dim anAnimation As SourceMdlAnimation Dim boneCount As Integer 'Dim boneIndex As Byte Dim boneChangeCount As Integer @@ -1372,7 +1333,7 @@ Public Class SourceMdlFile53 animationInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position boneChangeCount += 1 - anAnimation = New SourceMdlAnimation53() + anAnimation = New SourceMdlAnimation() aSectionOfAnimation.Add(anAnimation) anAnimation.TranslationScale = Me.theInputFileReader.ReadSingle() @@ -1414,7 +1375,7 @@ Public Class SourceMdlFile53 ReadMdlAnimationAnimValues(anAnimation, rotValuePointerInputFileStreamPosition, posValuePointerInputFileStreamPosition, sectionFrameCount, lastSectionIsBeingRead) Exit For Else - nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + anAnimation.nextTitanfall2MdlAnimationOffset + nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + anAnimation.nextTitanfall2MdlAnimationOffset If nextAnimationInputFileStreamPosition < Me.theInputFileReader.BaseStream.Position Then 'PROBLEM! Should not be going backwards in file. Dim i As Integer = 42 @@ -1743,7 +1704,7 @@ Public Class SourceMdlFile53 anIkRule.attachmentNameOffset = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To 3 + For x As Integer = 0 To anIkRule.unused.Length - 1 anIkRule.unused(x) = Me.theInputFileReader.ReadInt32() Next @@ -1802,13 +1763,13 @@ Public Class SourceMdlFile53 Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.theIkRules alignment") - If fileOffsetOfLastEndOfIkRuleExtraData > 0 Then - Return fileOffsetOfLastEndOfIkRuleExtraData - Else - Return Me.theInputFileReader.BaseStream.Position - 1 - End If + 'If fileOffsetOfLastEndOfIkRuleExtraData > 0 Then + ' Return fileOffsetOfLastEndOfIkRuleExtraData + 'Else + ' Return Me.theInputFileReader.BaseStream.Position - 1 + 'End If End If - End Function + End Sub Private Function ReadCompressedIkErrors(ByVal ikRuleInputFileStreamPosition As Long, ByVal ikRuleIndex As Integer, ByVal anAnimationDesc As SourceMdlAnimationDesc53) As Long Dim anIkRule As SourceMdlIkRule53 @@ -1879,38 +1840,23 @@ Public Class SourceMdlFile53 'Dim fileOffsetStart2 As Long 'Dim fileOffsetEnd2 As Long - Try - fileOffsetStart = animInputFileStreamPosition + fileOffsetStart = animInputFileStreamPosition - 'animSectionInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + 'animSectionInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - Dim anAnimSection As New SourceMdlAnimationSection() - anAnimSection.animBlock = Me.theInputFileReader.ReadInt32() - anAnimSection.animOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.theSections.Add(anAnimSection) + Dim anAnimSection As New SourceMdlAnimationSection() + anAnimSection.animBlock = Me.theInputFileReader.ReadInt32() + anAnimSection.animOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.theSections.Add(anAnimSection) - 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position + 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) + 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - 'aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimSection [" + anAnimationDesc.theName + "] [animBlock = " + anAnimSection.animBlock.ToString() + "] [calculated ANI file Offset = " + (Me.theMdlFileData.theAnimBlocks(anAnimSection.animBlock).dataStart + anAnimSection.animOffset).ToString() + "]") - If Me.theMdlFileData.theAnimBlocks Is Nothing Then - aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimSection [" + anAnimationDesc.theName + "] [animBlock = " + anAnimSection.animBlock.ToString() + "]") Else Dim animBlock As Integer - Dim description As String - animBlock = anAnimSection.animBlock - If animBlock = 0 Then - description = "MDL" - Else - description = "ANI" - End If - aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimSection [" + anAnimationDesc.theName + "] [animBlock = " + animBlock.ToString() + "] [calculated " + description + " file Offset = " + (Me.theMdlFileData.theAnimBlocks(animBlock).dataStart + anAnimSection.animOffset).ToString() + "]") - End If - Catch ex As Exception - Dim debug As Integer = 4242 - End Try + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theSections") End Sub Protected Sub ReadMdlMovements(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) @@ -1946,13 +1892,9 @@ Public Class SourceMdlFile53 Next fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theMovements " + anAnimationDesc.theMovements.Count.ToString()) - - Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.theMovements alignment") - - Return Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theMovements") End If - End Function + End Sub Protected Sub ReadLocalHierarchies(ByVal animInputFileStreamPosition As Long, ByVal anAnimationDesc As SourceMdlAnimationDesc53) If anAnimationDesc.localHierarchyCount > 0 Then diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb deleted file mode 100644 index 2257ab2..0000000 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlAnimation53.vb +++ /dev/null @@ -1,72 +0,0 @@ -Imports System.Runtime.InteropServices - -Public Class SourceMdlAnimation53 - - 'FROM: SourceEngineXXXX_source\public\studio.h - '// per bone per animation DOF and weight pointers - 'struct mstudioanim_t - '{ - ' DECLARE_BYTESWAP_DATADESC(); - ' byte bone; - ' byte flags; // weighing options - - ' // valid for animating data only - ' inline byte *pData( void ) const { return (((byte *)this) + sizeof( struct mstudioanim_t )); }; - ' inline mstudioanim_valueptr_t *pRotV( void ) const { return (mstudioanim_valueptr_t *)(pData()); }; - ' inline mstudioanim_valueptr_t *pPosV( void ) const { return (mstudioanim_valueptr_t *)(pData()) + ((flags & STUDIO_ANIM_ANIMROT) != 0); }; - - ' // valid if animation unvaring over timeline - ' inline Quaternion48 *pQuat48( void ) const { return (Quaternion48 *)(pData()); }; - ' inline Quaternion64 *pQuat64( void ) const { return (Quaternion64 *)(pData()); }; - ' inline Vector48 *pPos( void ) const { return (Vector48 *)(pData() + ((flags & STUDIO_ANIM_RAWROT) != 0) * sizeof( *pQuat48() ) + ((flags & STUDIO_ANIM_RAWROT2) != 0) * sizeof( *pQuat64() ) ); }; - - ' short nextoffset; - ' inline mstudioanim_t *pNext( void ) const { if (nextoffset != 0) return (mstudioanim_t *)(((byte *)this) + nextoffset); else return NULL; }; - '}; - - Public translationScale As Single - - ' byte bone; - Public boneIndex As Byte - ' byte flags; // weighing options - Public flags As Byte - - Public unk As Short - - ' if (flags & STUDIO_ANIM_RAWROT2) <> 0 then this field is filled - Public theRot64bits As SourceQuaternion64bits - ' if (flags & STUDIO_ANIM_RAWPOS) <> 0 then this field is filled - Public thePos As SourceVector48bits - - Public theScale As SourceVector48bits - - ' short nextoffset; - Public nextSourceMdlAnimationOffset As Integer - - - ' Values for the field, flags: - '#define STUDIO_ANIM_RAWPOS 0x01 // Vector48 - '#define STUDIO_ANIM_RAWROT 0x02 // Quaternion48 - '#define STUDIO_ANIM_ANIMPOS 0x04 // mstudioanim_valueptr_t - '#define STUDIO_ANIM_ANIMROT 0x08 // mstudioanim_valueptr_t - '#define STUDIO_ANIM_DELTA 0x10 - '#define STUDIO_ANIM_RAWROT2 0x20 // Quaternion64 - Public Const STUDIO_ANIM_RAWPOS As Integer = &H1 - Public Const STUDIO_ANIM_RAWROT As Integer = &H2 - Public Const STUDIO_ANIM_ANIMPOS As Integer = &H4 - Public Const STUDIO_ANIM_ANIMROT As Integer = &H8 - Public Const STUDIO_ANIM_DELTA As Integer = &H10 - Public Const STUDIO_ANIM_RAWROT2 As Integer = &H20 - - - ' Do not use union, because it will have to rely on size of a .NET Framework data type. - ' _ - 'Public Structure theData - ' Public theRotV As SourceMdlAnimationValuePointer - ' Public thePosV As SourceMdlAnimationValuePointer - ' Public theQuat48 As SourceQuaternion48 - ' Public theQuat64 As SourceQuaternion64 - ' Public thePosV2 As SourceMdlAnimationValuePointer - 'End Structure - -End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 871267f..823d363 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -51,13 +51,7 @@ Public Class SourceSmdFile53 Else boneCount = Me.theMdlFileData.theBones.Count End If - For boneIndex As Integer = 0 To boneCount - 1 - 'Dim aBone As SourceMdlBone - 'aBone = Me.theMdlFileData.theBones(boneIndex) - 'If lodIndex = -2 AndAlso aBone.proceduralRuleOffset <> 0 AndAlso aBone.proceduralRuleType = SourceMdlBone.STUDIO_PROC_JIGGLE Then - ' Continue For - 'End If - + For boneIndex As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 name = Me.theMdlFileData.theBones(boneIndex).theName line = " " @@ -75,7 +69,6 @@ Public Class SourceSmdFile53 Public Sub WriteSkeletonSection(ByVal lodIndex As Integer) Dim line As String = "" - Dim aBone As SourceMdlBone53 'skeleton line = "skeleton" @@ -88,22 +81,20 @@ Public Class SourceSmdFile53 End If Me.theOutputFileStreamWriter.WriteLine(line) For boneIndex As Integer = 0 To Me.theMdlFileData.theBones.Count - 1 - aBone = Me.theMdlFileData.theBones(boneIndex) - line = " " line += boneIndex.ToString(TheApp.InternalNumberFormat) line += " " - line += aBone.position.x.ToString("0.000000", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.theBones(boneIndex).position.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += aBone.position.y.ToString("0.000000", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.theBones(boneIndex).position.y.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += aBone.position.z.ToString("0.000000", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.theBones(boneIndex).position.z.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += aBone.rotation.x.ToString("0.000000", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.theBones(boneIndex).rotation.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += aBone.rotation.y.ToString("0.000000", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.theBones(boneIndex).rotation.y.ToString("0.000000", TheApp.InternalNumberFormat) line += " " - line += aBone.rotation.z.ToString("0.000000", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.theBones(boneIndex).rotation.z.ToString("0.000000", TheApp.InternalNumberFormat) Me.theOutputFileStreamWriter.WriteLine(line) Next @@ -210,10 +201,12 @@ Public Class SourceSmdFile53 Dim collisionData As SourcePhyCollisionData Dim aBone As SourceMdlBone53 + Dim boneIndex As Integer Dim aTriangle As SourcePhyFace - Dim faceSection As SourcePhyConvexMesh + Dim convexMesh As SourcePhyConvexMesh Dim phyVertex As SourcePhyVertex Dim aVectorTransformed As SourceVector + Dim aSourcePhysCollisionModel As SourcePhyPhysCollisionModel Try If Me.thePhyFileData.theSourcePhyCollisionDatas IsNot Nothing Then @@ -222,29 +215,62 @@ Public Class SourceSmdFile53 For collisionDataIndex As Integer = 0 To Me.thePhyFileData.theSourcePhyCollisionDatas.Count - 1 collisionData = Me.thePhyFileData.theSourcePhyCollisionDatas(collisionDataIndex) - For faceSectionIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 - faceSection = collisionData.theConvexMeshes(faceSectionIndex) + If collisionDataIndex < Me.thePhyFileData.theSourcePhyPhysCollisionModels.Count Then + aSourcePhysCollisionModel = Me.thePhyFileData.theSourcePhyPhysCollisionModels(collisionDataIndex) + Else + aSourcePhysCollisionModel = Nothing + End If + + For convexMeshIndex As Integer = 0 To collisionData.theConvexMeshes.Count - 1 + convexMesh = collisionData.theConvexMeshes(convexMeshIndex) - If faceSection.theBoneIndex >= Me.theMdlFileData.theBones.Count Then + ' [12-Apr-2022] From RED_EYE. (He is using someone else's set of data strutures for PHY file.) + ' flags: has_children: (self.flags >> 0) & 3 ' 0 = false; > 0 true + ' This seems to be correct way rather than checking Me.thePhyFileData.theSourcePhyIsCollisionModel. + ' Example where checking Me.thePhyFileData.theSourcePhyIsCollisionModel is incorrect (because the gib meshes are compiled in): + ' "SourceFilmmaker\game\hl2\models\combine_strider.mdl" + If (convexMesh.flags And 3) > 0 Then Continue For End If - aBone = Me.theMdlFileData.theBones(faceSection.theBoneIndex) - For triangleIndex As Integer = 0 To faceSection.theFaces.Count - 1 - aTriangle = faceSection.theFaces(triangleIndex) + If Me.theMdlFileData.theBones.Count = 1 Then + boneIndex = 0 + Else + boneIndex = convexMesh.theBoneIndex + ' MDL36 and MDL37 need this because their PHY does not store bone index. + ' Model versions above MDL37 can have multiple bones with same name, so this check needs to be last. + If boneIndex < 0 Then + If aSourcePhysCollisionModel IsNot Nothing AndAlso Me.theMdlFileData.theBoneNameToBoneIndexMap.ContainsKey(aSourcePhysCollisionModel.theName) Then + boneIndex = Me.theMdlFileData.theBoneNameToBoneIndexMap(aSourcePhysCollisionModel.theName) + Else + ' Not expected to reach here, but just in case, write a mesh connected to first bone instead of writing an empty mesh. + boneIndex = 0 + End If + End If + End If + aBone = Me.theMdlFileData.theBones(boneIndex) + + For triangleIndex As Integer = 0 To convexMesh.theFaces.Count - 1 + aTriangle = convexMesh.theFaces(triangleIndex) line = " phy" Me.theOutputFileStreamWriter.WriteLine(line) ' 19 -0.000009 0.000001 0.999953 0.0 0.0 0.0 1 0 + ' 19 -0.000005 1.000002 -0.000043 0.0 0.0 0.0 1 0 + ' 19 -0.008333 0.997005 1.003710 0.0 0.0 0.0 1 0 For vertexIndex As Integer = 0 To aTriangle.vertexIndex.Length - 1 'phyVertex = collisionData.theVertices(aTriangle.vertexIndex(vertexIndex)) - phyVertex = faceSection.theVertices(aTriangle.vertexIndex(vertexIndex)) + phyVertex = convexMesh.theVertices(aTriangle.vertexIndex(vertexIndex)) + + aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex, aSourcePhysCollisionModel) - aVectorTransformed = Me.TransformPhyVertex(aBone, phyVertex.vertex) + ''DEBUG: Move different face sections away from each other. + 'aVectorTransformed.x += faceSectionIndex * 20 + 'aVectorTransformed.y += faceSectionIndex * 20 line = " " - line += faceSection.theBoneIndex.ToString(TheApp.InternalNumberFormat) + line += boneIndex.ToString(TheApp.InternalNumberFormat) line += " " line += aVectorTransformed.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " @@ -252,6 +278,8 @@ Public Class SourceSmdFile53 line += " " line += aVectorTransformed.z.ToString("0.000000", TheApp.InternalNumberFormat) + 'line += " 0 0 0" + '------ line += " " line += phyVertex.Normal.x.ToString("0.000000", TheApp.InternalNumberFormat) line += " " @@ -343,7 +371,7 @@ Public Class SourceSmdFile53 'Dim tempRotation As New SourceVector() Dim aSequenceDesc As SourceMdlSequenceDesc Dim anAnimationDesc As SourceMdlAnimationDesc53 - + aSequenceDesc = CType(aSequenceDescBase, SourceMdlSequenceDesc) anAnimationDesc = CType(anAnimationDescBase, SourceMdlAnimationDesc53) @@ -581,6 +609,33 @@ Public Class SourceSmdFile53 frameLineIndex = 0 boneIndex = Me.theAnimationFrameLines.Keys(frameLineIndex) aFrameLine = Me.theAnimationFrameLines.Values(frameLineIndex) + + aFirstAnimationDescFrameLine.rotation = New SourceVector() + aFirstAnimationDescFrameLine.position = New SourceVector() + + aFirstAnimationDescFrameLine.rotation.x = aFrameLine.rotation.x + aFirstAnimationDescFrameLine.rotation.y = aFrameLine.rotation.y + 'If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then + ' Dim z As Double + ' z = aFrameLine.rotation.z + ' z += MathModule.DegreesToRadians(-90) + ' aFirstAnimationDescFrameLine.rotation.z = z + 'Else + aFirstAnimationDescFrameLine.rotation.z = aFrameLine.rotation.z + 'End If + + ''NOTE: Only adjust position if bone is a root bone. Do not know why. + ''If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then + ''TEST: Try this version, because of "sequence_blend from Game Zombie" model. + 'If Me.theMdlFileData.theBones(boneIndex).parentBoneIndex = -1 AndAlso (aFrameLine.position.debug_text.StartsWith("raw") OrElse aFrameLine.rotation.debug_text = "anim+bone") Then + ' aFirstAnimationDescFrameLine.position.x = aFrameLine.position.y + ' aFirstAnimationDescFrameLine.position.y = (-aFrameLine.position.x) + ' aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z + 'Else + aFirstAnimationDescFrameLine.position.x = aFrameLine.position.x + aFirstAnimationDescFrameLine.position.y = aFrameLine.position.y + aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z + 'End If End Sub Private Function WriteVertexLine(ByVal aStripGroup As SourceVtxStripGroup07, ByVal aVtxIndexIndex As Integer, ByVal lodIndex As Integer, ByVal meshVertexIndexStart As Integer, ByVal bodyPartVertexIndexStart As Integer) As String @@ -658,56 +713,6 @@ Public Class SourceSmdFile53 Return line End Function - Private Sub CalculateFirstAnimDescFrameLinesForPhysics(ByRef aFirstAnimationDescFrameLine As AnimationFrameLine) - Dim boneIndex As Integer - Dim aFrameLine As AnimationFrameLine - Dim frameIndex As Integer - Dim frameLineIndex As Integer - Dim aSequenceDesc As SourceMdlSequenceDesc - Dim anAnimationDesc As SourceMdlAnimationDesc53 - - aSequenceDesc = Nothing - anAnimationDesc = Me.theMdlFileData.theAnimationDescs(0) - - Me.theAnimationFrameLines = New SortedList(Of Integer, AnimationFrameLine)() - frameIndex = 0 - Me.theAnimationFrameLines.Clear() - 'If (anAnimationDesc.flags And SourceMdlAnimationDesc.STUDIO_ALLZEROS) = 0 Then - Me.CalcAnimation(aSequenceDesc, anAnimationDesc, frameIndex) - 'End If - - frameLineIndex = 0 - boneIndex = Me.theAnimationFrameLines.Keys(frameLineIndex) - aFrameLine = Me.theAnimationFrameLines.Values(frameLineIndex) - - aFirstAnimationDescFrameLine.rotation = New SourceVector() - aFirstAnimationDescFrameLine.position = New SourceVector() - - aFirstAnimationDescFrameLine.rotation.x = aFrameLine.rotation.x - aFirstAnimationDescFrameLine.rotation.y = aFrameLine.rotation.y - 'If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then - ' Dim z As Double - ' z = aFrameLine.rotation.z - ' z += MathModule.DegreesToRadians(-90) - ' aFirstAnimationDescFrameLine.rotation.z = z - 'Else - aFirstAnimationDescFrameLine.rotation.z = aFrameLine.rotation.z - 'End If - - ''NOTE: Only adjust position if bone is a root bone. Do not know why. - ''If Me.theSourceEngineModel.theMdlFileHeader.theBones(boneIndex).parentBoneIndex = -1 Then - ''TEST: Try this version, because of "sequence_blend from Game Zombie" model. - 'If Me.theMdlFileData.theBones(boneIndex).parentBoneIndex = -1 AndAlso (aFrameLine.position.debug_text.StartsWith("raw") OrElse aFrameLine.rotation.debug_text = "anim+bone") Then - ' aFirstAnimationDescFrameLine.position.x = aFrameLine.position.y - ' aFirstAnimationDescFrameLine.position.y = (-aFrameLine.position.x) - ' aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z - 'Else - aFirstAnimationDescFrameLine.position.x = aFrameLine.position.x - aFirstAnimationDescFrameLine.position.y = aFrameLine.position.y - aFirstAnimationDescFrameLine.position.z = aFrameLine.position.z - 'End If - End Sub - Private Sub ProcessTransformsForPhysics() If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then Dim aFirstAnimationDescFrameLine As New AnimationFrameLine() @@ -738,19 +743,7 @@ Public Class SourceSmdFile53 End If End Sub - 'NOTE: From disassembling of MDL Decompiler with OllyDbg, the following calculations are used in VPHYSICS.DLL for each face: - ' convertedZ = 1.0 / 0.0254 * lastVertex.position.z - ' convertedY = 1.0 / 0.0254 * -lastVertex.position.y - ' convertedX = 1.0 / 0.0254 * lastVertex.position.x - 'NOTE: From disassembling of MDL Decompiler with OllyDbg, the following calculations are used after above for each vertex: - ' newValue1 = unknownZ1 * convertedZ + unknownY1 * convertedY + unknownX1 * convertedX + unknownW1 - ' newValue2 = unknownZ2 * convertedZ + unknownY2 * convertedY + unknownX2 * convertedX + unknownW2 - ' newValue3 = unknownZ3 * convertedZ + unknownY3 * convertedY + unknownX3 * convertedX + unknownW3 - 'Seems to be same as this code: - 'Dim aBone As SourceMdlBone - 'aBone = Me.theSourceEngineModel.theMdlFileHeader.theBones(anEyeball.boneIndex) - 'eyeballPosition = MathModule.VectorITransform(anEyeball.org, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone53, ByVal vertex As SourceVector) As SourceVector + Private Function TransformPhyVertex(ByVal aBone As SourceMdlBone53, ByVal vertex As SourceVector, ByVal aSourcePhysCollisionModel As SourcePhyPhysCollisionModel) As SourceVector Dim aVectorTransformed As New SourceVector Dim aVector As New SourceVector() @@ -831,253 +824,270 @@ Public Class SourceSmdFile53 ' aVectorTransformed.y = 1 / 0.0254 * -vertex.x ' aVectorTransformed.z = 1 / 0.0254 * -vertex.y 'Else + ' 'NOTE: Correct: + ' ' Team Fortress 2\tf2_misc_dir\models\player\demo.mdl ' aVector.x = 1 / 0.0254 * vertex.x ' aVector.y = 1 / 0.0254 * vertex.z ' aVector.z = 1 / 0.0254 * -vertex.y ' aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) 'End If '------ - If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then - 'Dim copyOfVector As New SourceVector() - ''copyOfVector.x = 1 / 0.0254 * vertex.x - ''copyOfVector.y = 1 / 0.0254 * vertex.y - ''copyOfVector.z = 1 / 0.0254 * vertex.z - ''copyOfVector.x = 1 / 0.0254 * vertex.x - ''copyOfVector.y = 1 / 0.0254 * vertex.z - ''copyOfVector.z = 1 / 0.0254 * -vertex.y - 'copyOfVector.x = 1 / 0.0254 * vertex.z - 'copyOfVector.y = 1 / 0.0254 * -vertex.x - 'copyOfVector.z = 1 / 0.0254 * -vertex.y - 'aVector = MathModule.VectorTransform(copyOfVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - ''aVector.x = 1 / 0.0254 * vertex.z - ''aVector.y = 1 / 0.0254 * -vertex.x - ''aVector.z = 1 / 0.0254 * -vertex.y - ''aVectorTransformed.x = 1 / 0.0254 * vertex.z - ''aVectorTransformed.y = 1 / 0.0254 * -vertex.x - ''aVectorTransformed.z = 1 / 0.0254 * -vertex.y - - 'Dim debug As Integer = 4242 - - ''Dim temp As Double - ''temp = aVector.y - ''aVector.y = aVector.z - ''aVector.z = -temp - ''------ - ''aVector.y = -aVector.y - ''------ - ''Dim temp As Double - ''temp = aVector.x - ''aVector.x = aVector.z - ''aVector.z = -aVector.y - ''aVector.y = -temp - ''------ - ''Dim temp As Double - ''temp = aVector.x - ''aVectorTransformed.x = aVector.z - ''aVectorTransformed.z = -aVector.y - ''aVectorTransformed.y = -temp - - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - - '[2017-12-22] - ' Correct for cube_like_mesh - 'aVectorTransformed.x = 1 / 0.0254 * vertex.z - 'aVectorTransformed.y = 1 / 0.0254 * -vertex.x - 'aVectorTransformed.z = 1 / 0.0254 * -vertex.y - '------ - ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl - 'aVectorTransformed.x = 1 / 0.0254 * vertex.z - 'aVectorTransformed.y = 1 / 0.0254 * -vertex.y - 'aVectorTransformed.z = 1 / 0.0254 * vertex.x - '------ - 'aVector.x = 1 / 0.0254 * vertex.z - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.z - 'aVector.z = 1 / 0.0254 * vertex.y - 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.z - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * -vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * vertex.y - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * -vertex.y - 'aVector.y = 1 / 0.0254 * vertex.x - 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.z - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.z - ' Correct for cube_like_mesh - ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl - ' Incorrect for L4D2 w_models/weapons/w_rifle_m16a2.mdl - 'aVector.x = 1 / 0.0254 * -vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * -vertex.z - 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.poseToWorldColumn0, Me.poseToWorldColumn1, Me.poseToWorldColumn2, Me.poseToWorldColumn3) - '====== - ''FROM: collisionmodel.cpp ConvertToWorldSpace() - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - ''Dim worldToBoneColumn0 As New SourceVector() - ''Dim worldToBoneColumn1 As New SourceVector() - ''Dim worldToBoneColumn2 As New SourceVector() - ''Dim worldToBoneColumn3 As New SourceVector() - ''MathModule.AngleMatrix(aBone.rotation.x, aBone.rotation.y, aBone.rotation.z, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) - ''worldToBoneColumn3.x = aBone.position.x - ''worldToBoneColumn3.y = aBone.position.y - ''worldToBoneColumn3.z = aBone.position.z - ''aVector.x = aVectorTransformed.x - ''aVector.y = aVectorTransformed.y - ''aVector.z = aVectorTransformed.z - ''aVectorTransformed = MathModule.VectorTransform(aVector, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) - 'aVector.x = aVectorTransformed.x - 'aVector.y = aVectorTransformed.y - 'aVector.z = aVectorTransformed.z - 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) - '====== - ''FROM: collisionmodel.cpp ConvertToWorldSpace() - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) - 'aVector.x = aVectorTransformed.x - 'aVector.y = aVectorTransformed.y - 'aVector.z = aVectorTransformed.z - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - '====== - ''FROM: collisionmodel.cpp ConvertToWorldSpace() - ' ''NOTE: These 3 lines work for airport_fuel_truck, ambulance, and army_truck, but not w_desert_file and w_rifle_m16a2. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.z - 'aVector.z = 1 / 0.0254 * -vertex.y - ' ''NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. - ''aVector.x = 1 / 0.0254 * vertex.x - ''aVector.y = 1 / 0.0254 * -vertex.y - ''aVector.z = 1 / 0.0254 * vertex.z - 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - 'aVector.x = aVectorTransformed.x - 'aVector.y = aVectorTransformed.y - 'aVector.z = aVectorTransformed.z - ''aVector.x = aVectorTransformed.x - ''aVector.y = aVectorTransformed.z - ''aVector.z = -aVectorTransformed.y - 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - '====== - 'FROM: collisionmodel.cpp ConvertToWorldSpace() - If (Me.theMdlFileData.flags And SourceMdlFileData.STUDIOHDR_FLAGS_STATIC_PROP) > 0 Then - 'NOTE: These 3 lines do not work for airport_fuel_truck, ambulance, and army_truck. + 'TODO: [TransformPhyVertex] Merge the various code blocks (separated by MDL version) into one code block. + If Me.theMdlFileData.version >= 44 AndAlso Me.theMdlFileData.version <= 47 Then + ' This works for various weapons and vehicles in HL2. + If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then + aVectorTransformed.x = 1 / 0.0254 * vertex.z + aVectorTransformed.y = 1 / 0.0254 * -vertex.x + aVectorTransformed.z = 1 / 0.0254 * -vertex.y + Else + aVector.x = 1 / 0.0254 * vertex.x + aVector.y = 1 / 0.0254 * vertex.z + aVector.z = 1 / 0.0254 * -vertex.y + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + End If + Else + If Me.thePhyFileData.theSourcePhyCollisionDatas.Count = 1 Then + 'Dim copyOfVector As New SourceVector() + ''copyOfVector.x = 1 / 0.0254 * vertex.x + ''copyOfVector.y = 1 / 0.0254 * vertex.y + ''copyOfVector.z = 1 / 0.0254 * vertex.z + ''copyOfVector.x = 1 / 0.0254 * vertex.x + ''copyOfVector.y = 1 / 0.0254 * vertex.z + ''copyOfVector.z = 1 / 0.0254 * -vertex.y + 'copyOfVector.x = 1 / 0.0254 * vertex.z + 'copyOfVector.y = 1 / 0.0254 * -vertex.x + 'copyOfVector.z = 1 / 0.0254 * -vertex.y + 'aVector = MathModule.VectorTransform(copyOfVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + ''aVector.x = 1 / 0.0254 * vertex.z + ''aVector.y = 1 / 0.0254 * -vertex.x + ''aVector.z = 1 / 0.0254 * -vertex.y + ''aVectorTransformed.x = 1 / 0.0254 * vertex.z + ''aVectorTransformed.y = 1 / 0.0254 * -vertex.x + ''aVectorTransformed.z = 1 / 0.0254 * -vertex.y + + 'Dim debug As Integer = 4242 + + ''Dim temp As Double + ''temp = aVector.y + ''aVector.y = aVector.z + ''aVector.z = -temp + ''------ + ''aVector.y = -aVector.y + ''------ + ''Dim temp As Double + ''temp = aVector.x + ''aVector.x = aVector.z + ''aVector.z = -aVector.y + ''aVector.y = -temp + ''------ + ''Dim temp As Double + ''temp = aVector.x + ''aVectorTransformed.x = aVector.z + ''aVectorTransformed.z = -aVector.y + ''aVectorTransformed.y = -temp + + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + + '[2017-12-22] + ' Correct for cube_like_mesh + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.x + 'aVectorTransformed.z = 1 / 0.0254 * -vertex.y + '------ + ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl + 'aVectorTransformed.x = 1 / 0.0254 * vertex.z + 'aVectorTransformed.y = 1 / 0.0254 * -vertex.y + 'aVectorTransformed.z = 1 / 0.0254 * vertex.x + '------ + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.y 'aVector.x = 1 / 0.0254 * vertex.x 'aVector.y = 1 / 0.0254 * vertex.z 'aVector.z = 1 / 0.0254 * -vertex.y - 'aVector.x = 1 / 0.0254 * vertex.y - 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.z 'aVector.y = 1 / 0.0254 * -vertex.x - 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y 'aVector.x = 1 / 0.0254 * vertex.x 'aVector.y = 1 / 0.0254 * vertex.y 'aVector.z = 1 / 0.0254 * vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * -vertex.x 'aVector.y = 1 / 0.0254 * vertex.z 'aVector.z = 1 / 0.0254 * vertex.y - '' Still need a rotate 90 on the z. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x 'aVector.z = 1 / 0.0254 * vertex.z 'aVector.x = 1 / 0.0254 * -vertex.y 'aVector.y = 1 / 0.0254 * vertex.x 'aVector.z = 1 / 0.0254 * vertex.z - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.z - 'aVector.z = 1 / 0.0254 * vertex.y - 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.y 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + ' Correct for cube_like_mesh + ' Correct for L4D2 w_models/weapons/w_desert_rifle.mdl + ' Incorrect for L4D2 w_models/weapons/w_rifle_m16a2.mdl + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, Me.poseToWorldColumn0, Me.poseToWorldColumn1, Me.poseToWorldColumn2, Me.poseToWorldColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z 'aVector.z = 1 / 0.0254 * -vertex.y - + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + ''Dim worldToBoneColumn0 As New SourceVector() + ''Dim worldToBoneColumn1 As New SourceVector() + ''Dim worldToBoneColumn2 As New SourceVector() + ''Dim worldToBoneColumn3 As New SourceVector() + ''MathModule.AngleMatrix(aBone.rotation.x, aBone.rotation.y, aBone.rotation.z, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) + ''worldToBoneColumn3.x = aBone.position.x + ''worldToBoneColumn3.y = aBone.position.y + ''worldToBoneColumn3.z = aBone.position.z + ''aVector.x = aVectorTransformed.x + ''aVector.y = aVectorTransformed.y + ''aVector.z = aVectorTransformed.z + ''aVectorTransformed = MathModule.VectorTransform(aVector, worldToBoneColumn0, worldToBoneColumn1, worldToBoneColumn2, worldToBoneColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVectorTransformed = MathModule.VectorTransform(aVector, poseToWorldColumn0, poseToWorldColumn1, poseToWorldColumn2, poseToWorldColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '====== + ''FROM: collisionmodel.cpp ConvertToWorldSpace() + ' ''NOTE: These 3 lines work for airport_fuel_truck, ambulance, and army_truck, but not w_desert_file and w_rifle_m16a2. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + ' ''NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. + ''aVector.x = 1 / 0.0254 * vertex.x + ''aVector.y = 1 / 0.0254 * -vertex.y + ''aVector.z = 1 / 0.0254 * vertex.z 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) 'aVector.x = aVectorTransformed.x 'aVector.y = aVectorTransformed.y 'aVector.z = aVectorTransformed.z + ''aVector.x = aVectorTransformed.x + ''aVector.y = aVectorTransformed.z + ''aVector.z = -aVectorTransformed.y 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + '====== + 'FROM: collisionmodel.cpp ConvertToWorldSpace() + If (Me.theMdlFileData.flags And SourceMdlFileData.STUDIOHDR_FLAGS_STATIC_PROP) > 0 Then + 'NOTE: These 3 lines do not work for airport_fuel_truck, ambulance, and army_truck. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * -vertex.y + 'aVector.x = 1 / 0.0254 * vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + '' Still need a rotate 90 on the z. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * -vertex.y + 'aVector.y = 1 / 0.0254 * vertex.x + 'aVector.z = 1 / 0.0254 * vertex.z + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.z + 'aVector.z = 1 / 0.0254 * vertex.y + 'aVector.x = 1 / 0.0254 * vertex.z + 'aVector.y = 1 / 0.0254 * -vertex.x + 'aVector.z = 1 / 0.0254 * -vertex.y + + 'aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + 'aVector.x = aVectorTransformed.x + 'aVector.y = aVectorTransformed.y + 'aVector.z = aVectorTransformed.z + 'aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) - '------ + '------ - 'TEST: Works for props_vehciles that use $staticprop. - aVector.x = 1 / 0.0254 * vertex.z - aVector.y = 1 / 0.0254 * -vertex.x - aVector.z = 1 / 0.0254 * -vertex.y - aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - aVector.x = aVectorTransformed.x - aVector.y = aVectorTransformed.z - aVector.z = -aVectorTransformed.y - aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + 'TEST: Works for props_vehciles that use $staticprop. + aVector.x = 1 / 0.0254 * vertex.z + aVector.y = 1 / 0.0254 * -vertex.x + aVector.z = 1 / 0.0254 * -vertex.y + aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + aVector.x = aVectorTransformed.x + aVector.y = aVectorTransformed.z + aVector.z = -aVectorTransformed.y + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + Else + 'NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. + 'TEST: Did not work for 50_cal. Rotated 180. Original model has phys mesh rotated oddly, anyway. + 'TEST: Incorrect. Need to 180 on the Y and -1 on scale Z. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * -vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'TEST: Incorrect. Need to 180 on the Y. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * vertex.z + 'TEST: Incorrect. Need to -1 on scale Z. Noticable on w_minigun. + 'aVector.x = 1 / 0.0254 * vertex.x + 'aVector.y = 1 / 0.0254 * vertex.y + 'aVector.z = 1 / 0.0254 * -vertex.z + 'TEST: Works for w_minigun. + 'TEST: Works for 50cal, but be aware that the phys mesh does not look right for the model. It does look like original model, though. + 'TEST: Does not work for Garry's Mod addon "dodge_daytona" 236224475. + aVector.x = 1 / 0.0254 * vertex.x + aVector.y = 1 / 0.0254 * -vertex.y + aVector.z = 1 / 0.0254 * -vertex.z + + aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) + aVector.x = aVectorTransformed.x + aVector.y = aVectorTransformed.y + aVector.z = aVectorTransformed.z + aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) + End If Else - 'NOTE: These 3 lines work for w_desert_file and w_rifle_m16a2, but not ambulance and army_truck. - 'TEST: Did not work for 50_cal. Rotated 180. Original model has phys mesh rotated oddly, anyway. - 'TEST: Incorrect. Need to 180 on the Y and -1 on scale Z. Noticable on w_minigun. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * -vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - 'TEST: Incorrect. Need to 180 on the Y. Noticable on w_minigun. + 'FROM: collisionmodel.cpp ConvertToBoneSpace() 'aVector.x = 1 / 0.0254 * vertex.x 'aVector.y = 1 / 0.0254 * vertex.y 'aVector.z = 1 / 0.0254 * vertex.z - 'TEST: Incorrect. Need to -1 on scale Z. Noticable on w_minigun. - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * -vertex.z - 'TEST: Works for w_minigun. - 'TEST: Works for 50cal, but be aware that the phys mesh does not look right for the model. It does look like original model, though. - 'TEST: Does not work for Garry's Mod addon "dodge_daytona" 236224475. aVector.x = 1 / 0.0254 * vertex.x - aVector.y = 1 / 0.0254 * -vertex.y - aVector.z = 1 / 0.0254 * -vertex.z - - aVectorTransformed = MathModule.VectorTransform(aVector, Me.worldToPoseColumn0, Me.worldToPoseColumn1, Me.worldToPoseColumn2, Me.worldToPoseColumn3) - aVector.x = aVectorTransformed.x - aVector.y = aVectorTransformed.y - aVector.z = aVectorTransformed.z + aVector.y = 1 / 0.0254 * vertex.z + aVector.z = 1 / 0.0254 * -vertex.y aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) End If - Else - 'FROM: collisionmodel.cpp ConvertToBoneSpace() - 'aVector.x = 1 / 0.0254 * vertex.x - 'aVector.y = 1 / 0.0254 * vertex.y - 'aVector.z = 1 / 0.0254 * vertex.z - aVector.x = 1 / 0.0254 * vertex.x - aVector.y = 1 / 0.0254 * vertex.z - aVector.z = 1 / 0.0254 * -vertex.y - aVectorTransformed = MathModule.VectorITransform(aVector, aBone.poseToBoneColumn0, aBone.poseToBoneColumn1, aBone.poseToBoneColumn2, aBone.poseToBoneColumn3) End If 'If Me.theMdlFileData.theBoneTransforms IsNot Nothing Then @@ -1219,7 +1229,7 @@ Public Class SourceSmdFile53 Dim animIndex As Integer Dim aBone As SourceMdlBone53 Dim aWeight As Double - Dim anAnimation As SourceMdlAnimation53 + Dim anAnimation As SourceMdlAnimation Dim rot As SourceVector Dim pos As SourceVector Dim aFrameLine As AnimationFrameLine @@ -1230,7 +1240,7 @@ Public Class SourceSmdFile53 animIndex = 0 Dim sectionIndex As Integer - Dim aSectionOfAnimation As List(Of SourceMdlAnimation53) + Dim aSectionOfAnimation As List(Of SourceMdlAnimation) If anAnimationDesc.sectionFrameCount = 0 Then sectionIndex = 0 sectionFrameIndex = frameIndex @@ -1551,7 +1561,7 @@ Public Class SourceSmdFile53 ' Return rot 'End Function - Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation53, ByRef rotationQuat As SourceQuaternion) As SourceVector + Private Function CalcBoneRotation(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation, ByRef rotationQuat As SourceQuaternion) As SourceVector Dim rot As New SourceQuaternion() Dim angleVector As New SourceVector() @@ -1569,7 +1579,7 @@ Public Class SourceSmdFile53 angleVector.debug_text = "raw64 (" + rot.x.ToString() + ", " + rot.y.ToString() + ", " + rot.z.ToString() + ", " + rot.w.ToString() + ")" Return angleVector End If - + Try If anAnimation.theRotV IsNot Nothing Then Dim rotV As SourceMdlAnimationValuePointer = anAnimation.theRotV @@ -1678,7 +1688,7 @@ Public Class SourceSmdFile53 ' Assert( pos.IsValid() ); '} - Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation53) As SourceVector + Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation) As SourceVector Dim pos As New SourceVector() If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) > 0 Then @@ -1810,9 +1820,6 @@ Public Class SourceSmdFile53 Private poseToWorldColumn2 As New SourceVector() Private poseToWorldColumn3 As New SourceVector() - Private previousFrameRotation As New SourceVector() - Private frame0Position As New SourceVector() - #End Region End Class diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 31794ca..902971a 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -129,7 +129,6 @@ - From ce3222dc6949dba418d73d13bef3f004f51b639f Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Sat, 3 Sep 2022 01:32:20 -0400 Subject: [PATCH 26/39] Update SourceMdlFile53.vb --- Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb | 2 -- 1 file changed, 2 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index cb209a6..9a73229 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1853,8 +1853,6 @@ Public Class SourceMdlFile53 'Me.theInputFileReader.BaseStream.Seek(inputFileStreamPosition, SeekOrigin.Begin) - Else - Dim animBlock As Integer fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 aFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.theSections") End Sub From 907b43168116d1aa027b76dfb3ea1c61a73add30 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Tue, 6 Sep 2022 00:43:30 -0400 Subject: [PATCH 27/39] minor command cleanup --- .../GameModel/SourceModel53/SourceModel53.vb | 13 ++------ .../GameModel/SourceModel53/SourceQcFile53.vb | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index 845c569..a7f5f92 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -493,7 +493,6 @@ Public Class SourceModel53 ' qcFile.WriteBodyGroupCommand(0) '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.WriteSurfacePropCommand() @@ -503,6 +502,7 @@ Public Class SourceModel53 qcFile.WriteIllumPositionCommand() qcFile.WriteEyePositionCommand() + ' Removed in V53 'qcFile.WriteMaxEyeDeflectionCommand() qcFile.WriteNoForcedFadeCommand() qcFile.WriteForcePhonemeCrossfadeCommand() @@ -510,9 +510,8 @@ Public Class SourceModel53 qcFile.WriteAmbientBoostCommand() qcFile.WriteOpaqueCommand() qcFile.WriteObsoleteCommand() - 'TODO: Probably should be just like MDL v52. - 'qcFile.WriteCastTextureShadowsCommand() - 'qcFile.WriteDoNotCastShadowsCommand() + qcFile.WriteCastTextureShadowsCommand() + qcFile.WriteDoNotCastShadowsCommand() qcFile.WriteCdMaterialsCommand() qcFile.WriteTextureGroupCommand() If TheApp.Settings.DecompileDebugInfoFilesIsChecked Then @@ -771,12 +770,6 @@ Public Class SourceModel53 mdlFile.WriteInternalMdlFileName(internalMdlFileName) End Sub - 'Protected Overrides Sub WriteAniFileNameToMdlFile(ByVal internalAniFileName As String) - ' Dim mdlFile As New SourceMdlFile53(Me.theOutputFileBinaryWriter, Me.theMdlFileData) - - 'mdlFile.WriteInternalAniFileName(internalAniFileName) - 'End Sub - #End Region #Region "Data" diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index b6f0fdf..32f88e3 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -1401,6 +1401,38 @@ Public Class SourceQcFile53 End If End Sub + Public Sub WriteCastTextureShadowsCommand() + Dim line As String = "" + + '$casttextureshadows + If (Me.theMdlFileData.flags And SourceMdlFileData.STUDIOHDR_FLAGS_CAST_TEXTURE_SHADOWS) > 0 Then + Me.theOutputFileStreamWriter.WriteLine() + + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + line = "$CastTextureShadows" + Else + line = "$casttextureshadows" + End If + Me.theOutputFileStreamWriter.WriteLine(line) + End If + End Sub + + Public Sub WriteDoNotCastShadowsCommand() + Dim line As String = "" + + '$donotcastshadows + If (Me.theMdlFileData.flags And SourceMdlFileData.STUDIOHDR_FLAGS_DO_NOT_CAST_SHADOWS) > 0 Then + Me.theOutputFileStreamWriter.WriteLine() + + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + line = "$DoNotCastShadows" + Else + line = "$donotcastshadows" + End If + Me.theOutputFileStreamWriter.WriteLine(line) + End If + End Sub + Public Sub WriteCdMaterialsCommand() Dim line As String = "" Dim texturePaths As List(Of String) From 49845c066086522a6c0c889c1f7dd5694e1fee58 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Tue, 6 Sep 2022 22:56:39 -0400 Subject: [PATCH 28/39] add some rui structs, get more v52/v53 data reading reads per tri collision header and maya strings now, nothing done with them for now but it's less unread bytes. --- .../SourceModel52/SourceMdlFile52.vb | 63 +++++++++++++-- .../SourceMdlFileData/RSourceAABBHeader52.vb | 10 --- .../RSourcePerTriCollisionHeader52.vb | 24 ++++++ .../SourceMdlFileData/SourceMdlFileData52.vb | 23 +++--- .../GameModel/SourceModel52/SourceModel52.vb | 4 + .../SourceModel53/SourceMdlFile53.vb | 80 ++++++++++++------- .../SourceMdlFileData/RSourceRuiHeader53.vb | 6 ++ .../RSourceRuiMeshHeader53.vb | 41 ++++++++++ .../SourceMdlFileData/SourceMdlFileData53.vb | 44 +++++----- .../GameModel/SourceModel53/SourceModel53.vb | 4 +- Crowbar/Crowbar.vbproj | 4 +- 11 files changed, 215 insertions(+), 88 deletions(-) delete mode 100644 Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb create mode 100644 Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourcePerTriCollisionHeader52.vb create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiHeader53.vb create mode 100644 Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiMeshHeader53.vb diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 2a3de12..1d22239 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -319,22 +319,39 @@ Public Class SourceMdlFile52 Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.boneFlexDriverOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknownOffset01 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown01 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown02 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown03 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknownOffset02 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCollisionOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCount1 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCount2 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCount3 = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unkStringOffset = Me.theInputFileReader.ReadInt32() 'NOTE: In V52 the subheader is 208 bytes instead of 256. - 'For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1 - ' Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32() - 'Next + For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1 + Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32() + Next fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, logDescription) End Sub + ' TODO: write to .txt (maybe), get log formatting better, remove null characters when present. + Public Sub ReadMayaStrings() + If Me.theMdlFileData.mayaOffset > 0 And Me.theMdlFileData.mayaOffset < Me.theMdlFileData.boneOffset Then + Dim fileOffsetStart As Long + Dim fileOffsetEnd As Long + + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.mayaOffset, SeekOrigin.Begin) + fileOffsetStart = Me.theInputFileReader.BaseStream.Position + + theMdlFileData.theMayaStrings = Me.theInputFileReader.ReadChars(Me.theMdlFileData.boneOffset - Me.theMdlFileData.mayaOffset) + + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theMayaStrings " + theMdlFileData.theMayaStrings) + End If + End Sub + Public Sub ReadBones() If Me.theMdlFileData.boneCount > 0 Then Dim boneInputFileStreamPosition As Long @@ -4219,6 +4236,36 @@ Public Class SourceMdlFile52 End If End Sub + ' This just reads the bytes for now, will implement reading the mesh at a later date once it's understood. + Public Sub ReadPerTriCollisionHeader() + Dim fileOffsetStart As Long + Dim fileOffsetEnd As Long + + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.studioHeader2Offset + Me.theMdlFileData.perTriCollisionOffset, SeekOrigin.Begin) + fileOffsetStart = Me.theInputFileReader.BaseStream.Position + + Dim theDetailedCollision As New RSourcePerTriCollisionHeader52 + + theDetailedCollision.version = Me.theInputFileReader.ReadInt32() + + theDetailedCollision.bbMin = New SourceVector() + theDetailedCollision.bbMin.x = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMin.y = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMin.z = Me.theInputFileReader.ReadSingle() + + theDetailedCollision.bbMax = New SourceVector() + theDetailedCollision.bbMax.x = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMax.y = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMax.z = Me.theInputFileReader.ReadSingle() + + For k As Integer = 0 To 7 + theDetailedCollision.unused(k) = Me.theInputFileReader.ReadInt32() + Next + + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theDetailedCollision") + End Sub + 'Public Sub ReadFinalBytesAlignment() ' Me.theMdlFileData.theFileSeekLog.LogAndAlignFromFileSeekLogEnd(Me.theInputFileReader, 4, "Final bytes alignment") 'End Sub diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb deleted file mode 100644 index 61fa991..0000000 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourceAABBHeader52.vb +++ /dev/null @@ -1,10 +0,0 @@ -Public Class RSourceAABBHeader52 - - Public version As Integer - - Public bbMin As SourceVector - Public bbMax As SourceVector - - Public unused(7) As Integer - -End Class diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourcePerTriCollisionHeader52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourcePerTriCollisionHeader52.vb new file mode 100644 index 0000000..6a3e033 --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/RSourcePerTriCollisionHeader52.vb @@ -0,0 +1,24 @@ +Public Class RSourcePerTriCollisionHeader52 + + 'struct pertriheader_t + '{ + ' int version; // unsure If this Is an actual version Or type + ' // set to '2' for static prop. + ' + ' // aabb sizes, same as hulls + ' Vector3 bbmin; + ' Vector3 bbmax; + ' + ' int unused[8]; // hopefully, checks out With other mdl structs + '}; + + ' 2 for static props, 0 for everything else, unknown if 1 is used. + Public version As Integer + + ' Size of AABB + Public bbMin As SourceVector + Public bbMax As SourceVector + + Public unused(7) As Integer + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb index 9f66afa..6291813 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFileData/SourceMdlFileData52.vb @@ -547,21 +547,16 @@ Public boneFlexDriverCount As Integer Public boneFlexDriverOffset As Integer - ' Both V52 and V53 have this section. - ' Related to some block that appears when linear bone data is not present. - Public unknownOffset01 As Integer - Public unknown01 As Integer - Public unknown02 As Integer - Public unknown03 As Integer - ' Points to byte just before string table. - Public unknownOffset02 As Integer + ' High detail collision mesh for static props. + Public perTriCollisionOffset As Integer + Public perTriCount1 As Integer + Public perTriCount2 As Integer + Public perTriCount3 As Integer - 'NOTE: Just skip reading these bytes, because it unknown if any are used. - 'NOTE: These are unused in V52 as far as I can tell. - 'Public reserved(56) As Integer - '====== - 'Public studiohdr2(63) As Integer + ' When used the string is normally "Titan", only observed on models for animation. + Public unkStringOffset As Integer + Public reserved(38) As Integer 'Public theID As String @@ -594,6 +589,8 @@ Public theSurfacePropName As String Public theTexturePaths As List(Of String) Public theTextures As List(Of SourceMdlTexture) + Public theMayaStrings As String + Public theDetailedCollision As RSourcePerTriCollisionHeader52 Public theSectionFrameCount As Integer Public theSectionFrameMinFrameCount As Integer diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb index 94a1939..5ecff3f 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb @@ -349,6 +349,8 @@ Public Class SourceModel52 mdlFile.ReadMdlHeader02("MDL File Header 02") End If + mdlFile.ReadMayaStrings() + mdlFile.ReadBones() mdlFile.ReadBoneControllers() mdlFile.ReadAttachments() @@ -395,6 +397,8 @@ Public Class SourceModel52 mdlFile.ReadBoneTransforms() mdlFile.ReadLinearBoneTable() + mdlFile.ReadPerTriCollisionHeader() + 'TODO: ReadLocalIkAutoPlayLocks() mdlFile.ReadFlexControllerUis() diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 9a73229..181a04d 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -270,7 +270,6 @@ Public Class SourceMdlFile53 Me.theMdlFileData.unused = Me.theInputFileReader.ReadByte() - ' In v52 and v53 this is actually used for something, as a float. Me.theMdlFileData.fadeDistance = Me.theInputFileReader.ReadSingle() Me.theMdlFileData.flexControllerUiCount = Me.theInputFileReader.ReadInt32() @@ -285,7 +284,6 @@ Public Class SourceMdlFile53 Me.theMdlFileData.sourceBoneTransformCount = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.sourceBoneTransformOffset = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.illumPositionAttachmentIndex = Me.theInputFileReader.ReadInt32() - 'Me.theMdlFileData.maxEyeDeflection = Me.theInputFileReader.ReadSingle() Me.theMdlFileData.linearBoneOffset = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.boneFlexDriverCount = Me.theInputFileReader.ReadInt32() @@ -294,11 +292,12 @@ Public Class SourceMdlFile53 'Me.theMdlFileData.vertAnimFixedPointScale = Me.theInputFileReader.ReadSingle() 'Me.theMdlFileData.surfacePropLookup = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.aabbOffset = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown01 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown02 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknown03 = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknownOffset02 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCollisionOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCount1 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCount2 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.perTriCount3 = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unkStringOffset = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.vtxOffset = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.vvdOffset = Me.theInputFileReader.ReadInt32() @@ -311,16 +310,37 @@ Public Class SourceMdlFile53 Me.theMdlFileData.vvcSize = Me.theInputFileReader.ReadInt32() Me.theMdlFileData.phySize = Me.theInputFileReader.ReadInt32() - Me.theMdlFileData.unknownOffset03 = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unkSectionOffset = Me.theInputFileReader.ReadInt32() + Me.theMdlFileData.unkSectionCount = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unknown05 = Me.theInputFileReader.ReadInt32() + + Me.theMdlFileData.unknownOffset06 = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To Me.theMdlFileData.unknown.Length - 1 - Me.theMdlFileData.unknown(x) = Me.theInputFileReader.ReadInt32() + For x As Integer = 0 To Me.theMdlFileData.reserved.Length - 1 + Me.theMdlFileData.reserved(x) = Me.theInputFileReader.ReadInt32() Next fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, logDescription) End Sub + ' TODO: write to .txt (maybe), get log formatting better, remove null characters when present. + Public Sub ReadMayaStrings() + If Me.theMdlFileData.mayaOffset > 0 And Me.theMdlFileData.mayaOffset < Me.theMdlFileData.boneOffset Then + Dim fileOffsetStart As Long + Dim fileOffsetEnd As Long + + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.mayaOffset, SeekOrigin.Begin) + fileOffsetStart = Me.theInputFileReader.BaseStream.Position + + theMdlFileData.theMayaStrings = Me.theInputFileReader.ReadChars(Me.theMdlFileData.boneOffset - Me.theMdlFileData.mayaOffset) + + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theMayaStrings " + theMdlFileData.theMayaStrings) + End If + End Sub + Public Sub ReadBones() If Me.theMdlFileData.boneCount > 0 Then Dim boneInputFileStreamPosition As Long @@ -2003,8 +2023,6 @@ Public Class SourceMdlFile53 aSeqDesc.keyValueSize = Me.theInputFileReader.ReadInt32() aSeqDesc.cyclePoseIndex = Me.theInputFileReader.ReadInt32() - aSeqDesc.activityModifierOffset = 0 - aSeqDesc.activityModifierCount = 0 aSeqDesc.activityModifierOffset = Me.theInputFileReader.ReadInt32() aSeqDesc.activityModifierCount = Me.theInputFileReader.ReadInt32() @@ -3896,34 +3914,34 @@ Public Class SourceMdlFile53 End If End Sub - ' TODO: this doesn't actually work lol. - Public Sub ReadAABBHeader() - 'Dim inputFileStreamPosition As Long - 'Dim fileOffsetStart As Long + ' This just reads the bytes for now, will implement reading the mesh at a later date once it's understood. + Public Sub ReadPerTriCollisionHeader() + Dim fileOffsetStart As Long + Dim fileOffsetEnd As Long - Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.aabbOffset, SeekOrigin.Begin) - 'fileOffsetStart = Me.theInputFileReader.BaseStream.Position + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.perTriCollisionOffset, SeekOrigin.Begin) + fileOffsetStart = Me.theInputFileReader.BaseStream.Position - Dim theAABB As New RSourceAABBHeader52 + Dim theDetailedCollision As New RSourcePerTriCollisionHeader52 - theAABB.version = Me.theInputFileReader.ReadInt32() + theDetailedCollision.version = Me.theInputFileReader.ReadInt32() - theAABB.bbMin = New SourceVector() - theAABB.bbMin.x = Me.theInputFileReader.ReadSingle() - theAABB.bbMin.y = Me.theInputFileReader.ReadSingle() - theAABB.bbMin.z = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMin = New SourceVector() + theDetailedCollision.bbMin.x = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMin.y = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMin.z = Me.theInputFileReader.ReadSingle() - theAABB.bbMax = New SourceVector() - theAABB.bbMax.x = Me.theInputFileReader.ReadSingle() - theAABB.bbMax.y = Me.theInputFileReader.ReadSingle() - theAABB.bbMax.z = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMax = New SourceVector() + theDetailedCollision.bbMax.x = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMax.y = Me.theInputFileReader.ReadSingle() + theDetailedCollision.bbMax.z = Me.theInputFileReader.ReadSingle() For k As Integer = 0 To 7 - theAABB.unused(k) = Me.theInputFileReader.ReadInt32() + theDetailedCollision.unused(k) = Me.theInputFileReader.ReadInt32() Next - 'inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theDetailedCollision") End Sub 'Public Sub ReadFinalBytesAlignment() diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiHeader53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiHeader53.vb new file mode 100644 index 0000000..a72e58c --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiHeader53.vb @@ -0,0 +1,6 @@ +Public Class RSourceRuiHeader53 + + Public unk As Integer + Public meshIndex As Integer + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiMeshHeader53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiMeshHeader53.vb new file mode 100644 index 0000000..071ae1c --- /dev/null +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/RSourceRuiMeshHeader53.vb @@ -0,0 +1,41 @@ +Public Class RSourceRuiMeshHeader53 + + 'struct mstudioruimesh_t + '{ + ' int numparents; // apparently you can have meshes parented To more than one bone(?) + ' int numvertices; // number Of verts + ' int numfaces; // number Of faces (quads) + ' + ' int parentindex; // this gets padding out front Of it To even off the struct + ' + ' int vertexindex; // offset into smd style vertex data + ' int vertmapindex; // offsets into a vertex map For Each quad + ' int facedataindex; // offset into uv section + ' + ' byte unk[4]; // zero sometimes, others Not. has to do with face clipping. + ' + ' char szruimeshname[parentindex - 32]; // have to subtract header to get actual size (padding included) + ' + ' int16 parent[numparents]; // parent(s) bone Of mesh + ' + ' mstudioruivertmap_t vertexmap[numfaces]; // vertex map For Each face + ' mstudioruivert_t vertex[numvertices]; + ' + ' mstudioruimesface_t facedata[numfaces]; + '}; + + Public parentCount As Integer + Public vertexCount As Integer + Public faceCount As Integer + + Public parentOffset As Integer + + Public vertexOffset As Integer + Public vertexMapOffset As Integer + Public faceOffset As Integer + + Public unk As Integer + + Public meshName(parentOffset - 32) As String + +End Class diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb index 2550e57..f1ae666 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFileData/SourceMdlFileData53.vb @@ -488,16 +488,6 @@ ' mutable void *virtualModel; Public virtualModelP As Integer - ' int szanimblocknameindex; - 'Public animBlockNameOffset As Integer - ' int numanimblocks; - 'Public animBlockCount As Integer - ' int animblockindex; - 'Public animBlockOffset As Integer - ' mutable void *animblockModel; - 'Public animBlockModelP As Integer - - 'NOTE: Probably not used or used for something else. ' int bonetablebynameindex; Public boneTableByNameOffset As Integer @@ -532,21 +522,19 @@ Public sourceBoneTransformCount As Integer Public sourceBoneTransformOffset As Integer Public illumPositionAttachmentIndex As Integer - 'Public maxEyeDeflection As Double Public linearBoneOffset As Integer - 'Public nameOffset As Integer Public boneFlexDriverCount As Integer Public boneFlexDriverOffset As Integer - ' Both V52 and V53 have this section. - ' Related to some block that appears when linear bone data is not present. - Public aabbOffset As Integer - Public unknown01 As Integer - Public unknown02 As Integer - Public unknown03 As Integer - ' Points to byte just before string table. - Public unknownOffset02 As Integer + ' High detail collision mesh for static props. + Public perTriCollisionOffset As Integer + Public perTriCount1 As Integer + Public perTriCount2 As Integer + Public perTriCount3 As Integer + + ' When used the string is normally "Titan", only observed on models for animation. + Public unkStringOffset As Integer Public vtxOffset As Integer Public vvdOffset As Integer @@ -557,11 +545,16 @@ Public vvdSize As Integer Public vvcSize As Integer Public phySize As Integer - Public unknownOffset03 As Integer - Public unknown04 As Integer + + Public unkSectionOffset As Integer + ' Only used if PHY has a solid count of "1" + Public unkSectionCount As Integer + Public unknown05 As Integer Public unknownOffset06 As Integer - Public unknown(60) As Integer + + ' Nothing observed past here, however the first in may be a count for unknownOffset06 + Public reserved(59) As Integer 'NOTE: Header is 716 bytes. @@ -594,7 +587,10 @@ Public theSurfacePropName As String Public theTexturePaths As List(Of String) Public theTextures As List(Of SourceMdlTexture) - Public theAABB As RSourceAABBHeader52 + Public theMayaStrings As String + Public theDetailedCollision As RSourcePerTriCollisionHeader52 + Public theRuiHeaders As List(Of RSourceRuiHeader53) + Public theRuiMeshes As List(Of RSourceRuiMeshHeader53) Public theSectionFrameCount As Integer Public theSectionFrameMinFrameCount As Integer diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index a7f5f92..9de4ffc 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -351,6 +351,8 @@ Public Class SourceModel53 mdlFile.ReadMdlHeader00("MDL File Header 00") mdlFile.ReadMdlHeader01("MDL File Header 01") + mdlFile.ReadMayaStrings() + mdlFile.ReadBones() mdlFile.ReadBoneControllers() mdlFile.ReadAttachments() @@ -398,7 +400,7 @@ Public Class SourceModel53 mdlFile.ReadBoneTransforms() mdlFile.ReadLinearBoneTable() - mdlFile.ReadAABBHeader() + mdlFile.ReadPerTriCollisionHeader() ''TODO: ReadLocalIkAutoPlayLocks() 'mdlFile.ReadFlexControllerUis() diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index 902971a..a8209db 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -127,8 +127,10 @@ - + + + From 2b45c3ee64af039d464316c0bf3e47a0afb35f40 Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Thu, 8 Sep 2022 14:37:07 -0400 Subject: [PATCH 29/39] Changed IKRule structure and made progress on anim sections. --- .../SourceMdlFileData/SourceMdlAnimation.vb | 1 + .../SourceMdlFileData/SourceMdlIkRule.vb | 3 +- .../SourceModel53/SourceMdlFile53.vb | 129 ++++++++++++------ .../SourceModel53/SourceSmdFile53.vb | 4 + 4 files changed, 95 insertions(+), 42 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb index 1105f7d..9e36acf 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb @@ -65,6 +65,7 @@ Public Class SourceMdlAnimation 'MDL 53 values for flags: Public Const MDL53_ANIM_TRANSLATION As Integer = &H2 Public Const MDL53_ANIM_ROTATION As Integer = &H4 + Public Const MDL53_ANIM_SCALE As Integer = &H8 ' Do not use union, because it will have to rely on size of a .NET Framework data type. diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb index e55c1cc..b384fee 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlIkRule.vb @@ -87,7 +87,8 @@ Public Class SourceMdlIkRule Public attachmentNameOffset As Integer - Public unused(3) As Integer + Public unused(6) As Integer + Public unused_MDL53(8) As Integer diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index bfb57b5..f422ee4 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1,4 +1,5 @@ Imports System.IO +Imports System.Runtime.InteropServices Public Class SourceMdlFile53 @@ -945,7 +946,7 @@ Public Class SourceMdlFile53 anAnimationDesc.animOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.ikRuleCount = Me.theInputFileReader.ReadInt32() anAnimationDesc.ikRuleOffset = Me.theInputFileReader.ReadInt32() - anAnimationDesc.animblockIkRuleOffset = Me.theInputFileReader.ReadInt32() + 'anAnimationDesc.animblockIkRuleOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.localHierarchyCount = Me.theInputFileReader.ReadInt32() anAnimationDesc.localHierarchyOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.sectionOffset = Me.theInputFileReader.ReadInt32() @@ -957,6 +958,7 @@ Public Class SourceMdlFile53 'anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() anAnimationDesc.ikRuleZeroFrameOffset = Me.theInputFileReader.ReadInt32() + anAnimationDesc.spanStallTime = Me.theInputFileReader.ReadSingle() For x As Integer = 0 To anAnimationDesc.unused1.Length - 1 anAnimationDesc.unused1(x) = Me.theInputFileReader.ReadInt32() @@ -983,25 +985,15 @@ Public Class SourceMdlFile53 If Me.theMdlFileData.theAnimationDescs IsNot Nothing Then For Each anAnimationDesc As SourceMdlAnimationDesc52 In Me.theMdlFileData.theAnimationDescs If anAnimationDesc.sectionOffset <> 0 AndAlso anAnimationDesc.sectionFrameCount > 0 Then - Dim sectionCount As Integer - - 'FROM: simplify.cpp: - ' panim->numsections = (int)(panim->numframes / panim->sectionframes) + 2; - 'NOTE: It is unclear why "+ 2" is used in studiomdl. - sectionCount = CInt(Math.Truncate(anAnimationDesc.frameCount / anAnimationDesc.sectionFrameCount)) + 2 - - Dim offset As Long - offset = anAnimationDesc.theOffsetStart + anAnimationDesc.sectionOffset - If offset <> Me.theInputFileReader.BaseStream.Position Then - 'TODO: It looks like more than one animDesc can point to same sections, so need to revise how this is done. - 'Me.theMdlFileData.theFileSeekLog.Add(Me.theInputFileReader.BaseStream.Position, Me.theInputFileReader.BaseStream.Position, "[ERROR] anAnimationDesc.theSections [" + anAnimationDesc.theName + "] offset mismatch: pos = " + Me.theInputFileReader.BaseStream.Position.ToString() + " offset = " + offset.ToString()) - Me.theInputFileReader.BaseStream.Seek(offset, SeekOrigin.Begin) - End If + Dim offset As Long = anAnimationDesc.theOffsetStart + anAnimationDesc.sectionOffset + Me.theInputFileReader.BaseStream.Seek(offset, SeekOrigin.Begin) - anAnimationDesc.theSections = New List(Of SourceMdlAnimationSection)(sectionCount) - For sectionIndex As Integer = 0 To sectionCount - 1 + anAnimationDesc.theSections = New List(Of SourceMdlAnimationSection)() + 'NOTE: There does not seem to be a sectionCount value, but the anAnimationDesc.animOffset seems to be the offset of the next data. + ' The "+ 4" represents the size of SourceMdlAnimationSection. + While Me.theInputFileReader.BaseStream.Position + 4 <= anAnimationDesc.theOffsetStart + anAnimationDesc.animOffset Me.ReadMdlAnimationSection(Me.theInputFileReader.BaseStream.Position, anAnimationDesc, Me.theMdlFileData.theFileSeekLog) - Next + End While End If Next End If @@ -1023,15 +1015,52 @@ Public Class SourceMdlFile53 End If anAnimationDesc.theSectionsOfAnimations = New List(Of List(Of SourceMdlAnimation))() - aSectionOfAnimation = New List(Of SourceMdlAnimation)() - anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) - Me.ReadMdlAnimation(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, anAnimationDesc.theSectionsOfAnimations(0), True) + 'aSectionOfAnimation = New List(Of SourceMdlAnimation)() + 'anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) + + ''NOTE: First sectionOfAnimation is at animOffset. + 'Me.ReadMdlAnimation(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, anAnimationDesc.theSectionsOfAnimations(0), True) + If anAnimationDesc.sectionOffset <> 0 AndAlso anAnimationDesc.sectionFrameCount > 0 Then + Dim sectionFrameCount As Integer + Dim sectionCount As Integer + + 'TODO: Shouldn't this be set to largest sectionFrameCount? + Me.theMdlFileData.theSectionFrameCount = anAnimationDesc.sectionFrameCount + If Me.theMdlFileData.theSectionFrameMinFrameCount >= anAnimationDesc.frameCount Then + Me.theMdlFileData.theSectionFrameMinFrameCount = anAnimationDesc.frameCount - 1 + End If + + sectionCount = anAnimationDesc.theSections.Count + + For sectionIndex As Integer = 0 To sectionCount - 1 + aSectionOfAnimation = New List(Of SourceMdlAnimation)() + anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) + Next + + Dim adjustedAnimOffset As Long + For sectionIndex As Integer = 0 To sectionCount - 1 + If sectionIndex < sectionCount - 1 Then + sectionFrameCount = anAnimationDesc.sectionFrameCount + Else + sectionFrameCount = anAnimationDesc.frameCount - ((sectionCount - 1) * anAnimationDesc.sectionFrameCount) + End If + aSectionOfAnimation = anAnimationDesc.theSectionsOfAnimations(sectionIndex) + adjustedAnimOffset = anAnimationDesc.theSections(sectionIndex).animOffset + If adjustedAnimOffset = 0 Then + Exit For + End If + 'Me.ReadMdlAnimation(animInputFileStreamPosition + adjustedAnimOffset, anAnimationDesc, sectionFrameCount, aSectionOfAnimation, (sectionIndex >= sectionCount - 2) Or (anAnimationDesc.frameCount = (sectionIndex + 1) * anAnimationDesc.sectionFrameCount)) + Me.ReadMdlAnimation(animInputFileStreamPosition + adjustedAnimOffset, anAnimationDesc, sectionFrameCount, aSectionOfAnimation, True) + 'Me.ReadMdlAnimation(animInputFileStreamPosition + adjustedAnimOffset, anAnimationDesc, sectionFrameCount, aSectionOfAnimation, sectionIndex >= sectionCount - 1) + Next + Else + aSectionOfAnimation = New List(Of SourceMdlAnimation)() + anAnimationDesc.theSectionsOfAnimations.Add(aSectionOfAnimation) + Me.ReadMdlAnimation(animInputFileStreamPosition + anAnimationDesc.animOffset, anAnimationDesc, anAnimationDesc.frameCount, anAnimationDesc.theSectionsOfAnimations(0), True) + End If - 'If anAnimationDesc.animBlock = 0 Then Me.ReadMdlIkRules(animInputFileStreamPosition, anAnimationDesc) ' Me.ReadLocalHierarchies(animInputFileStreamPosition, anAnimationDesc) - 'End If - Me.ReadMdlMovements(animInputFileStreamPosition, anAnimationDesc) Next End If @@ -1317,6 +1346,7 @@ Public Class SourceMdlFile53 'Dim animValuePointerInputFileStreamPosition As Long Dim rotValuePointerInputFileStreamPosition As Long Dim posValuePointerInputFileStreamPosition As Long + Dim scaleValuePointerInputFileStreamPosition As Long Dim fileOffsetStart As Long Dim fileOffsetEnd As Long Dim anAnimation As SourceMdlAnimation @@ -1358,6 +1388,7 @@ Public Class SourceMdlFile53 anAnimation.TranslationY.the16BitValue = Me.theInputFileReader.ReadUInt16() anAnimation.TranslationZ.the16BitValue = Me.theInputFileReader.ReadUInt16() + scaleValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position anAnimation.ScaleX = New SourceFloat16bits() anAnimation.ScaleY = New SourceFloat16bits() anAnimation.ScaleZ = New SourceFloat16bits() @@ -1372,7 +1403,7 @@ Public Class SourceMdlFile53 'NOTE: If the offset is 0 then there are no more bone animation structures, so end the loop. If anAnimation.nextTitanfall2MdlAnimationOffset = 0 Then - ReadMdlAnimationAnimValues(anAnimation, rotValuePointerInputFileStreamPosition, posValuePointerInputFileStreamPosition, sectionFrameCount, lastSectionIsBeingRead) + ReadMdlAnimationAnimValues(anAnimation, rotValuePointerInputFileStreamPosition, posValuePointerInputFileStreamPosition, scaleValuePointerInputFileStreamPosition, sectionFrameCount, lastSectionIsBeingRead) Exit For Else nextAnimationInputFileStreamPosition = animationInputFileStreamPosition + anAnimation.nextTitanfall2MdlAnimationOffset @@ -1383,7 +1414,7 @@ Public Class SourceMdlFile53 End If If anAnimation.nextTitanfall2MdlAnimationOffset > 32 Then - ReadMdlAnimationAnimValues(anAnimation, rotValuePointerInputFileStreamPosition, posValuePointerInputFileStreamPosition, sectionFrameCount, lastSectionIsBeingRead) + ReadMdlAnimationAnimValues(anAnimation, rotValuePointerInputFileStreamPosition, posValuePointerInputFileStreamPosition, scaleValuePointerInputFileStreamPosition, sectionFrameCount, lastSectionIsBeingRead) End If Me.theInputFileReader.BaseStream.Seek(nextAnimationInputFileStreamPosition, SeekOrigin.Begin) @@ -1399,7 +1430,7 @@ Public Class SourceMdlFile53 'Me.theMdlFileData.theFileSeekLog.LogToEndAndAlignToNextStart(Me.theInputFileReader, fileOffsetEnd, 4, "anAnimationDesc.anAnimation [" + anAnimationDesc.theName + "] alignment") End Sub - Private Sub ReadMdlAnimationAnimValues(ByVal anAnimation As SourceMdlAnimation, ByVal rotValuePointerInputFileStreamPosition As Long, ByVal posValuePointerInputFileStreamPosition As Long, ByVal frameCount As Integer, ByVal lastSectionIsBeingRead As Boolean) + Private Sub ReadMdlAnimationAnimValues(ByVal anAnimation As SourceMdlAnimation, ByVal rotValuePointerInputFileStreamPosition As Long, ByVal posValuePointerInputFileStreamPosition As Long, ByVal scaleValuePointerInputFileStreamPosition As Long, ByVal frameCount As Integer, ByVal lastSectionIsBeingRead As Boolean) If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) = 0 Then anAnimation.theRotV = New SourceMdlAnimationValuePointer() If anAnimation.theRot64bits.XOffset > 0 Then @@ -1431,6 +1462,22 @@ Public Class SourceMdlFile53 Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationZ.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimZValues, "anAnimation.thePosV.theAnimZValues") End If End If + + If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_SCALE) = 0 Then + Dim scaleVector As New SourceMdlAnimationValuePointer() + If anAnimation.ScaleX.the16BitValue > 0 Then + scaleVector.theAnimXValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(scaleValuePointerInputFileStreamPosition + anAnimation.ScaleX.the16BitValue, frameCount, lastSectionIsBeingRead, scaleVector.theAnimXValues, "anAnimation scaleVector.theAnimXValues") + End If + If anAnimation.ScaleY.the16BitValue > 0 Then + scaleVector.theAnimYValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(scaleValuePointerInputFileStreamPosition + anAnimation.ScaleY.the16BitValue, frameCount, lastSectionIsBeingRead, scaleVector.theAnimYValues, "anAnimation scaleVector.theAnimYValues") + End If + If anAnimation.ScaleZ.the16BitValue > 0 Then + scaleVector.theAnimZValues = New List(Of SourceMdlAnimationValue)() + Me.ReadMdlAnimValues(scaleValuePointerInputFileStreamPosition + anAnimation.ScaleZ.the16BitValue, frameCount, lastSectionIsBeingRead, scaleVector.theAnimZValues, "anAnimation scaleVector.theAnimZValues") + End If + End If End Sub '========================================================== @@ -1625,7 +1672,7 @@ Public Class SourceMdlFile53 End If fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 - Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, debugDescription + " (accumulatedTotal = " + CStr(accumulatedTotal) + ")") + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, debugDescription + " (accumulatedTotal = " + CStr(accumulatedTotal) + ") (frameCount = " + CStr(frameCount) + ")") End Sub 'Private Sub DebugQuaternion(ByVal q As SourceQuaternion64) @@ -1658,11 +1705,12 @@ Public Class SourceMdlFile53 Dim fileOffsetOfLastEndOfIkRuleExtraData As Long - If anAnimationDesc.animBlock > 0 AndAlso anAnimationDesc.animblockIkRuleOffset = 0 Then - 'Return 0 - Else - Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition + anAnimationDesc.ikRuleOffset, SeekOrigin.Begin) - End If + 'If anAnimationDesc.animBlock > 0 AndAlso anAnimationDesc.animblockIkRuleOffset = 0 Then + ' 'Return 0 + ' Dim debug As Integer = 4242 + 'Else + Me.theInputFileReader.BaseStream.Seek(animInputFileStreamPosition + anAnimationDesc.ikRuleOffset, SeekOrigin.Begin) + 'End If fileOffsetStart = Me.theInputFileReader.BaseStream.Position fileOffsetOfLastEndOfIkRuleExtraData = 0 @@ -1693,7 +1741,7 @@ Public Class SourceMdlFile53 anIkRule.q.w = Me.theInputFileReader.ReadSingle() anIkRule.compressedIkErrorOffset = Me.theInputFileReader.ReadInt32() - anIkRule.unused2 = Me.theInputFileReader.ReadInt32() + 'anIkRule.unused2 = Me.theInputFileReader.ReadInt32() anIkRule.ikErrorIndexStart = Me.theInputFileReader.ReadInt32() anIkRule.ikErrorOffset = Me.theInputFileReader.ReadInt32() @@ -1702,19 +1750,19 @@ Public Class SourceMdlFile53 anIkRule.influenceTail = Me.theInputFileReader.ReadSingle() anIkRule.influenceEnd = Me.theInputFileReader.ReadSingle() - anIkRule.unused3 = Me.theInputFileReader.ReadSingle() + 'anIkRule.unused3 = Me.theInputFileReader.ReadSingle() anIkRule.contact = Me.theInputFileReader.ReadSingle() anIkRule.drop = Me.theInputFileReader.ReadSingle() anIkRule.top = Me.theInputFileReader.ReadSingle() - anIkRule.unused6 = Me.theInputFileReader.ReadInt32() - anIkRule.unused7 = Me.theInputFileReader.ReadInt32() - anIkRule.unused8 = Me.theInputFileReader.ReadInt32() + 'anIkRule.unused6 = Me.theInputFileReader.ReadInt32() + 'anIkRule.unused7 = Me.theInputFileReader.ReadInt32() + 'anIkRule.unused8 = Me.theInputFileReader.ReadInt32() anIkRule.attachmentNameOffset = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To anIkRule.unused.Length - 1 - anIkRule.unused(x) = Me.theInputFileReader.ReadInt32() + For x As Integer = 0 To anIkRule.unused_MDL53.Length - 1 + anIkRule.unused_MDL53(x) = Me.theInputFileReader.ReadInt32() Next anAnimationDesc.theIkRules.Add(anIkRule) @@ -1856,7 +1904,6 @@ Public Class SourceMdlFile53 'animSectionInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anAnimSection As New SourceMdlAnimationSection() - anAnimSection.animBlock = Me.theInputFileReader.ReadInt32() anAnimSection.animOffset = Me.theInputFileReader.ReadInt32() anAnimationDesc.theSections.Add(anAnimSection) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 7ad95c2..1c9be0b 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -1251,6 +1251,10 @@ Public Class SourceSmdFile53 anAnimation = Nothing aSectionOfAnimation = Nothing If anAnimationDesc.theSectionsOfAnimations IsNot Nothing Then + If sectionIndex >= anAnimationDesc.theSectionsOfAnimations.Count Then + Dim debug As Integer = 4242 + Exit Sub + End If aSectionOfAnimation = anAnimationDesc.theSectionsOfAnimations(sectionIndex) If animIndex >= 0 AndAlso animIndex < aSectionOfAnimation.Count Then anAnimation = aSectionOfAnimation(animIndex) From b6b0c2e9c4d3209323ca9c44f2b25ebd0af0a386 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 8 Sep 2022 14:48:57 -0400 Subject: [PATCH 30/39] rui start --- .../GameModel/SourceModel53/SourceMdlFile53.vb | 15 +++++++++++++++ .../Core/GameModel/SourceModel53/SourceModel53.vb | 7 +++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 181a04d..aae0093 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -3044,6 +3044,21 @@ Public Class SourceMdlFile53 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "aFlexRule.theFlexOps " + aFlexRule.theFlexOps.Count.ToString()) End Sub + Public Sub ReadRui() + If Me.theMdlFileData.ruiCount > 0 Then + Dim fileOffsetStart As Long + Dim fileOffsetEnd As Long + + Me.theInputFileReader.BaseStream.Seek(Me.theMdlFileData.ruiOffset, SeekOrigin.Begin) + fileOffsetStart = Me.theInputFileReader.BaseStream.Position + + 'Me.theInputFileReader.ReadBytes(Me.theMdlFileData.ikChainOffset - Me.theMdlFileData.ruiOffset) + + fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 + Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "theMdlFileData.theRuiMeshes") + End If + End Sub + Public Sub ReadIkChains() If Me.theMdlFileData.ikChainCount > 0 Then Dim ikChainInputFileStreamPosition As Long diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index 9de4ffc..a261f3a 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -376,18 +376,17 @@ Public Class SourceModel53 mdlFile.ReadLocalNodes() 'NOTE: Read flex descs before body parts so that flexes (within body parts) can add info to flex descs. - mdlFile.ReadFlexDescs() + 'mdlFile.ReadFlexDescs() mdlFile.ReadBodyParts() '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.ReadIkLocks() - 'mdlFile.ReadMouths() mdlFile.ReadPoseParamDescs() mdlFile.ReadModelGroups() - ''TODO: Me.ReadAnimBlocks() - ''TODO: Me.ReadAnimBlockName() + + mdlFile.ReadRui() 'NOTE: V53 MDLs normally don't have more than one texture path due to how RPak materials work. mdlFile.ReadTexturePaths() From 8c943e1e832a836b88436992d26845569bdec78e Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Thu, 8 Sep 2022 15:29:04 -0400 Subject: [PATCH 31/39] fix error and activity modifiers --- Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb | 4 ++-- Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index cd10742..a191a7d 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1775,8 +1775,8 @@ Public Class SourceMdlFile53 anIkRule.attachmentNameOffset = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To anIkRule.unused_MDL53.Length - 1 - anIkRule.unused_MDL53(x) = Me.theInputFileReader.ReadInt32() + For x As Integer = 0 To anIkRule.unused.Length - 1 + anIkRule.unused(x) = Me.theInputFileReader.ReadInt32() Next anAnimationDesc.theIkRules.Add(anIkRule) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 32f88e3..4fa2ff0 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -2310,7 +2310,9 @@ Public Class SourceQcFile53 For Each activityModifier As SourceMdlActivityModifier In aSequenceDesc.theActivityModifiers line = vbTab line += "activitymodifier " + line += """" line += activityModifier.theName + line += """" Me.theOutputFileStreamWriter.WriteLine(line) Next End If From 6ec5f736cfc9db9a568f26f58d5ee25a14100455 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Tue, 13 Sep 2022 00:21:39 -0400 Subject: [PATCH 32/39] minor changes --- .../SourceMdlFileData/SourceMdlAnimation.vb | 8 +++++--- .../GameModel/SourceModel53/SourceMdlFile53.vb | 6 +++--- .../GameModel/SourceModel53/SourceSmdFile53.vb | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb index 9e36acf..0a936c7 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb @@ -62,10 +62,12 @@ Public Class SourceMdlAnimation Public Const STUDIO_ANIM_ANIMROT As Integer = &H8 Public Const STUDIO_ANIM_DELTA As Integer = &H10 Public Const STUDIO_ANIM_RAWROT2 As Integer = &H20 + 'MDL 53 values for flags: - Public Const MDL53_ANIM_TRANSLATION As Integer = &H2 - Public Const MDL53_ANIM_ROTATION As Integer = &H4 - Public Const MDL53_ANIM_SCALE As Integer = &H8 + Public Const STUDIO_ANIM_RAWPOS_53 As Integer = &H2 + Public Const STUDIO_ANIM_RAWROT_53 As Integer = &H4 + Public Const STUDIO_ANIM_RAWSCALE_53 As Integer = &H8 + Public Const STUDIO_ANIM_UNKFLAG_53 As Integer = &H10 ' Do not use union, because it will have to rely on size of a .NET Framework data type. diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index a191a7d..346a470 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1449,7 +1449,7 @@ Public Class SourceMdlFile53 End Sub Private Sub ReadMdlAnimationAnimValues(ByVal anAnimation As SourceMdlAnimation, ByVal rotValuePointerInputFileStreamPosition As Long, ByVal posValuePointerInputFileStreamPosition As Long, ByVal scaleValuePointerInputFileStreamPosition As Long, ByVal frameCount As Integer, ByVal lastSectionIsBeingRead As Boolean) - If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) = 0 Then + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT_53) = 0 Then anAnimation.theRotV = New SourceMdlAnimationValuePointer() If anAnimation.theRot64bits.XOffset > 0 Then anAnimation.theRotV.theAnimXValues = New List(Of SourceMdlAnimationValue)() @@ -1465,7 +1465,7 @@ Public Class SourceMdlFile53 End If End If - If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) = 0 Then + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS_53) = 0 Then anAnimation.thePosV = New SourceMdlAnimationValuePointer() If anAnimation.TranslationX.the16BitValue > 0 Then anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() @@ -1481,7 +1481,7 @@ Public Class SourceMdlFile53 End If End If - If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_SCALE) = 0 Then + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWSCALE_53) = 0 Then Dim scaleVector As New SourceMdlAnimationValuePointer() If anAnimation.ScaleX.the16BitValue > 0 Then scaleVector.theAnimXValues = New List(Of SourceMdlAnimationValue)() diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 926cfe4..18b7674 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -1569,7 +1569,7 @@ Public Class SourceSmdFile53 Dim rot As New SourceQuaternion() Dim angleVector As New SourceVector() - If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_ROTATION) > 0 Then + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT_53) > 0 Then rot.x = anAnimation.theRot64bits.x rot.y = anAnimation.theRot64bits.y rot.z = anAnimation.theRot64bits.z @@ -1582,6 +1582,15 @@ Public Class SourceSmdFile53 angleVector.debug_text = "raw64 (" + rot.x.ToString() + ", " + rot.y.ToString() + ", " + rot.z.ToString() + ", " + rot.w.ToString() + ")" Return angleVector + ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_UNKFLAG_53) > 0 And SourceMdlAnimation.STUDIO_ANIM_RAWROT_53 = 0 Then + angleVector.x = aBone.rotation.x + angleVector.y = aBone.rotation.y + angleVector.z = aBone.rotation.z + rotationQuat.x = 0 + rotationQuat.y = 0 + rotationQuat.z = 0 + rotationQuat.w = 0 + angleVector.debug_text = "bone" End If Try @@ -1695,7 +1704,7 @@ Public Class SourceSmdFile53 Private Function CalcBonePosition(ByVal frameIndex As Integer, ByVal s As Double, ByVal aBone As SourceMdlBone53, ByVal anAnimation As SourceMdlAnimation) As SourceVector Dim pos As New SourceVector() - If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) > 0 Then + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS_53) > 0 Then pos.x = anAnimation.TranslationX.TheFloatValue pos.y = anAnimation.TranslationY.TheFloatValue pos.z = anAnimation.TranslationZ.TheFloatValue @@ -1724,6 +1733,7 @@ Public Class SourceSmdFile53 pos.z += aBone.position.z End If pos.debug_text = "anim" + 'ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then ' pos.x = 0 ' pos.y = 0 From 8a9086a1a7913fb347f0c5690136c1711936b972 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Tue, 13 Sep 2022 15:25:31 -0400 Subject: [PATCH 33/39] temporary mass fix + activity modifier on v52 --- Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb | 5 ++++- Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb index 849501f..a38922c 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb @@ -2372,7 +2372,9 @@ Public Class SourceQcFile52 For Each activityModifier As SourceMdlActivityModifier In aSequenceDesc.theActivityModifiers line = vbTab line += "activitymodifier " + line += """" line += activityModifier.theName + line += """" Me.theOutputFileStreamWriter.WriteLine(line) Next End If @@ -3400,9 +3402,10 @@ Public Class SourceQcFile52 Private Sub WriteCollisionModelOrCollisionJointsOptions() Dim line As String = "" + ' for some reason it doesn't read this correctly so I am doing a janky fix for now. line = vbTab line += "$mass " - line += Me.thePhyFileData.theSourcePhyEditParamsSection.totalMass.ToString("0.######", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.mass.ToString("0.######", TheApp.InternalNumberFormat) Me.theOutputFileStreamWriter.WriteLine(line) line = vbTab line += "$inertia " diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 4fa2ff0..01c299c 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -3164,9 +3164,10 @@ Public Class SourceQcFile53 Private Sub WriteCollisionModelOrCollisionJointsOptions() Dim line As String = "" + ' for some reason it doesn't read this correctly so I am doing a janky fix for now. line = vbTab line += "$mass " - line += Me.thePhyFileData.theSourcePhyEditParamsSection.totalMass.ToString("0.######", TheApp.InternalNumberFormat) + line += Me.theMdlFileData.mass.ToString("0.######", TheApp.InternalNumberFormat) Me.theOutputFileStreamWriter.WriteLine(line) line = vbTab line += "$inertia " From 4821ef419c6254bd7d5b3dcdf4bd5435c431a767 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Mon, 19 Sep 2022 16:24:42 -0400 Subject: [PATCH 34/39] fixes last issue with anims sometimes having bad position easy fix tbh dunno how I didn't see this sooner. --- Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 18b7674..36e6e0c 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -1715,19 +1715,19 @@ Public Class SourceSmdFile53 If anAnimation.thePosV IsNot Nothing Then Dim posV As SourceMdlAnimationValuePointer = anAnimation.thePosV If anAnimation.TranslationX.the16BitValue <= 0 Then - pos.x = 0 + pos.x += aBone.position.x Else pos.x = Me.ExtractAnimValue(frameIndex, posV.theAnimXValues, anAnimation.TranslationScale) pos.x += aBone.position.x End If If anAnimation.TranslationY.the16BitValue <= 0 Then - pos.y = 0 + pos.y += aBone.position.y Else pos.y = Me.ExtractAnimValue(frameIndex, posV.theAnimYValues, anAnimation.TranslationScale) pos.y += aBone.position.y End If If anAnimation.TranslationZ.the16BitValue <= 0 Then - pos.z = 0 + pos.z += aBone.position.z Else pos.z = Me.ExtractAnimValue(frameIndex, posV.theAnimZValues, anAnimation.TranslationScale) pos.z += aBone.position.z From 35871eb142f41107eea158e3c9ff2abc07b696e8 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Tue, 20 Sep 2022 17:35:58 -0400 Subject: [PATCH 35/39] fix v53 activity modifiers --- .../SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb | 2 ++ Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb | 1 + 2 files changed, 3 insertions(+) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb index 4f8549d..7389aaf 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb @@ -13,6 +13,8 @@ Public Class SourceMdlActivityModifier Public nameOffset As Integer + ' V53 has an int here. + Public unkV53 As Integer Public theName As String diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index b4b9d78..011770a 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -2416,6 +2416,7 @@ Public Class SourceMdlFile53 activityModifierInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anActivityModifier As New SourceMdlActivityModifier() anActivityModifier.nameOffset = Me.theInputFileReader.ReadInt32() + anActivityModifier.unkV53 = Me.theInputFileReader.ReadInt32() aSeqDesc.theActivityModifiers.Add(anActivityModifier) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position From 19e5a150048388ed24979b70d43ff36da5ab891f Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Sun, 25 Sep 2022 00:09:57 -0400 Subject: [PATCH 36/39] add support for delta anims in v53 --- .../SourceMdlActivityModifier.vb | 2 +- .../SourceMdlFileData/SourceMdlAnimation.vb | 21 ++- .../GameModel/SourceModel52/SourceModel52.vb | 2 + .../GameModel/SourceModel52/SourceQcFile52.vb | 15 ++ .../SourceModel53/SourceMdlFile53.vb | 29 ++-- .../GameModel/SourceModel53/SourceModel53.vb | 2 + .../GameModel/SourceModel53/SourceQcFile53.vb | 17 ++ .../SourceModel53/SourceSmdFile53.vb | 158 ++++++++++-------- 8 files changed, 155 insertions(+), 91 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb index 7389aaf..f5ecb05 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb @@ -13,7 +13,7 @@ Public Class SourceMdlActivityModifier Public nameOffset As Integer - ' V53 has an int here. + ' V53 has an int here that needs to be read for proper output. 0 or 1. Public unkV53 As Integer Public theName As String diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb index 0a936c7..6cc3d93 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlAnimation.vb @@ -33,16 +33,15 @@ Public Class SourceMdlAnimation Public nextSourceMdlAnimationOffset As Short 'MDL 53 stuff - Public TranslationScale As Double - Public Flags2 As Byte - Public Flags3 As Byte + Public positionScale As Double + Public unk As Short 'Public OffsetX As Short 'Public OffsetY As Short 'Public OffsetZ As Short 'Public OffsetL As Short - Public TranslationX As SourceFloat16bits - Public TranslationY As SourceFloat16bits - Public TranslationZ As SourceFloat16bits + Public PosX As SourceFloat16bits + Public PosY As SourceFloat16bits + Public PosZ As SourceFloat16bits Public ScaleX As SourceFloat16bits Public ScaleY As SourceFloat16bits Public ScaleZ As SourceFloat16bits @@ -63,7 +62,15 @@ Public Class SourceMdlAnimation Public Const STUDIO_ANIM_DELTA As Integer = &H10 Public Const STUDIO_ANIM_RAWROT2 As Integer = &H20 - 'MDL 53 values for flags: + ' MDL 53 values for flags: + '#define STUDIO_ANIM_DELTA_53 0x01 // this appears to be delta until proven otherwise + '// These work as toggles, flag enabled is raw data, flag disabled is pointers, see 'STUDIO_ANIM_READBONE_53' for exception. + '#define STUDIO_ANIM_RAWPOS_53 0x02 // Vector48 + '#define STUDIO_ANIM_RAWROT_53 0x04 // Quaternion48 + '#define STUDIO_ANIM_RAWSCALE_53 0x08 // Vector48 + '// if above flag is disabled and below is enabled there is special exceptions + '#define STUDIO_ANIM_READBONE_53 0x10 // read bone data if any Of the above are disabled, only observed For rotation + Public Const STUDIO_ANIM_DELTA_53 As Integer = &H1 Public Const STUDIO_ANIM_RAWPOS_53 As Integer = &H2 Public Const STUDIO_ANIM_RAWROT_53 As Integer = &H4 Public Const STUDIO_ANIM_RAWSCALE_53 As Integer = &H8 diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb index 5ecff3f..a30e4b1 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceModel52.vb @@ -470,6 +470,8 @@ Public Class SourceModel52 qcFile.WriteStaticPropCommand() qcFile.WriteConstDirectionalLightCommand() + qcFile.WriteFadeDistanceCommand() + 'If Me.theMdlFileData.theModelCommandIsUsed Then ' qcFile.WriteModelCommand() ' qcFile.WriteBodyGroupCommand(1) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb index a38922c..b9336b9 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb @@ -214,6 +214,21 @@ Public Class SourceQcFile52 ' Return pathFileName 'End Function + Public Sub WriteFadeDistanceCommand() + Dim line As String = "" + + '$fadedist -1.0 + Me.theOutputFileStreamWriter.WriteLine() + + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + line = "//$FadeDist " + Else + line = "//$fadedist " + End If + line += Me.theMdlFileData.fadeDistance.ToString("0.######", TheApp.InternalNumberFormat) + Me.theOutputFileStreamWriter.WriteLine(line) + End Sub + Public Sub WriteModelCommand() Dim line As String = "" Dim aBodyPart As SourceMdlBodyPart diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 011770a..a8d47b8 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1384,11 +1384,10 @@ Public Class SourceMdlFile53 anAnimation = New SourceMdlAnimation() aSectionOfAnimation.Add(anAnimation) - anAnimation.TranslationScale = Me.theInputFileReader.ReadSingle() + anAnimation.positionScale = Me.theInputFileReader.ReadSingle() anAnimation.boneIndex = Me.theInputFileReader.ReadByte() anAnimation.flags = Me.theInputFileReader.ReadByte() - anAnimation.Flags2 = Me.theInputFileReader.ReadByte() - anAnimation.Flags3 = Me.theInputFileReader.ReadByte() + anAnimation.unk = Me.theInputFileReader.ReadInt16() 'anAnimation.OffsetX = Me.theInputFileReader.ReadInt16() 'anAnimation.OffsetY = Me.theInputFileReader.ReadInt16() @@ -1399,12 +1398,12 @@ Public Class SourceMdlFile53 anAnimation.theRot64bits.theBytes = Me.theInputFileReader.ReadBytes(8) posValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position - anAnimation.TranslationX = New SourceFloat16bits() - anAnimation.TranslationY = New SourceFloat16bits() - anAnimation.TranslationZ = New SourceFloat16bits() - anAnimation.TranslationX.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.TranslationY.the16BitValue = Me.theInputFileReader.ReadUInt16() - anAnimation.TranslationZ.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.PosX = New SourceFloat16bits() + anAnimation.PosY = New SourceFloat16bits() + anAnimation.PosZ = New SourceFloat16bits() + anAnimation.PosX.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.PosY.the16BitValue = Me.theInputFileReader.ReadUInt16() + anAnimation.PosZ.the16BitValue = Me.theInputFileReader.ReadUInt16() scaleValuePointerInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position anAnimation.ScaleX = New SourceFloat16bits() @@ -1467,17 +1466,17 @@ Public Class SourceMdlFile53 If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS_53) = 0 Then anAnimation.thePosV = New SourceMdlAnimationValuePointer() - If anAnimation.TranslationX.the16BitValue > 0 Then + If anAnimation.PosX.the16BitValue > 0 Then anAnimation.thePosV.theAnimXValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationX.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.PosX.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimXValues, "anAnimation.thePosV.theAnimXValues") End If - If anAnimation.TranslationY.the16BitValue > 0 Then + If anAnimation.PosY.the16BitValue > 0 Then anAnimation.thePosV.theAnimYValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationY.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimYValues, "anAnimation.thePosV.theAnimYValues") + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.PosY.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimYValues, "anAnimation.thePosV.theAnimYValues") End If - If anAnimation.TranslationZ.the16BitValue > 0 Then + If anAnimation.PosZ.the16BitValue > 0 Then anAnimation.thePosV.theAnimZValues = New List(Of SourceMdlAnimationValue)() - Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.TranslationZ.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimZValues, "anAnimation.thePosV.theAnimZValues") + Me.ReadMdlAnimValues(posValuePointerInputFileStreamPosition + anAnimation.PosZ.the16BitValue, frameCount, lastSectionIsBeingRead, anAnimation.thePosV.theAnimZValues, "anAnimation.thePosV.theAnimZValues") End If End If diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb index a261f3a..273a292 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceModel53.vb @@ -487,6 +487,8 @@ Public Class SourceModel53 qcFile.WriteStaticPropCommand() qcFile.WriteConstDirectionalLightCommand() + qcFile.WriteFadeDistanceCommand() + 'If Me.theMdlFileData.theModelCommandIsUsed Then ' qcFile.WriteModelCommand() ' qcFile.WriteBodyGroupCommand(1) diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 01c299c..6a7665a 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -214,6 +214,21 @@ Public Class SourceQcFile53 ' Return pathFileName 'End Function + Public Sub WriteFadeDistanceCommand() + Dim line As String = "" + + '$fadedist -1.0 + Me.theOutputFileStreamWriter.WriteLine() + + If TheApp.Settings.DecompileQcUseMixedCaseForKeywordsIsChecked Then + line = "//$FadeDist " + Else + line = "//$fadedist " + End If + line += Me.theMdlFileData.fadeDistance.ToString("0.######", TheApp.InternalNumberFormat) + Me.theOutputFileStreamWriter.WriteLine(line) + End Sub + Public Sub WriteModelCommand() Dim line As String = "" Dim aBodyPart As SourceMdlBodyPart @@ -2313,6 +2328,8 @@ Public Class SourceQcFile53 line += """" line += activityModifier.theName line += """" + line += " // " + line += activityModifier.unkV53.ToString(TheApp.InternalNumberFormat) Me.theOutputFileStreamWriter.WriteLine(line) Next End If diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb index 36e6e0c..c64919f 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceSmdFile53.vb @@ -1320,9 +1320,9 @@ Public Class SourceSmdFile53 '------ 'aFrameLine.position = New SourceVector() 'If (anAnimation.flags And SourceMdlAnimation.MDL53_ANIM_TRANSLATION) > 0 Then - ' aFrameLine.position.x = anAnimation.TranslationX.TheFloatValue - ' aFrameLine.position.y = anAnimation.TranslationY.TheFloatValue - ' aFrameLine.position.z = anAnimation.TranslationZ.TheFloatValue + ' aFrameLine.position.x = anAnimation.PosX.TheFloatValue + ' aFrameLine.position.y = anAnimation.PosY.TheFloatValue + ' aFrameLine.position.z = anAnimation.PosZ.TheFloatValue ' aFrameLine.position.debug_text = "anim" 'Else ' aFrameLine.position.x = aBone.position.x @@ -1582,48 +1582,18 @@ Public Class SourceSmdFile53 angleVector.debug_text = "raw64 (" + rot.x.ToString() + ", " + rot.y.ToString() + ", " + rot.z.ToString() + ", " + rot.w.ToString() + ")" Return angleVector - ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_UNKFLAG_53) > 0 And SourceMdlAnimation.STUDIO_ANIM_RAWROT_53 = 0 Then - angleVector.x = aBone.rotation.x - angleVector.y = aBone.rotation.y - angleVector.z = aBone.rotation.z - rotationQuat.x = 0 - rotationQuat.y = 0 - rotationQuat.z = 0 - rotationQuat.w = 0 - angleVector.debug_text = "bone" End If - Try - If anAnimation.theRotV IsNot Nothing Then - Dim rotV As SourceMdlAnimationValuePointer = anAnimation.theRotV - If anAnimation.theRot64bits.XOffset <= 0 Then - angleVector.x = 0 - Else - angleVector.x = Me.ExtractAnimValue(frameIndex, rotV.theAnimXValues, aBone.rotationScale.x) - angleVector.x += aBone.rotation.x - End If - If anAnimation.theRot64bits.YOffset <= 0 Then - angleVector.y = 0 - Else - angleVector.y = Me.ExtractAnimValue(frameIndex, rotV.theAnimYValues, aBone.rotationScale.y) - angleVector.y += aBone.rotation.y - End If - If anAnimation.theRot64bits.ZOffset <= 0 Then - angleVector.z = 0 - Else - angleVector.z = Me.ExtractAnimValue(frameIndex, rotV.theAnimZValues, aBone.rotationScale.z) - angleVector.z += aBone.rotation.z - End If - angleVector.debug_text = "anim" - 'ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then - ' angleVector.x = 0 - ' angleVector.y = 0 - ' angleVector.z = 0 - ' rotationQuat.x = 0 - ' rotationQuat.y = 0 - ' rotationQuat.z = 0 - ' rotationQuat.w = 0 - ' angleVector.debug_text = "delta" + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWROT_53) > 0 Then + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA_53) > 0 Then + angleVector.x = 0 + angleVector.y = 0 + angleVector.z = 0 + rotationQuat.x = 0 + rotationQuat.y = 0 + rotationQuat.z = 0 + rotationQuat.w = 0 + angleVector.debug_text = "delta" Else angleVector.x = aBone.rotation.x angleVector.y = aBone.rotation.y @@ -1634,9 +1604,49 @@ Public Class SourceSmdFile53 rotationQuat.w = 0 angleVector.debug_text = "bone" End If - Catch ex As Exception - Dim debug As Integer = 4242 - End Try + Return angleVector + End If + + 'Try + If anAnimation.theRotV IsNot Nothing Then + Dim rotV As SourceMdlAnimationValuePointer = anAnimation.theRotV + If anAnimation.theRot64bits.XOffset <= 0 Then + angleVector.x = 0 + Else + angleVector.x = Me.ExtractAnimValue(frameIndex, rotV.theAnimXValues, aBone.rotationScale.x) + End If + If anAnimation.theRot64bits.YOffset <= 0 Then + angleVector.y = 0 + Else + angleVector.y = Me.ExtractAnimValue(frameIndex, rotV.theAnimYValues, aBone.rotationScale.y) + End If + If anAnimation.theRot64bits.ZOffset <= 0 Then + angleVector.z = 0 + Else + angleVector.z = Me.ExtractAnimValue(frameIndex, rotV.theAnimZValues, aBone.rotationScale.z) + End If + angleVector.debug_text = "anim" + + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA_53) = 0 Then + angleVector.x += aBone.rotation.x + angleVector.y += aBone.rotation.y + angleVector.z += aBone.rotation.z + angleVector.debug_text += "+bone" + End If + + Else + angleVector.x = aBone.rotation.x + angleVector.y = aBone.rotation.y + angleVector.z = aBone.rotation.z + rotationQuat.x = 0 + rotationQuat.y = 0 + rotationQuat.z = 0 + rotationQuat.w = 0 + angleVector.debug_text = "bone" + End If + 'Catch ex As Exception + 'Dim debug As Integer = 4242 + 'End Try rotationQuat = MathModule.EulerAnglesToQuaternion(angleVector) Return angleVector @@ -1705,40 +1715,52 @@ Public Class SourceSmdFile53 Dim pos As New SourceVector() If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_RAWPOS_53) > 0 Then - pos.x = anAnimation.TranslationX.TheFloatValue - pos.y = anAnimation.TranslationY.TheFloatValue - pos.z = anAnimation.TranslationZ.TheFloatValue - pos.debug_text = "raw" - Return pos + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA_53) > 0 Then + pos.x = 0 + pos.y = 0 + pos.z = 0 + pos.debug_text = "delta" + Return pos + Else + pos.x = anAnimation.PosX.TheFloatValue + pos.y = anAnimation.PosY.TheFloatValue + pos.z = anAnimation.PosZ.TheFloatValue + pos.debug_text = "raw" + Return pos + End If End If If anAnimation.thePosV IsNot Nothing Then Dim posV As SourceMdlAnimationValuePointer = anAnimation.thePosV - If anAnimation.TranslationX.the16BitValue <= 0 Then - pos.x += aBone.position.x + + If anAnimation.PosX.the16BitValue <= 0 Then + pos.x = 0 Else - pos.x = Me.ExtractAnimValue(frameIndex, posV.theAnimXValues, anAnimation.TranslationScale) - pos.x += aBone.position.x + pos.x = Me.ExtractAnimValue(frameIndex, posV.theAnimXValues, anAnimation.positionScale) End If - If anAnimation.TranslationY.the16BitValue <= 0 Then - pos.y += aBone.position.y + + If anAnimation.PosY.the16BitValue <= 0 Then + pos.y = 0 Else - pos.y = Me.ExtractAnimValue(frameIndex, posV.theAnimYValues, anAnimation.TranslationScale) - pos.y += aBone.position.y + pos.y = Me.ExtractAnimValue(frameIndex, posV.theAnimYValues, anAnimation.positionScale) End If - If anAnimation.TranslationZ.the16BitValue <= 0 Then - pos.z += aBone.position.z + + If anAnimation.PosZ.the16BitValue <= 0 Then + pos.z = 0 Else - pos.z = Me.ExtractAnimValue(frameIndex, posV.theAnimZValues, anAnimation.TranslationScale) - pos.z += aBone.position.z + pos.z = Me.ExtractAnimValue(frameIndex, posV.theAnimZValues, anAnimation.positionScale) End If + pos.debug_text = "anim" - 'ElseIf (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA) > 0 Then - ' pos.x = 0 - ' pos.y = 0 - ' pos.z = 0 - ' pos.debug_text = "delta" + If (anAnimation.flags And SourceMdlAnimation.STUDIO_ANIM_DELTA_53) = 0 Then + pos.x += aBone.position.x + pos.y += aBone.position.y + pos.z += aBone.position.z + pos.debug_text += "+bone" + End If + + ' never used from what I have seen Else pos.x = aBone.position.x pos.y = aBone.position.y From 7a30198b28898a20ae6adff6df381ae9d5198f9d Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Sun, 13 Nov 2022 16:32:59 -0500 Subject: [PATCH 37/39] fix actmods and tweak frame anims for v52 --- .../SourceAniFileData/SourceAniFrameAnim52.vb | 28 +++----- .../SourceModel52/SourceMdlFile52.vb | 65 ++++++++----------- .../SourceModel53/SourceMdlFile53.vb | 6 +- 3 files changed, 37 insertions(+), 62 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceAniFileData/SourceAniFrameAnim52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceAniFileData/SourceAniFrameAnim52.vb index 8f1d8c0..7f4eb43 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceAniFileData/SourceAniFrameAnim52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceAniFileData/SourceAniFrameAnim52.vb @@ -21,7 +21,9 @@ Public Class SourceAniFrameAnim52 Public constantsOffset As Integer Public frameOffset As Integer Public frameLength As Integer - Public unused(2) As Integer + Public oldBoneFlags As Integer + Public unkDataIndex As Integer + Public unused As Integer 'NOTE: These are indexed by global bone index. @@ -34,26 +36,12 @@ Public Class SourceAniFrameAnim52 'NOTE: This is indexed by frame index and global bone index. Public theBoneFrameDataInfos As List(Of List(Of BoneFrameDataInfo49)) - 'FROM: AlienSwarm_source\src\public\studio.h - ' Values for the field, theBoneFlags: - '#define STUDIO_FRAME_RAWPOS 0x01 // Vector48 in constants - '#define STUDIO_FRAME_RAWROT 0x02 // Quaternion48 in constants - '#define STUDIO_FRAME_ANIMPOS 0x04 // Vector48 in framedata - '#define STUDIO_FRAME_ANIMROT 0x08 // Quaternion48 in framedata - '#define STUDIO_FRAME_FULLANIMPOS 0x10 // Vector in framedata + ' In V52 they added scale tracks and redid how these work Public Const STUDIO_FRAME_RAWPOS As Integer = &H1 Public Const STUDIO_FRAME_RAWROT As Integer = &H2 - Public Const STUDIO_FRAME_ANIMPOS As Integer = &H4 - Public Const STUDIO_FRAME_ANIMROT As Integer = &H8 - Public Const STUDIO_FRAME_FULLANIMPOS As Integer = &H10 - - '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 - '#define STUDIO_FRAME_CONST_ROT2 0x40 // Quaternion48S in constants - '#define STUDIO_FRAME_ANIM_ROT2 0x80 // Quaternion48S in framedata - Public Const STUDIO_FRAME_CONST_ROT2 As Integer = &H40 - Public Const STUDIO_FRAME_ANIM_ROT2 As Integer = &H80 - + Public Const STUDIO_FRAME_RAWSCALE As Integer = &H4 + Public Const STUDIO_FRAME_ANIMPOS As Integer = &H8 + Public Const STUDIO_FRAME_ANIMROT As Integer = &H10 + Public Const STUDIO_FRAME_ANIMSCALE As Integer = &H20 End Class diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 1d22239..8385ea8 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -1326,9 +1326,9 @@ Public Class SourceMdlFile52 aSectionOfAnimation.constantsOffset = Me.theInputFileReader.ReadInt32() aSectionOfAnimation.frameOffset = Me.theInputFileReader.ReadInt32() aSectionOfAnimation.frameLength = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To aSectionOfAnimation.unused.Length - 1 - aSectionOfAnimation.unused(x) = Me.theInputFileReader.ReadInt32() - Next + aSectionOfAnimation.oldBoneFlags = Me.theInputFileReader.ReadInt32() + aSectionOfAnimation.unkDataIndex = Me.theInputFileReader.ReadInt32() + aSectionOfAnimation.unused = Me.theInputFileReader.ReadInt32() fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.aSectionOfAnimation [" + anAnimationDesc.theName + "] (frameCount = " + CStr(anAnimationDesc.frameCount) + "; sectionFrameCount = " + CStr(sectionFrameCount) + ")") @@ -1402,22 +1402,24 @@ Public Class SourceMdlFile52 aSectionOfAnimation.theBoneConstantInfos.Add(aBoneConstantInfo) 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) - End If - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWROT) > 0 Then + If (boneFlag And SourceAniFrameAnim52.STUDIO_FRAME_RAWROT) > 0 Then aBoneConstantInfo.theConstantRawRot = New SourceQuaternion48bits() aBoneConstantInfo.theConstantRawRot.theXInput = Me.theInputFileReader.ReadUInt16() aBoneConstantInfo.theConstantRawRot.theYInput = Me.theInputFileReader.ReadUInt16() aBoneConstantInfo.theConstantRawRot.theZWInput = Me.theInputFileReader.ReadUInt16() End If - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_RAWPOS) > 0 Then + If (boneFlag And SourceAniFrameAnim52.STUDIO_FRAME_RAWPOS) > 0 Then aBoneConstantInfo.theConstantRawPos = New SourceVector48bits() aBoneConstantInfo.theConstantRawPos.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() aBoneConstantInfo.theConstantRawPos.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() aBoneConstantInfo.theConstantRawPos.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() End If + ' just read these because we can't really use it + If (boneFlag And SourceAniFrameAnim52.STUDIO_FRAME_RAWSCALE) > 0 Then + Me.theInputFileReader.ReadUInt16() + Me.theInputFileReader.ReadUInt16() + Me.theInputFileReader.ReadUInt16() + End If Next If Me.theInputFileReader.BaseStream.Position > fileOffsetStart Then @@ -1455,33 +1457,23 @@ Public Class SourceMdlFile52 boneFlag = aSectionOfAnimation.theBoneFlags(boneIndex) - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIM_ROT2) > 0 Then - aBoneFrameDataInfo.theAnimRotationUnknown = New SourceQuaternion48bitsViaBytes() - aBoneFrameDataInfo.theAnimRotationUnknown.theBytes = Me.theInputFileReader.ReadBytes(6) - End If - 'If (boneFlag And SourceAniFrameAnim.STUDIO_FRAME_ANIMROT) > 0 Then - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_FULLANIMPOS) > 0 Then + If (boneFlag And SourceAniFrameAnim52.STUDIO_FRAME_ANIMROT) > 0 Then aBoneFrameDataInfo.theAnimRotation = New SourceQuaternion48bits() aBoneFrameDataInfo.theAnimRotation.theXInput = Me.theInputFileReader.ReadUInt16() aBoneFrameDataInfo.theAnimRotation.theYInput = Me.theInputFileReader.ReadUInt16() aBoneFrameDataInfo.theAnimRotation.theZWInput = Me.theInputFileReader.ReadUInt16() End If - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIMPOS) > 0 Then + If (boneFlag And SourceAniFrameAnim52.STUDIO_FRAME_ANIMPOS) > 0 Then aBoneFrameDataInfo.theAnimPosition = New SourceVector48bits() aBoneFrameDataInfo.theAnimPosition.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() aBoneFrameDataInfo.theAnimPosition.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() aBoneFrameDataInfo.theAnimPosition.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() End If - 'If (boneFlag And SourceAniFrameAnim.STUDIO_FRAME_FULLANIMPOS) > 0 Then - If (boneFlag And SourceAniFrameAnim49.STUDIO_FRAME_ANIMROT) > 0 Then - 'aBoneFrameDataInfo.theFullAnimPosition = New SourceVector() - 'aBoneFrameDataInfo.theFullAnimPosition.x = Me.theInputFileReader.ReadSingle() - 'aBoneFrameDataInfo.theFullAnimPosition.y = Me.theInputFileReader.ReadSingle() - 'aBoneFrameDataInfo.theFullAnimPosition.z = Me.theInputFileReader.ReadSingle() - aBoneFrameDataInfo.theAnimPosition = New SourceVector48bits() - aBoneFrameDataInfo.theAnimPosition.theXInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - aBoneFrameDataInfo.theAnimPosition.theYInput.the16BitValue = Me.theInputFileReader.ReadUInt16() - aBoneFrameDataInfo.theAnimPosition.theZInput.the16BitValue = Me.theInputFileReader.ReadUInt16() + ' just read these because we can't really use it + If (boneFlag And SourceAniFrameAnim52.STUDIO_FRAME_ANIMSCALE) > 0 Then + Me.theInputFileReader.ReadUInt16() + Me.theInputFileReader.ReadUInt16() + Me.theInputFileReader.ReadUInt16() End If Next @@ -2295,19 +2287,13 @@ Public Class SourceMdlFile52 aSeqDesc.keyValueSize = Me.theInputFileReader.ReadInt32() aSeqDesc.cyclePoseIndex = Me.theInputFileReader.ReadInt32() - aSeqDesc.activityModifierOffset = 0 - aSeqDesc.activityModifierCount = 0 - If Me.theMdlFileData.version = 49 Then - aSeqDesc.activityModifierOffset = Me.theInputFileReader.ReadInt32() - aSeqDesc.activityModifierCount = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To 4 - aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() - Next - Else - For x As Integer = 0 To 6 - aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() - Next - End If + aSeqDesc.activityModifierOffset = Me.theInputFileReader.ReadInt32() + aSeqDesc.activityModifierCount = Me.theInputFileReader.ReadInt32() + + ' there are two ints here but we cannot use them + For x As Integer = 0 To 4 + aSeqDesc.unused(x) = Me.theInputFileReader.ReadInt32() + Next Me.theMdlFileData.theSequenceDescs.Add(aSeqDesc) @@ -2635,6 +2621,7 @@ Public Class SourceMdlFile52 activityModifierInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anActivityModifier As New SourceMdlActivityModifier() anActivityModifier.nameOffset = Me.theInputFileReader.ReadInt32() + anActivityModifier.unkV53 = Me.theInputFileReader.ReadInt32() aSeqDesc.theActivityModifiers.Add(anActivityModifier) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index a8d47b8..977ed4f 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -1217,9 +1217,9 @@ Public Class SourceMdlFile53 aSectionOfAnimation.constantsOffset = Me.theInputFileReader.ReadInt32() aSectionOfAnimation.frameOffset = Me.theInputFileReader.ReadInt32() aSectionOfAnimation.frameLength = Me.theInputFileReader.ReadInt32() - For x As Integer = 0 To aSectionOfAnimation.unused.Length - 1 - aSectionOfAnimation.unused(x) = Me.theInputFileReader.ReadInt32() - Next + aSectionOfAnimation.oldBoneFlags = Me.theInputFileReader.ReadInt32() + aSectionOfAnimation.unkDataIndex = Me.theInputFileReader.ReadInt32() + aSectionOfAnimation.unused = Me.theInputFileReader.ReadInt32() fileOffsetEnd = Me.theInputFileReader.BaseStream.Position - 1 Me.theMdlFileData.theFileSeekLog.Add(fileOffsetStart, fileOffsetEnd, "anAnimationDesc.aSectionOfAnimation [" + anAnimationDesc.theName + "] (frameCount = " + CStr(anAnimationDesc.frameCount) + "; sectionFrameCount = " + CStr(sectionFrameCount) + ")") From 8138835a134483ff6d2f576f6709fdef65a2c619 Mon Sep 17 00:00:00 2001 From: Rika <34874943+IJARika@users.noreply.github.com> Date: Mon, 14 Nov 2022 13:49:31 -0500 Subject: [PATCH 38/39] some minor cleanups --- .../SourceMdlFileData/SourceMdlActivityModifier.vb | 4 ++-- .../Core/GameModel/SourceModel52/SourceMdlFile52.vb | 10 +++++----- Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb | 2 -- .../Core/GameModel/SourceModel53/SourceMdlFile53.vb | 2 +- Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb | 6 ++---- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb index f5ecb05..a74aa8f 100644 --- a/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb +++ b/Crowbar/Core/GameModel/SourceCommon/SourceMdlFileData/SourceMdlActivityModifier.vb @@ -13,8 +13,8 @@ Public Class SourceMdlActivityModifier Public nameOffset As Integer - ' V53 has an int here that needs to be read for proper output. 0 or 1. - Public unkV53 As Integer + ' V53/V52 has an int here that needs to be read for proper output. 0 or 1. + Public unk As Integer Public theName As String diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb index 8385ea8..daa5b64 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceMdlFile52.vb @@ -1341,10 +1341,10 @@ Public Class SourceMdlFile52 aSectionOfAnimation.theBoneFlags.Add(boneFlag) 'DEBUG: - If (boneFlag And &H20) > 0 Then - 'TODO: Titanfall models get here. - Dim unknownFlagIsUsed As Integer = 4242 - End If + 'If (boneFlag And &H20) > 0 Then + ' 'TODO: Titanfall models get here. + ' Dim unknownFlagIsUsed As Integer = 4242 + 'End If If boneFlag > &HFF Then Dim unknownFlagIsUsed As Integer = 4242 End If @@ -2621,7 +2621,7 @@ Public Class SourceMdlFile52 activityModifierInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anActivityModifier As New SourceMdlActivityModifier() anActivityModifier.nameOffset = Me.theInputFileReader.ReadInt32() - anActivityModifier.unkV53 = Me.theInputFileReader.ReadInt32() + anActivityModifier.unk = Me.theInputFileReader.ReadInt32() aSeqDesc.theActivityModifiers.Add(anActivityModifier) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position diff --git a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb index b9336b9..ee9eaa6 100644 --- a/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb +++ b/Crowbar/Core/GameModel/SourceModel52/SourceQcFile52.vb @@ -2387,9 +2387,7 @@ Public Class SourceQcFile52 For Each activityModifier As SourceMdlActivityModifier In aSequenceDesc.theActivityModifiers line = vbTab line += "activitymodifier " - line += """" line += activityModifier.theName - line += """" Me.theOutputFileStreamWriter.WriteLine(line) Next End If diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb index 977ed4f..5163b81 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceMdlFile53.vb @@ -2415,7 +2415,7 @@ Public Class SourceMdlFile53 activityModifierInputFileStreamPosition = Me.theInputFileReader.BaseStream.Position Dim anActivityModifier As New SourceMdlActivityModifier() anActivityModifier.nameOffset = Me.theInputFileReader.ReadInt32() - anActivityModifier.unkV53 = Me.theInputFileReader.ReadInt32() + anActivityModifier.unk = Me.theInputFileReader.ReadInt32() aSeqDesc.theActivityModifiers.Add(anActivityModifier) inputFileStreamPosition = Me.theInputFileReader.BaseStream.Position diff --git a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb index 6a7665a..a2633ef 100644 --- a/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb +++ b/Crowbar/Core/GameModel/SourceModel53/SourceQcFile53.vb @@ -2325,11 +2325,9 @@ Public Class SourceQcFile53 For Each activityModifier As SourceMdlActivityModifier In aSequenceDesc.theActivityModifiers line = vbTab line += "activitymodifier " - line += """" line += activityModifier.theName - line += """" - line += " // " - line += activityModifier.unkV53.ToString(TheApp.InternalNumberFormat) + 'line += " // " + 'line += activityModifier.unk.ToString(TheApp.InternalNumberFormat) Me.theOutputFileStreamWriter.WriteLine(line) Next End If From 157c204adccd7b8feb4d2f30c1ff126719ee15fc Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Wed, 4 Jan 2023 04:29:00 -0500 Subject: [PATCH 39/39] Revert back to Framework 4.0 to keep XP compatibility. --- Crowbar/Crowbar.vbproj | 2 +- CrowbarLauncher/CrowbarLauncher.vbproj | 2 +- CrowbarSteamPipe/CrowbarSteamPipe.vbproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Crowbar/Crowbar.vbproj b/Crowbar/Crowbar.vbproj index a8209db..bbb2d7c 100644 --- a/Crowbar/Crowbar.vbproj +++ b/Crowbar/Crowbar.vbproj @@ -13,7 +13,7 @@ WindowsFormsWithCustomSubMain On Resources\crowbar_icon.ico - v4.8 + v4.0 diff --git a/CrowbarLauncher/CrowbarLauncher.vbproj b/CrowbarLauncher/CrowbarLauncher.vbproj index 0cd21b7..dcbdbc4 100644 --- a/CrowbarLauncher/CrowbarLauncher.vbproj +++ b/CrowbarLauncher/CrowbarLauncher.vbproj @@ -11,7 +11,7 @@ CrowbarLauncher 512 WindowsFormsWithCustomSubMain - v4.8 + v4.0 true diff --git a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj index c4ef19b..fadfb6b 100644 --- a/CrowbarSteamPipe/CrowbarSteamPipe.vbproj +++ b/CrowbarSteamPipe/CrowbarSteamPipe.vbproj @@ -11,7 +11,7 @@ CrowbarSteamPipe 512 Console - v4.8 + v4.0 true