| 151 | } |
| 152 | |
| 153 | void AnimatedModel::PreInitSkinningData() |
| 154 | { |
| 155 | if (!SkinnedModel || !SkinnedModel->IsLoaded()) |
| 156 | return; |
| 157 | PROFILE_CPU(); |
| 158 | PROFILE_MEM(Animations); |
| 159 | ScopeLock lock(SkinnedModel->Locker); |
| 160 | |
| 161 | SetupSkinningData(); |
| 162 | auto& skeleton = SkinnedModel->Skeleton; |
| 163 | const int32 bonesCount = skeleton.Bones.Count(); |
| 164 | const int32 nodesCount = skeleton.Nodes.Count(); |
| 165 | |
| 166 | // Get nodes global transformations for the initial pose |
| 167 | GraphInstance.NodesPose.Resize(nodesCount, false); |
| 168 | auto nodesPose = GraphInstance.NodesPose.Get(); |
| 169 | for (int32 nodeIndex = 0; nodeIndex < nodesCount; nodeIndex++) |
| 170 | { |
| 171 | Matrix localTransform; |
| 172 | skeleton.Nodes[nodeIndex].LocalTransform.GetWorld(localTransform); |
| 173 | const int32 parentIndex = skeleton.Nodes[nodeIndex].ParentIndex; |
| 174 | if (parentIndex != -1) |
| 175 | nodesPose[nodeIndex] = localTransform * nodesPose[parentIndex]; |
| 176 | else |
| 177 | nodesPose[nodeIndex] = localTransform; |
| 178 | } |
| 179 | GraphInstance.Invalidate(); |
| 180 | GraphInstance.RootTransform = nodesCount > 0 ? skeleton.Nodes[0].LocalTransform : Transform::Identity; |
| 181 | |
| 182 | // Setup bones transformations including bone offset matrix |
| 183 | Matrix3x4* output = (Matrix3x4*)_skinningData.Data.Get(); |
| 184 | const SkeletonBone* bones = skeleton.Bones.Get(); |
| 185 | for (int32 boneIndex = 0; boneIndex < bonesCount; boneIndex++) |
| 186 | { |
| 187 | auto& bone = bones[boneIndex]; |
| 188 | Matrix identityMatrix = bone.OffsetMatrix * nodesPose[bone.NodeIndex]; |
| 189 | output[boneIndex].SetMatrixTranspose(identityMatrix); |
| 190 | } |
| 191 | _skinningData.OnDataChanged(true); |
| 192 | |
| 193 | UpdateBounds(); |
| 194 | UpdateSockets(); |
| 195 | } |
| 196 | |
| 197 | void AnimatedModel::GetCurrentPose(Array<Matrix>& nodesTransformation, bool worldSpace) const |
| 198 | { |
no test coverage detected