void AnimationSystem::MatrixPaletteGeneration() { // todo: can be easly run in parallel. for( u32 i = 0; i < m_controllers.Count(); ++i ) { AnimController& controller = m_controllers[i]; AnimHierarchy* hierarchy = controller.GetHierarchy(); Skeleton* skeleton = controller.GetSkeleton(); Matrix4x4* palette = controller.GetSkinningPalette(); // we need inverse matrix of root node's world transformation to calculate model-space palette. Matrix4x4 parentInvMatrix = hierarchy->GetNode(0).GetWorldTransformation(); parentInvMatrix.InverseIt(); for( u16 j = 0; j < hierarchy->GetNodeCount(); ++j ) { // creating skinning palette. // K = (Bj_M)^-1 * Cj_M // palette matrix is inverse bind pose in model-space multiplied by current pose in model-space. // world-space matrix palette[j] = hierarchy->GetNode(j).GetWorldTransformation(); // world-space -> model-space palette[j] = parentInvMatrix * palette[j]; // skinning palette matrix ( model-space * inverse bind pose ) palette[j] *= skeleton->GetInvBindPose(j); } } }