void ControlPanel::initBodypartChoices() { CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr(); if (hdr) { int i; mstudiobodyparts_t *pbodyparts = hdr->pBodypart(0); cBodypart->removeAll(); if (hdr->numbodyparts() > 0) { for (i = 0; i < hdr->numbodyparts(); i++) cBodypart->add (pbodyparts[i].pszName()); cBodypart->select (0); cSubmodel->removeAll(); for (i = 0; i < pbodyparts[0].nummodels; i++) { char str[64]; sprintf (str, "Submodel %d", i + 1); cSubmodel->add (str); } cSubmodel->select (0); } } }
// If the local player is visible (thirdperson mode, tf2 taunts, etc., then make sure that we are using the // w_ (world) model not the v_ (view) model or else the model can flicker, etc. // Otherwise, if we're not the local player, always use the world model void C_BaseCombatWeapon::EnsureCorrectRenderingModel() { C_BasePlayer *localplayer = C_BasePlayer::GetLocalPlayer(); if ( localplayer && localplayer == GetOwner() && !localplayer->ShouldDrawLocalPlayer() ) { return; } MDLCACHE_CRITICAL_SECTION(); // BRJ 10/14/02 // FIXME: Remove when Yahn's client-side prediction is done // It's a hacky workaround for the model indices fighting // (GetRenderBounds uses the model index, which is for the view model) SetModelIndex( GetWorldModelIndex() ); // Validate our current sequence just in case ( in theory the view and weapon models should have the same sequences for sequences that overlap at least ) CStudioHdr *pStudioHdr = GetModelPtr(); if ( pStudioHdr && GetSequence() >= pStudioHdr->GetNumSeq() ) { SetSequence( 0 ); } }
void IFaceposerModels::CheckResetFlexes( void ) { int current_render_frame = g_MDLViewer->GetCurrentFrame(); if ( current_render_frame == m_nLastRenderFrame ) return; m_nLastRenderFrame = current_render_frame; // the phoneme editor just adds to the face, so reset the controllers int c = Count(); for ( int i = 0; i < c; i++ ) { CFacePoserModel *m = GetEntry( i ); if ( !m ) continue; StudioModel *model = m->GetModel(); if ( !model ) continue; CStudioHdr *hdr = model->GetStudioHdr(); if ( !hdr ) continue; for ( LocalFlexController_t i = LocalFlexController_t(0); i < hdr->numflexcontrollers(); i++ ) { model->SetFlexController( i, 0.0f ); } } }
void CAnimating::GetBoneTransform( int iBone, matrix3x4_t &pBoneToWorld ) { CStudioHdr *pStudioHdr = GetModelPtr( ); if (!pStudioHdr) { Assert(!"CBaseAnimating::GetBoneTransform: model missing"); return; } if (iBone < 0 || iBone >= pStudioHdr->numbones()) { Assert(!"CBaseAnimating::GetBoneTransform: invalid bone index"); return; } CBoneCache *pcache = GetBoneCache( ); matrix3x4_t *pmatrix = pcache->GetCachedBone( iBone ); if ( !pmatrix ) { MatrixCopy( EntityToWorldTransform(), pBoneToWorld ); return; } Assert( pmatrix ); // FIXME MatrixCopy( *pmatrix, pBoneToWorld ); }
void CAnimating::ResetSequenceInfo() { if (GetSequence() == -1) { // This shouldn't happen. Setting m_nSequence blindly is a horrible coding practice. SetSequence( 0 ); } CStudioHdr *pStudioHdr = GetModelPtr(); m_flGroundSpeed = GetSequenceGroundSpeed( pStudioHdr, GetSequence() ); m_bSequenceLoops = ((GetSequenceFlags( pStudioHdr, GetSequence() ) & STUDIO_LOOPING) != 0); // m_flAnimTime = gpGlobals->time; m_flPlaybackRate = 1.0; m_bSequenceFinished = false; m_flLastEventCheck = 0; m_nNewSequenceParity = ( *(m_nNewSequenceParity)+1 ) & EF_PARITY_MASK; m_nResetEventsParity = ( *(m_nResetEventsParity)+1 ) & EF_PARITY_MASK; // FIXME: why is this called here? Nothing should have changed to make this nessesary if ( pStudioHdr ) { SetEventIndexForSequence( pStudioHdr->pSeqdesc( GetSequence() ) ); } }
//----------------------------------------------------------------------------- // Purpose: clear out any face/eye values stored in the material system //----------------------------------------------------------------------------- void C_HL2MPRagdoll::SetupWeights( const matrix3x4_t *pBoneToWorld, int nFlexWeightCount, float *pFlexWeights, float *pFlexDelayedWeights ) { BaseClass::SetupWeights( pBoneToWorld, nFlexWeightCount, pFlexWeights, pFlexDelayedWeights ); static float destweight[128]; static bool bIsInited = false; CStudioHdr *hdr = GetModelPtr(); if ( !hdr ) return; int nFlexDescCount = hdr->numflexdesc(); if ( nFlexDescCount ) { Assert( !pFlexDelayedWeights ); memset( pFlexWeights, 0, nFlexWeightCount * sizeof(float) ); } if ( m_iEyeAttachment > 0 ) { matrix3x4_t attToWorld; if (GetAttachment( m_iEyeAttachment, attToWorld )) { Vector local, tmp; local.Init( 1000.0f, 0.0f, 0.0f ); VectorTransform( local, attToWorld, tmp ); modelrender->SetViewTarget( GetModelPtr(), GetBody(), tmp ); } } }
bool HasContentsGrate( CBaseEntity *pEntity ) { // FIXME: Move this into the GetModelContents() function in base entity // Find the contents based on the model type int nModelType = modelinfo->GetModelType( pEntity->GetModel() ); if ( nModelType == mod_studio ) { CBaseAnimating *pAnim = dynamic_cast<CBaseAnimating *>(pEntity); if ( pAnim != NULL ) { CStudioHdr *pStudioHdr = pAnim->GetModelPtr(); if ( pStudioHdr != NULL && (pStudioHdr->contents() & CONTENTS_GRATE) ) return true; } } else if ( nModelType == mod_brush ) { // Brushes poll their contents differently int contents = modelinfo->GetModelContents( pEntity->GetModelIndex() ); if ( contents & CONTENTS_GRATE ) return true; } return false; }
void C_BaseAnimatingOverlay::GetRenderBounds( Vector& theMins, Vector& theMaxs ) { BaseClass::GetRenderBounds( theMins, theMaxs ); if ( !IsRagdoll() ) { CStudioHdr *pStudioHdr = GetModelPtr(); if ( !pStudioHdr || !pStudioHdr->SequencesAvailable() ) return; int nSequences = pStudioHdr->GetNumSeq(); int i; for (i = 0; i < m_AnimOverlay.Count(); i++) { if (m_AnimOverlay[i].m_flWeight > 0.0) { if ( m_AnimOverlay[i].m_nSequence >= nSequences ) { continue; } mstudioseqdesc_t &seqdesc = pStudioHdr->pSeqdesc( m_AnimOverlay[i].m_nSequence ); VectorMin( seqdesc.bbmin, theMins, theMins ); VectorMax( seqdesc.bbmax, theMaxs, theMaxs ); } } } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void C_SceneEntity::ResetActorFlexesForScene() { int nActorCount = m_pScene->GetNumActors(); for( int iActor = 0; iActor < nActorCount; ++iActor ) { CChoreoActor *pChoreoActor = m_pScene->GetActor( iActor ); if ( !pChoreoActor ) continue; C_BaseFlex *pFlexActor = FindNamedActor( pChoreoActor ); if ( !pFlexActor ) continue; CStudioHdr *pStudioHdr = pFlexActor->GetModelPtr(); if ( !pStudioHdr ) continue; if ( pStudioHdr->numflexdesc() == 0 ) continue; // Reset the flex weights to their starting position. LocalFlexController_t iController; for ( iController = LocalFlexController_t(0); iController < pStudioHdr->numflexcontrollers(); ++iController ) { pFlexActor->SetFlexWeight( iController, 0.0f ); } // Reset the prediction interpolation values. pFlexActor->m_iv_flexWeight.Reset(); } }
bool StudioModel::PostLoadModel( const char *modelname ) { MDLCACHE_CRITICAL_SECTION_( g_pMDLCache ); CStudioHdr *pStudioHdr = GetStudioHdr(); if (pStudioHdr == NULL) return false; SetSequence (0); SetController (0, 0.0f); SetController (1, 0.0f); SetController (2, 0.0f); SetController (3, 0.0f); SetBlendTime( DEFAULT_BLEND_TIME ); // SetHeadTurn( 1.0f ); // FIXME:!!! int n; for (n = 0; n < pStudioHdr->numbodyparts(); n++) { SetBodygroup (n, 0); } SetSkin (0); /* Vector mins, maxs; ExtractBbox (mins, maxs); if (mins[2] < 5.0f) m_origin[2] = -mins[2]; */ return true; }
void IFaceposerModels::CFacePoserModel::RecreateAllAnimationBitmaps() { StudioModel *model = m_pModel; if ( !model ) return; CStudioHdr *hdr = model->GetStudioHdr(); if ( !hdr ) return; g_pProgressDialog->Start( CFmtStr( "%s - Animation Thumbnails", GetShortModelName() ), "", true ); for ( int i = 0; i < hdr->GetNumSeq(); ++i ) { const mstudioseqdesc_t &seq = hdr->pSeqdesc( i ); g_pProgressDialog->UpdateText( "%s", seq.pszLabel() ); g_pProgressDialog->Update( (float)i / (float)hdr->GetNumSeq() ); RecreateAnimationBitmap( i, false ); if ( g_pProgressDialog->IsCancelled() ) { Msg( "Cancelling\n" ); break; } } g_pProgressDialog->Finish(); ReconcileAnimationBitmaps(); }
void CEnvParticleScript::PrecacheAnimationEventMaterials() { CStudioHdr *hdr = GetModelPtr(); if ( hdr ) { int numseq = hdr->GetNumSeq(); for ( int i = 0; i < numseq; ++i ) { mstudioseqdesc_t& seqdesc = hdr->pSeqdesc( i ); int ecount = seqdesc.numevents; for ( int j = 0 ; j < ecount; ++j ) { const mstudioevent_t* event = (const mstudioevent_for_client_server_t*)seqdesc.pEvent( j ); if ( event->Event() == CL_EVENT_SPRITEGROUP_CREATE ) { char pAttachmentName[256]; char pSpriteName[256]; int nArgs = sscanf( event->pszOptions(), "%255s %255s", pAttachmentName, pSpriteName ); if ( nArgs == 2 ) { PrecacheMaterial( pSpriteName ); } } } } } }
//----------------------------------------------------------------------------- // Zap! //----------------------------------------------------------------------------- void CRagdollBoogie::ZapThink() { if (!GetMoveParent()) return; CBaseAnimating *pRagdoll = GetMoveParent()->GetBaseAnimating(); if (!pRagdoll) return; // Make electricity on the client CStudioHdr *pStudioHdr = pRagdoll->GetModelPtr(); if (!pStudioHdr) return; mstudiohitboxset_t *set = pStudioHdr->pHitboxSet(pRagdoll->GetHitboxSet()); if (set->numhitboxes == 0) return; if (m_nSuppressionCount == 0) { CEffectData data; data.m_nEntIndex = GetMoveParent()->entindex(); data.m_flMagnitude = 4; data.m_flScale = HasSpawnFlags(SF_RAGDOLL_BOOGIE_ELECTRICAL_NARROW_BEAM) ? 1.0f : 2.0f; DispatchEffect("TeslaHitboxes", data); } SetContextThink(&CRagdollBoogie::ZapThink, gpGlobals->curtime + random->RandomFloat(0.1f, 0.3f), s_pZapContext); }
//----------------------------------------------------------------------------- // Purpose: find the anim events that may have started sounds, and stop them. //----------------------------------------------------------------------------- void C_BaseObject::StopAnimGeneratedSounds( void ) { MDLCACHE_CRITICAL_SECTION(); CStudioHdr *pStudioHdr = GetModelPtr(); if ( !pStudioHdr ) return; mstudioseqdesc_t &seqdesc = pStudioHdr->pSeqdesc( GetSequence() ); float flCurrentCycle = GetCycle(); mstudioevent_t *pevent = GetEventIndexForSequence( seqdesc ); for (int i = 0; i < (int)seqdesc.numevents; i++) { if ( pevent[i].cycle < flCurrentCycle ) { if ( pevent[i].event == CL_EVENT_SOUND || pevent[i].event == AE_CL_PLAYSOUND ) { StopSound( entindex(), pevent[i].options ); } } } }
//----------------------------------------------------------------------------- // Purpose: Returns the the sequence should be hidden or not //----------------------------------------------------------------------------- bool StudioModel::IsHidden( int iSequence ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if (pStudioHdr->pSeqdesc( iSequence ).flags & STUDIO_HIDDEN) return true; return false; }
LocalFlexController_t CAnimating::GetNumFlexControllers( void ) { CStudioHdr *pstudiohdr = GetModelPtr( ); if (! pstudiohdr) return LocalFlexController_t(0); return pstudiohdr->numflexcontrollers(); }
void StudioModel::GetSeqAnims( int iSequence, mstudioanimdesc_t *panim[4], float *weight ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if (!pStudioHdr) return; mstudioseqdesc_t &seqdesc = pStudioHdr->pSeqdesc( iSequence ); Studio_SeqAnims( pStudioHdr, seqdesc, iSequence, m_poseparameter, panim, weight ); }
int SEditModelRender::QuerySequences( char ***list ) { if ( !IsModelReady() ) return 0; MDLCACHE_CRITICAL_SECTION(); CStudioHdr *pHdr = pModelInstance->GetModelPtr(); if ( !pHdr ) return 0; CUtlVector< mstudioseqdesc_t* >hSeqs; for ( int i = 0; i < pHdr->GetNumSeq(); i++ ) if ( !( pHdr->pSeqdesc( i ).flags & STUDIO_HIDDEN ) ) hSeqs.AddToTail( &pHdr->pSeqdesc( i ) ); int numSequences = hSeqs.Count(); if ( !numSequences ) return 0; hSeqs.Sort( SequenceSort ); CUtlVector< const char* >hNameList; for ( int i = 0; i < numSequences; i++ ) { const char *seqName = NULL; const mstudioseqdesc_t &seqPtr = *hSeqs[ i ]; if ( seqPtr.pszLabel() ) seqName = seqPtr.pszLabel(); else seqName = "Unknown Sequence"; hNameList.AddToTail( seqName ); } *list = new char*[numSequences]; int iTotalLength = 0; for ( int i = 0; i < numSequences; i++ ) iTotalLength += Q_strlen( hNameList[i] ) + 1; **list = new char[ iTotalLength ]; int curpos = 0; for ( int i = 0; i < numSequences; i++ ) { int curLength = Q_strlen( hNameList[i] ) + 1; (*list)[ i ] = **list + curpos; Q_strcpy( (*list)[ i ], hNameList[i] ); curpos += curLength; } hNameList.Purge(); hSeqs.Purge(); return numSequences; }
void ControlPanel::setBoneControllerValue (int index, float value) { CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr(); if (hdr) { mstudiobonecontroller_t *pbonecontrollers = hdr->pBonecontroller(index); models->GetActiveStudioModel()->SetController (pbonecontrollers->inputfield, value); } }
int StudioModel::GetNumFrames( int iSequence ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if ( !pStudioHdr || iSequence < 0 || iSequence >= pStudioHdr->GetNumSeq() ) { return 1; } return Studio_MaxFrame( pStudioHdr, iSequence, m_poseparameter ); }
const char *CAnimating::GetFlexControllerName( LocalFlexController_t iFlexController ) { CStudioHdr *pstudiohdr = GetModelPtr( ); if (! pstudiohdr) return 0; mstudioflexcontroller_t *pflexcontroller = pstudiohdr->pFlexcontroller( iFlexController ); return pflexcontroller->pszName( ); }
void CEventPropertiesSequenceDialog::PopulateSequenceList( HWND wnd ) { CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr(); if (hdr) { for (int i = 0; i < hdr->GetNumSeq(); i++) { SendMessage( wnd, CB_ADDSTRING, 0, (LPARAM)hdr->pSeqdesc(i).pszLabel() ); } } }
void ControlPanel::setBoneController (int index) { CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr(); if (hdr) { mstudiobonecontroller_t *pbonecontroller = hdr->pBonecontroller(index); slController->setRange ( pbonecontroller->start, pbonecontroller->end); slController->setValue (0); } }
void ControlPanel::initPoseParameters() { CStudioHdr *hdr = models->GetActiveStudioModel()->GetStudioHdr(); if (hdr) { for (int i = 0; i < hdr->GetNumPoseParameters(); i++) { setBlend( i, 0.0 ); } } }
void StudioModel::SetFlexControllerRaw( LocalFlexController_t iFlex, float flValue ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if ( !pStudioHdr ) return; if (iFlex >= 0 && iFlex < pStudioHdr->numflexcontrollers()) { // mstudioflexcontroller_t *pflex = pStudioHdr->pFlexcontroller(iFlex); m_flexweight[iFlex] = clamp( flValue, 0.0f, 1.0f ); } }
void StudioModel::scaleBones (float scale) { CStudioHdr *pStudioHdr = GetStudioHdr(); if (!pStudioHdr) return; mstudiobone_t *pbones = pStudioHdr->pBone( 0 ); for (int i = 0; i < pStudioHdr->numbones(); i++) { pbones[i].pos *= scale; pbones[i].posscale *= scale; } }
float StudioModel::GetFlexControllerRaw( LocalFlexController_t iFlex ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if ( !pStudioHdr ) return 0.0f; if (iFlex >= 0 && iFlex < pStudioHdr->numflexcontrollers()) { // mstudioflexcontroller_t *pflex = pStudioHdr->pFlexcontroller(iFlex); return m_flexweight[iFlex]; } return 0.0; }
//----------------------------------------------------------------------------- // Purpose: Clear all pose parameters //----------------------------------------------------------------------------- void C_HL2MP_Player::InitializePoseParams( void ) { m_headYawPoseParam = LookupPoseParameter( "head_yaw" ); GetPoseParameterRange( m_headYawPoseParam, m_headYawMin, m_headYawMax ); m_headPitchPoseParam = LookupPoseParameter( "head_pitch" ); GetPoseParameterRange( m_headPitchPoseParam, m_headPitchMin, m_headPitchMax ); CStudioHdr *hdr = GetModelPtr(); for ( int i = 0; i < hdr->GetNumPoseParameters() ; i++ ) { SetPoseParameter( hdr, i, 0.0 ); } }
// walk the hitboxes and find the first one that is attached to the physics bone in question // return the hitgroup of that box static int HitGroupFromPhysicsBone( CBaseAnimating *pAnim, int physicsBone ) { CStudioHdr *pStudioHdr = pAnim->GetModelPtr( ); mstudiohitboxset_t *set = pStudioHdr->pHitboxSet( pAnim->m_nHitboxSet ); for ( int i = 0; i < set->numhitboxes; i++ ) { if ( pStudioHdr->pBone( set->pHitbox(i)->bone )->physicsbone == physicsBone ) { return set->pHitbox(i)->group; } } return 0; }
int StudioModel::SetSkin( int iValue ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if (!pStudioHdr) return 0; if (iValue >= pStudioHdr->numskinfamilies()) { return m_skinnum; } m_skinnum = iValue; return iValue; }