| 260 | } |
| 261 | |
| 262 | bool SkinnedModel::SetupSkeleton(const Array<SkeletonNode>& nodes) |
| 263 | { |
| 264 | // Validate input |
| 265 | if (nodes.Count() <= 0 || nodes.Count() > MAX_uint16) |
| 266 | return true; |
| 267 | auto model = this; |
| 268 | if (!model->IsVirtual()) |
| 269 | return true; |
| 270 | |
| 271 | ScopeLock lock(model->Locker); |
| 272 | |
| 273 | // Setup |
| 274 | model->Skeleton.Nodes = nodes; |
| 275 | model->Skeleton.Bones.Resize(nodes.Count()); |
| 276 | for (int32 i = 0; i < nodes.Count(); i++) |
| 277 | { |
| 278 | auto& node = model->Skeleton.Nodes[i]; |
| 279 | model->Skeleton.Bones[i].ParentIndex = node.ParentIndex; |
| 280 | model->Skeleton.Bones[i].LocalTransform = node.LocalTransform; |
| 281 | model->Skeleton.Bones[i].NodeIndex = i; |
| 282 | } |
| 283 | model->Skeleton.Dirty(); |
| 284 | ClearSkeletonMapping(); |
| 285 | |
| 286 | // Calculate offset matrix (inverse bind pose transform) for every bone manually |
| 287 | for (int32 i = 0; i < model->Skeleton.Bones.Count(); i++) |
| 288 | { |
| 289 | Matrix t = Matrix::Identity; |
| 290 | int32 idx = model->Skeleton.Bones[i].NodeIndex; |
| 291 | |
| 292 | do |
| 293 | { |
| 294 | t *= model->Skeleton.Nodes[idx].LocalTransform.GetWorld(); |
| 295 | idx = model->Skeleton.Nodes[idx].ParentIndex; |
| 296 | } while (idx != -1); |
| 297 | |
| 298 | t.Invert(); |
| 299 | |
| 300 | model->Skeleton.Bones[i].OffsetMatrix = t; |
| 301 | } |
| 302 | |
| 303 | return false; |
| 304 | } |
| 305 | |
| 306 | bool SkinnedModel::SetupSkeleton(const Array<SkeletonNode>& nodes, const Array<SkeletonBone>& bones, bool autoCalculateOffsetMatrix) |
| 307 | { |
nothing calls this directly
no test coverage detected