int StudioModel::GetNumFrames( int iSequence ) { CStudioHdr *pStudioHdr = GetStudioHdr(); if ( !pStudioHdr || iSequence < 0 || iSequence >= pStudioHdr->GetNumSeq() ) { return 1; } return Studio_MaxFrame( pStudioHdr, iSequence, m_poseparameter ); }
void CDmeMDL::SetUpBones( CStudioHdr &studioHdr, const matrix3x4_t& shapeToWorld, int nMaxBoneCount, matrix3x4_t *pBoneToWorld ) { // Default to middle of the pose parameter range float pPoseParameter[MAXSTUDIOPOSEPARAM]; for ( int i = 0; i < MAXSTUDIOPOSEPARAM; ++i ) { pPoseParameter[i] = 0.5f; } int nFrameCount = Studio_MaxFrame( &studioHdr, m_nSequence, pPoseParameter ); if ( nFrameCount == 0 ) { nFrameCount = 1; } float flCycle = ( m_flTime * m_flPlaybackRate ) / nFrameCount; // FIXME: We're always wrapping; may want to determing if we should clamp flCycle -= (int)(flCycle); Vector pos[MAXSTUDIOBONES]; Quaternion q[MAXSTUDIOBONES]; InitPose( &studioHdr, pos, q, BoneMask( ) ); AccumulatePose( &studioHdr, NULL, pos, q, m_nSequence, flCycle, pPoseParameter, BoneMask( ), 1.0f, m_flTime ); // FIXME: Try enabling this? // CalcAutoplaySequences( pStudioHdr, NULL, pos, q, pPoseParameter, BoneMask( ), flTime ); // Root transform matrix3x4_t rootToWorld, temp; // Rotate the root transform to make it align with DMEs // DMEs up vector is the y axis if ( !m_bDrawInEngine ) { matrix3x4_t engineToDme; EngineToDmeMatrix( engineToDme ); ConcatTransforms( engineToDme, shapeToWorld, rootToWorld ); } else { MatrixCopy( shapeToWorld, rootToWorld ); } if ( nMaxBoneCount > studioHdr.numbones() ) { nMaxBoneCount = studioHdr.numbones(); } for ( int i = 0; i < nMaxBoneCount; i++ ) { // If it's not being used, fill with NAN for errors #ifdef _DEBUG if ( !(studioHdr.pBone( i )->flags & BoneMask())) { int j, k; for (j = 0; j < 3; j++) { for (k = 0; k < 4; k++) { pBoneToWorld[i][j][k] = VEC_T_NAN; } } continue; } #endif matrix3x4_t boneMatrix; QuaternionMatrix( q[i], boneMatrix ); MatrixSetColumn( pos[i], 3, boneMatrix ); if (studioHdr.pBone(i)->parent == -1) { ConcatTransforms( rootToWorld, boneMatrix, pBoneToWorld[i] ); } else { ConcatTransforms( pBoneToWorld[ studioHdr.pBone(i)->parent ], boneMatrix, pBoneToWorld[i] ); } } }
//----------------------------------------------------------------------------- // Set up the bones for a frame //----------------------------------------------------------------------------- matrix3x4_t* CIHVTestApp::SetUpBones( studiohdr_t *pStudioHdr, const matrix3x4_t &shapeToWorld, int iRun, int model, int boneMask ) { // Default to middle of the pose parameter range float pPoseParameter[MAXSTUDIOPOSEPARAM]; for ( int i = 0; i < MAXSTUDIOPOSEPARAM; ++i ) { pPoseParameter[i] = 0.5f; } CStudioHdr studioHdr( pStudioHdr, g_pMDLCache ); int nFrameCount = Studio_MaxFrame( &studioHdr, g_BenchRuns[iRun].sequence1[model], pPoseParameter ); if ( nFrameCount == 0 ) { nFrameCount = 1; } Vector pos[MAXSTUDIOBONES]; Quaternion q[MAXSTUDIOBONES]; InitPose( &studioHdr, pos, q, boneMask ); AccumulatePose( &studioHdr, NULL, pos, q, g_BenchRuns[iRun].sequence1[model], s_Cycle[model], pPoseParameter, boneMask, 1.0f, 0.0 ); // FIXME: Try enabling this? // CalcAutoplaySequences( pStudioHdr, NULL, pos, q, pPoseParameter, BoneMask( ), flTime ); // Root transform matrix3x4_t rootToWorld, temp; MatrixCopy( shapeToWorld, rootToWorld ); matrix3x4_t *pBoneToWorld = g_pStudioRender->LockBoneMatrices( studioHdr.numbones() ); for ( int i = 0; i < studioHdr.numbones(); i++ ) { // If it's not being used, fill with NAN for errors if ( !(studioHdr.pBone( i )->flags & boneMask) ) { int j, k; for (j = 0; j < 3; j++) { for (k = 0; k < 4; k++) { pBoneToWorld[i][j][k] = VEC_T_NAN; } } continue; } matrix3x4_t boneMatrix; QuaternionMatrix( q[i], boneMatrix ); MatrixSetColumn( pos[i], 3, boneMatrix ); if (studioHdr.pBone(i)->parent == -1) { ConcatTransforms (rootToWorld, boneMatrix, pBoneToWorld[i]); } else { ConcatTransforms (pBoneToWorld[ studioHdr.pBone(i)->parent ], boneMatrix, pBoneToWorld[i] ); } } g_pStudioRender->UnlockBoneMatrices(); return pBoneToWorld; }