angus Posted October 15, 2019 Posted October 15, 2019 I see that I can use getBoneTransform(index) to get the transformation matrix of a bone, but I cannot see how to get it for children bones of the bones that are returned when enumerating the ObjectMeshSkinned. Is there any way of getting those values?
alexander Posted October 16, 2019 Posted October 16, 2019 Hi Angus, index is a unique number for every bone in your ObjectMeshSkinned. Use getBoneTransform() to get transform of children or parent bones. It doesn't matter. For example: int bone_parent = mesh->findBone("my_parent_bone"); for (int i = 0; i < mesh->getNumBoneChildren(bone_parent); i++) { int bone_child = mesh->getBoneChild(bone_parent, i); mat4 transform = mesh->getBoneTransform(bone_child); } Best regards, Alexander
angus Posted October 16, 2019 Author Posted October 16, 2019 5 hours ago, alexander said: Hi Angus, index is a unique number for every bone in your ObjectMeshSkinned. Use getBoneTransform() to get transform of children or parent bones. It doesn't matter. For example: I think there may be a bug in that case. The integers returned by mesh->getBoneChild(bone_parent, i); are not unique. The values returned will be 1,2,3,4 for parent bones and bone 2 will have children bone IDs 1,2,3,4 as well. ObjectMeshSkinnedPtr oms = ObjectMeshSkinned::cast(Editor::get()->getNodeById(1538661943)); for (int i = 0; i < oms->getNumBones(); i++) { int childcount = oms->getNumBoneChildren(i); Log::message("Parent: [%d] [%d] [%s]\n", i, childcount, oms->getBoneName(i)); if (childcount > 0) { for (int j = 0; j < oms->getNumBoneChildren(i); j++) { int child_id = oms->getBoneChild(i, j); Log::message("Child: [%d][%d][%s]\n", i, child_id, oms->getBoneName(child_id)); } } }
alexander Posted October 17, 2019 Posted October 17, 2019 Hi Angus, I've imported standard MetaRig from Blender and all seems to work. How your model looks like? Hierarchy? Can you give us small sample with your model? Best regards, Alexander
angus Posted October 17, 2019 Author Posted October 17, 2019 That's odd. I've attached the FBX I'm using in testing and I get the output below: Parent: [0] [0] [Head] Parent: [1] [3] [Neck] Child: [1][0][Head] Child: [1][3][Clavicle_L] Child: [1][4][Clavicle_R] Parent: [2] [1] [Spine03] Child: [2][1][Neck] Parent: [3] [0] [Clavicle_L] Parent: [4] [0] [Clavicle_R] Which seems wrong to me as, for example, the child_id is 4 but a parent is also bone ID 4. Have I made a mistake in my enumeration code? HumanMale_Bust.FBX
alexander Posted October 18, 2019 Posted October 18, 2019 Hi,child_id is 4 but a parent is also bone ID 4 As i said, "index is a unique number for every bone in your ObjectMeshSkinned". ObjectMeshSkinned::getNumBones() returns all bones, including children. Not the roots only. That's the reason why you are getting "Parent: [4] [0] [Clavicle_R]" and "Child: [1][4][Clavicle_R] ". Change log messages to this and all will be clear to understand: ObjectMeshSkinnedPtr oms = ObjectMeshSkinned::cast(Editor::get()->getNodeById(1538661943)); Log::message("List of all bones in ObjectMeshSkinned:\n"); for (int i = 0; i < oms->getNumBones(); i++) { int childcount = oms->getNumBoneChildren(i); Log::message("Bone \"%s\" (id: %d, children count: %d)\n", oms->getBoneName(i), i, childcount); if (childcount > 0) { for (int j = 0; j < oms->getNumBoneChildren(i); j++) { int child_id = oms->getBoneChild(i, j); Log::message(" Child \"%s\" (id: %d)\n", oms->getBoneName(child_id), child_id); } } } Best regards, Alexander
Recommended Posts