MCPcopy Create free account
hub / github.com/defold/defold / LoadSkins

Function LoadSkins

engine/modelc/src/modelimporter_gltf.cpp:1370–1427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1368}
1369
1370static void LoadSkins(Scene* scene, cgltf_data* gltf_data)
1371{
1372 if (gltf_data->skins_count == 0)
1373 return;
1374
1375 InitSize(scene->m_Skins, gltf_data->skins_count, gltf_data->skins_count);
1376
1377 for (uint32_t i = 0; i < gltf_data->skins_count; ++i)
1378 {
1379 cgltf_skin* gltf_skin = &gltf_data->skins[i];
1380
1381 Skin* skin = &scene->m_Skins[i];
1382 skin->m_Name = DuplicateObjectName(gltf_skin);
1383 skin->m_Index = i;
1384
1385 InitSize(skin->m_Bones, gltf_skin->joints_count+1, gltf_skin->joints_count);
1386
1387 cgltf_accessor* accessor = gltf_skin->inverse_bind_matrices;
1388 for (uint32_t j = 0; j < gltf_skin->joints_count; ++j)
1389 {
1390 cgltf_node* gltf_joint = gltf_skin->joints[j];
1391 Bone* bone = &skin->m_Bones[j];
1392 bone->m_Name = DuplicateObjectName(gltf_joint);
1393 bone->m_Index = j;
1394 bone->m_ParentIndex = FindBoneIndex(gltf_skin, gltf_joint->parent);
1395
1396 if (bone->m_ParentIndex != INVALID_INDEX)
1397 {
1398 Bone* parent = &skin->m_Bones[bone->m_ParentIndex];
1399 if (parent->m_Children.Full())
1400 parent->m_Children.OffsetCapacity(4);
1401 parent->m_Children.Push(bone);
1402 }
1403
1404 // Cannot translate the bones here, since they're not created yet
1405 // bone->m_Node = ...
1406 if (accessor)
1407 {
1408 float matrix[16];
1409 if (ReadAccessorMatrix4(accessor, j, matrix))
1410 {
1411 FromMatrix4x4(matrix, bone->m_InvBindPose);
1412 } else
1413 {
1414 assert(false);
1415 }
1416 }
1417 else
1418 {
1419 SetIdentity(bone->m_InvBindPose);
1420 }
1421 }
1422
1423 SortSkinBones(skin);
1424
1425 // LOAD SKELETON?
1426 }
1427}

Callers 1

LoadSceneFunction · 0.85

Calls 9

InitSizeFunction · 0.85
DuplicateObjectNameFunction · 0.85
FindBoneIndexFunction · 0.85
ReadAccessorMatrix4Function · 0.85
SortSkinBonesFunction · 0.85
assertFunction · 0.50
FullMethod · 0.45
OffsetCapacityMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected