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

Function ImportBones

Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp:468–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

466}
467
468bool ImportBones(OpenFbxImporterData& data, String& errorMsg)
469{
470 // Check all meshes
471 const int meshCount = data.Scene->getMeshCount();
472 for (int i = 0; i < meshCount; i++)
473 {
474 const auto aMesh = data.Scene->getMesh(i);
475 const ofbx::Skin* skin = aMesh->getSkin();
476 if (skin == nullptr || IsMeshInvalid(aMesh))
477 continue;
478
479 for (int clusterIndex = 0, clusterCount = skin->getClusterCount(); clusterIndex < clusterCount; clusterIndex++)
480 {
481 const ofbx::Cluster* cluster = skin->getCluster(clusterIndex);
482 if (cluster->getIndicesCount() == 0)
483 continue;
484 const auto link = cluster->getLink();
485 ASSERT(link != nullptr);
486
487 // Create bone if missing
488 int32 boneIndex = data.FindBone(link);
489 if (boneIndex == -1)
490 {
491 // Find the node where the bone is mapped
492 int32 nodeIndex = data.FindNode(link);
493 if (nodeIndex == -1)
494 {
495 nodeIndex = data.FindNode(String(link->name), StringSearchCase::IgnoreCase);
496 if (nodeIndex == -1)
497 {
498 LOG(Warning, "Invalid mesh bone linkage. Mesh: {0}, bone: {1}. Skipping...", String(aMesh->name), String(link->name));
499 continue;
500 }
501 }
502
503 // Add bone
504 boneIndex = data.Bones.Count();
505 data.Bones.Resize(boneIndex + 1);
506 auto& bone = data.Bones[boneIndex];
507
508 // Setup bone
509 bone.NodeIndex = nodeIndex;
510 bone.ParentBoneIndex = -1;
511 bone.FbxObj = link;
512 bone.OffsetMatrix = GetOffsetMatrix(data, aMesh, link) * Matrix::Scaling(data.GlobalSettings.UnitScaleFactor);
513 bone.OffsetMatrix.Invert();
514
515 // Mirror offset matrices (RH to LH)
516 if (data.ConvertRH)
517 {
518 auto& m = bone.OffsetMatrix;
519 m.M13 = -m.M13;
520 m.M23 = -m.M23;
521 m.M43 = -m.M43;
522 m.M31 = -m.M31;
523 m.M32 = -m.M32;
524 m.M34 = -m.M34;
525 }

Callers 1

ImportDataOpenFBXMethod · 0.85

Calls 15

GetOffsetMatrixFunction · 0.85
ScalingFunction · 0.85
RotationQuaternionFunction · 0.85
getMeshCountMethod · 0.80
getMeshMethod · 0.80
getClusterCountMethod · 0.80
getClusterMethod · 0.80
getIndicesCountMethod · 0.80
getLinkMethod · 0.80
IsIdentityMethod · 0.80
IsMeshInvalidFunction · 0.70
StringClass · 0.50

Tested by

no test coverage detected