| 1043 | |
| 1044 | |
| 1045 | void Tr2GStateAnimation::PrePhysicsAnimation( Be::Time time, const Matrix& modelTransform ) |
| 1046 | { |
| 1047 | if( IsInitialized() && m_animationEnabled ) |
| 1048 | { |
| 1049 | // Update gstate with parameters if fully loaded |
| 1050 | if( IsFullyLoaded() ) |
| 1051 | { |
| 1052 | for( auto parameterInstance = m_gStateParameterList.cbegin(); parameterInstance != m_gStateParameterList.cend(); parameterInstance++ ) |
| 1053 | { |
| 1054 | auto parameterNodeName = ( *parameterInstance )->GetNodeName(); |
| 1055 | auto name = ( *parameterInstance )->GetName(); |
| 1056 | auto value = ( *parameterInstance )->GetValue(); |
| 1057 | if( ( parameterNodeName.length() != 0 ) && ( name.length() != 0 ) ) |
| 1058 | { |
| 1059 | auto iterator = m_gStateParameterCachedList.find( { parameterNodeName, name } ); |
| 1060 | if( iterator != m_gStateParameterCachedList.end() ) |
| 1061 | { |
| 1062 | SetParameter( parameterNodeName, iterator->second, value ); |
| 1063 | } |
| 1064 | } |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | float animationTime = GetAnimationTime(); |
| 1069 | |
| 1070 | // TODO: Should this be done here? Seems wasteful to sample animations and build the pose |
| 1071 | // for objects that are off-screen. |
| 1072 | |
| 1073 | granny_real32 timeDelta = animationTime - m_last_gstate_time; |
| 1074 | m_last_gstate_time = animationTime; |
| 1075 | GStateAdvanceTime( m_gStateCharacterInstance, timeDelta ); |
| 1076 | |
| 1077 | auto framenum = static_cast<int>( animationTime ); |
| 1078 | |
| 1079 | granny_local_pose* Pose = GStateSampleAnimation( m_gStateCharacterInstance, m_gstate_pose_cache ); |
| 1080 | if( !Pose ) |
| 1081 | { |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | m_localPose = Pose; |
| 1086 | |
| 1087 | auto id = IdentityMatrix(); |
| 1088 | // build the worldpos out of the localpose using identity matrix as base |
| 1089 | GrannyBuildWorldPose( m_skeleton, 0, m_skeleton->BoneCount, m_localPose, &id.m[0][0], m_worldPose ); |
| 1090 | // construct the 3x4 matrix list, that will be passed to the shader, if we have a meshbinding at all |
| 1091 | if( m_meshBinding ) |
| 1092 | { |
| 1093 | int const* meshToBone = GrannyGetMeshBindingToBoneIndices( m_meshBinding ); |
| 1094 | if( m_meshBoneMatrixList && meshToBone && m_meshBoneCount ) |
| 1095 | { |
| 1096 | GrannyBuildIndexedCompositeBufferTransposed( m_skeleton, m_worldPose, meshToBone, m_meshBoneCount, reinterpret_cast<granny_matrix_3x4*>( m_meshBoneMatrixList ) ); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | |
| 1101 | extern ITr2DebugRendererPtr g_debugRenderer; |
| 1102 | if( g_debugRenderer ) |