diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp index 5c78e58a90a..49a87960dc6 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp @@ -2396,47 +2396,47 @@ void W3DModelDraw::adjustAnimation(const ModelConditionInfo* prevState, Real pre // ANIMATION BLENDING if (prevState && - m_curState->m_animBlendTime > 0 && - prevState->m_animations[0].getAnimHandle() && - m_renderObject->Class_ID() == RenderObjClass::CLASSID_HLOD) { + m_curState->m_animBlendTime > 0) { - //DEBUG_LOG((">>>>BLEND ANIMS!!")); + const W3DAnimationInfo& animInfoPrev = prevState->m_animations[m_whichAnimInPrevState]; + HAnimClass* animHandlePrev = animInfoPrev.getAnimHandle(); - HLodClass* hlod = (HLodClass*)m_renderObject; + if (animHandlePrev != nullptr && m_renderObject->Class_ID() == RenderObjClass::CLASSID_HLOD) { - const W3DAnimationInfo& animInfoPrev = prevState->m_animations[m_whichAnimInPrevState]; + //DEBUG_LOG((">>>>BLEND ANIMS!!")); - HAnimClass* animHandlePrev = animInfoPrev.getAnimHandle(); + HLodClass* hlod = (HLodClass*)m_renderObject; - Real factor = GameClientRandomValueReal(m_curState->m_animMinSpeedFactor, m_curState->m_animMaxSpeedFactor); + Real factor = GameClientRandomValueReal(m_curState->m_animMinSpeedFactor, m_curState->m_animMaxSpeedFactor); - Int startFramePrev = REAL_TO_INT(prevAnimFraction * m_prevAnimHelper.numFrames - 1); + Int startFramePrev = REAL_TO_INT(prevAnimFraction * m_prevAnimHelper.numFrames - 1); - // maxBlendTime = currentAnim duration in milliseconds - Int animBlendTime = m_curState->m_animBlendTime; - Int curAnimDurMS = REAL_TO_INT((animHandle->Get_Num_Frames() * 1000.0f / animHandle->Get_Frame_Rate()) * factor); - if (animBlendTime > curAnimDurMS) { - animBlendTime = curAnimDurMS; + // maxBlendTime = currentAnim duration in milliseconds + Int animBlendTime = m_curState->m_animBlendTime; + Int curAnimDurMS = REAL_TO_INT((animHandle->Get_Num_Frames() * 1000.0f / animHandle->Get_Frame_Rate()) * factor); + if (animBlendTime > curAnimDurMS) { + animBlendTime = curAnimDurMS; + } + hlod->Set_Animation( + animHandle, + startFrame, + animHandlePrev, + startFramePrev, + 1.0f, //We start with prev anim and fade into the new anim + m_curState->m_mode, + m_prevAnimHelper.mode, + animBlendTime + ); + // Let's ignore speed factor for prev anim for now + // We need to find out when the prev anim is supposed to fade out: + + hlod->Set_Animation_Frame_Rate_Multiplier(factor); //This might need to be different } - hlod->Set_Animation( - animHandle, - startFrame, - animHandlePrev, - startFramePrev, - 1.0f, //We start with prev anim and fade into the new anim - m_curState->m_mode, - m_prevAnimHelper.mode, - animBlendTime - ); + REF_PTR_RELEASE(animHandle); REF_PTR_RELEASE(animHandlePrev); animHandle = NULL; animHandlePrev = NULL; - - // Let's ignore speed factor for prev anim for now - // We need to find out when the prev anim is supposed to fade out: - - hlod->Set_Animation_Frame_Rate_Multiplier(factor); //This might need to be different } else { m_renderObject->Set_Animation(animHandle, startFrame, m_curState->m_mode); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animobj.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animobj.cpp index f94167dfa71..41d944d36e3 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animobj.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/animobj.cpp @@ -559,35 +559,47 @@ void Animatable3DObjClass::Set_Animation float percentage ) { - Release(); - - CurMotionMode = DOUBLE_ANIM; - ModeInterp.Motion0 = motion0; - ModeInterp.Motion1 = motion1; - ModeInterp.PrevFrame0 = ModeInterp.Frame0; - ModeInterp.PrevFrame1 = ModeInterp.Frame1; - ModeInterp.Frame0 = frame0; - ModeInterp.Frame1 = frame1; - ModeInterp.Percentage = percentage; - Set_Hierarchy_Valid(false); + if ((motion0) && (motion1)) { + motion0->Add_Ref(); + motion1->Add_Ref(); + Release(); + CurMotionMode = DOUBLE_ANIM; + ModeInterp.Motion0 = motion0; + ModeInterp.Motion1 = motion1; + ModeInterp.PrevFrame0 = ModeInterp.Frame0; + ModeInterp.PrevFrame1 = ModeInterp.Frame1; + ModeInterp.Frame0 = frame0; + ModeInterp.Frame1 = frame1; + ModeInterp.Percentage = percentage; + ModeInterp.LastSyncTime = WW3D::Get_Logic_Time_Milliseconds(); + //Set_Hierarchy_Valid(false); - if ( ModeInterp.Motion0 != nullptr ) { - ModeInterp.Motion0->Add_Ref(); - const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion0); - if (sound_name) { - int bone_index = Get_Bone_Index(sound_name); - motion0->Set_Embedded_Sound_Bone_Index(bone_index); + //if ( ModeInterp.Motion0 != nullptr ) + { + //ModeInterp.Motion0->Add_Ref(); + const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion0); + if (sound_name) { + int bone_index = Get_Bone_Index(sound_name); + motion0->Set_Embedded_Sound_Bone_Index(bone_index); + } } - } - if ( ModeInterp.Motion1 != nullptr ) { - ModeInterp.Motion1->Add_Ref(); - const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion1); - if (sound_name) { - int bone_index = Get_Bone_Index(sound_name); - motion1->Set_Embedded_Sound_Bone_Index(bone_index); + //if ( ModeInterp.Motion1 != nullptr ) + { + //ModeInterp.Motion1->Add_Ref(); + const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion1); + if (sound_name) { + int bone_index = Get_Bone_Index(sound_name); + motion1->Set_Embedded_Sound_Bone_Index(bone_index); + } } } + else { + CurMotionMode = BASE_POSE; + Release(); + } + + Set_Hierarchy_Valid(false); } @@ -608,60 +620,72 @@ void Animatable3DObjClass::Set_Animation //DEBUG_LOG2((">>> animobj.cpp - Set_Animation DOUBLE_ANIM - with mode0 '%d' and mode1 '%d'\n", mode0, mode1)); Release(); - CurMotionMode = DOUBLE_ANIM; - ModeInterp.Motion0 = motion0; - ModeInterp.Motion1 = motion1; - ModeInterp.PrevFrame0 = ModeInterp.Frame0; - ModeInterp.PrevFrame1 = ModeInterp.Frame1; - ModeInterp.Frame0 = frame0; - ModeInterp.Frame1 = frame1; - ModeInterp.Percentage = percentage; - ModeInterp.LastSyncTime = WW3D::Get_Sync_Time(); - ModeInterp.frameRateMultiplier0 = 1.0; - ModeInterp.animDirection0 = 1.0; - ModeInterp.frameRateMultiplier1 = 1.0; - ModeInterp.animDirection1 = 1.0; - ModeInterp.FadeOutTime = fadeOutTime; // This should be in milliseconds - if (startFadeTime == 0) { - ModeInterp.StartFadeTime = ModeInterp.LastSyncTime; - } - else { - ModeInterp.StartFadeTime = startFadeTime; - } - - ModeInterp.AnimMode0 = mode0; - ModeInterp.AnimMode1 = mode1; - - if (mode0 < ANIM_MODE_LOOP_BACKWARDS) - ModeInterp.animDirection0 = 1.0f; //assume playing forwards - else - ModeInterp.animDirection0 = -1.0f; //reverse animation playback + if ((motion0) && (motion1)) { + motion0->Add_Ref(); + motion1->Add_Ref(); + Release(); + CurMotionMode = DOUBLE_ANIM; + ModeInterp.Motion0 = motion0; + ModeInterp.Motion1 = motion1; + ModeInterp.PrevFrame0 = ModeInterp.Frame0; + ModeInterp.PrevFrame1 = ModeInterp.Frame1; + ModeInterp.Frame0 = frame0; + ModeInterp.Frame1 = frame1; + ModeInterp.Percentage = percentage; + ModeInterp.LastSyncTime = WW3D::Get_Sync_Time(); + ModeInterp.frameRateMultiplier0 = 1.0; + ModeInterp.animDirection0 = 1.0; + ModeInterp.frameRateMultiplier1 = 1.0; + ModeInterp.animDirection1 = 1.0; + ModeInterp.FadeOutTime = fadeOutTime; // This should be in milliseconds + if (startFadeTime == 0) { + ModeInterp.StartFadeTime = ModeInterp.LastSyncTime; + } + else { + ModeInterp.StartFadeTime = startFadeTime; + } - if (mode1 < ANIM_MODE_LOOP_BACKWARDS) - ModeInterp.animDirection1 = 1.0f; //assume playing forwards - else - ModeInterp.animDirection1 = -1.0f; //reverse animation playback + ModeInterp.AnimMode0 = mode0; + ModeInterp.AnimMode1 = mode1; + if (mode0 < ANIM_MODE_LOOP_BACKWARDS) + ModeInterp.animDirection0 = 1.0f; //assume playing forwards + else + ModeInterp.animDirection0 = -1.0f; //reverse animation playback - Set_Hierarchy_Valid(false); + if (mode1 < ANIM_MODE_LOOP_BACKWARDS) + ModeInterp.animDirection1 = 1.0f; //assume playing forwards + else + ModeInterp.animDirection1 = -1.0f; //reverse animation playback - if (ModeInterp.Motion0 != NULL) { - ModeInterp.Motion0->Add_Ref(); - const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion0); - if (sound_name) { - int bone_index = Get_Bone_Index(sound_name); - motion0->Set_Embedded_Sound_Bone_Index(bone_index); + //if (ModeInterp.Motion0 != NULL) + { + //ModeInterp.Motion0->Add_Ref(); + const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion0); + if (sound_name) { + int bone_index = Get_Bone_Index(sound_name); + motion0->Set_Embedded_Sound_Bone_Index(bone_index); + } } - } - if (ModeInterp.Motion1 != NULL) { - ModeInterp.Motion1->Add_Ref(); - const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion1); - if (sound_name) { - int bone_index = Get_Bone_Index(sound_name); - motion1->Set_Embedded_Sound_Bone_Index(bone_index); + //if (ModeInterp.Motion1 != NULL) + { + //ModeInterp.Motion1->Add_Ref(); + const char* sound_name = AnimatedSoundMgrClass::Get_Embedded_Sound_Name(motion1); + if (sound_name) { + int bone_index = Get_Bone_Index(sound_name); + motion1->Set_Embedded_Sound_Bone_Index(bone_index); + } } } + else { + CurMotionMode = BASE_POSE; + Release(); + } + + + Set_Hierarchy_Valid(false); + } @@ -897,8 +921,8 @@ void Animatable3DObjClass::Update_Sub_Object_Transforms(void) */ CompositeRenderObjClass::Update_Sub_Object_Transforms(); - HRawAnimClass* motion0 = nullptr; - HRawAnimClass* motion1 = nullptr; + //HRawAnimClass* motion0 = nullptr; + //HRawAnimClass* motion1 = nullptr; /* ** Update the transforms @@ -1221,7 +1245,7 @@ float Animatable3DObjClass::Compute_Current_Frame(float* newFrame0, float* newFr } break; } - + return 0; } float Animatable3DObjClass::Compute_Current_Frame_For_Anim(HAnimClass* anim, int animMode, float frame, float& direction) const { @@ -1284,7 +1308,7 @@ float Animatable3DObjClass::Compute_Current_Frame_For_Anim(HAnimClass* anim, int return frame; } - +// ------------------------- float Animatable3DObjClass::Compute_Current_Percentage() const { if (CurMotionMode == SINGLE_ANIM) { @@ -1305,6 +1329,7 @@ float Animatable3DObjClass::Compute_Current_Percentage() const } return 0.0f; } + return 0.0f; } /*********************************************************************************************** @@ -1459,6 +1484,7 @@ HAnimClass* Animatable3DObjClass::Peek_Animation_And_Info(float& frame0, int& nu return ModeInterp.Motion0; } + return nullptr; //DEBUG_LOG2((">>> animobj.cpp - Peek_Animation_And_Info - Done'\n")); }