I am using Assimp.net to import animated .dae files into my OpenTK engine and struggling to establish a usable hierarchal bone structure.
In the tutorial I am following, the root bone, or "joint", contains a list of it's children joints, and those a list of their children and so on.
Assimp returns each imported Mesh
object with a list of Bone
objects, emcapsuling the bone's Name
, OffsetMatrix
and VertexWeights
, but nothing about it's children or parent bones.
The Scene
, which contains the Mesh
, does have a list of total nodes
(some of which are bones) and these do have a parentName
value but building the hierarchy through recursive comparison checks is getting messy quick and is far from functioning.
How can I the isolate the root bone, then it's children, then their children, etc?
Turns out every node contains a collection of it's children called children
of type NodeCollection
, and from there I developed the following solution.
To find the root bone, iterate over every node
in the scene
and check if it's name is found in the bones
list contained in the mesh
, then if that node
has a parent name which isn't in the bones
list then it must be the root bone.
To build the bone hierarchy, get the children
from that "root bone" node found above, then find the matching name within the meshesbones
list, and from there extract the required vertex weights and offset matrix. Next, recursively search through the children of those children using the same method as above: iterating over each node
in the scene until the matching bone
name is found, then pull the data from the bone
within the bones
list, and do so reversely until there's no children left.
If there's a better way, I'd love to hear it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With