MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SetupSkeleton

Method SetupSkeleton

Source/Engine/Content/Assets/SkinnedModel.cpp:262–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262bool 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
306bool SkinnedModel::SetupSkeleton(const Array<SkeletonNode>& nodes, const Array<SkeletonBone>& bones, bool autoCalculateOffsetMatrix)
307{

Callers

nothing calls this directly

Calls 9

IsVirtualMethod · 0.80
GetVertexLayoutMethod · 0.80
FindElementMethod · 0.80
VertexElementClass · 0.50
CountMethod · 0.45
ResizeMethod · 0.45
DirtyMethod · 0.45
GetWorldMethod · 0.45
InvertMethod · 0.45

Tested by

no test coverage detected