From 85ffde8608d380569475f6939b6cf7cf1c0db46f Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Fri, 26 Aug 2022 19:52:06 -0400 Subject: [PATCH 01/15] 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 ef0745272d56e2af9efe7706f6f086ca83a6a0f5 Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Wed, 31 Aug 2022 17:43:42 -0400 Subject: [PATCH 02/15] 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 03/15] 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 04/15] 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 809cf3bec0fc561215c74e1c649d17a071837e77 Mon Sep 17 00:00:00 2001 From: ZeqMacaw Date: Thu, 1 Sep 2022 05:52:49 -0400 Subject: [PATCH 05/15] 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 06/15] 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 07/15] 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 08/15] 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 09/15] 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 10/15] 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 11/15] 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 12/15] 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 13/15] 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 14/15] 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 15/15] 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