Bpy: get instances world matrix AND tree hierarchie

Using depsgraph.object_instances, we can get real world_matrix of all instances of the scene, but not the hierarchy
Using depsgraph.objects, we can get hierarchy (get instance_collection.objects or children) of node, but not world_matrix of instances.

I can’t find a way to get both hierarchy and real world_matrix for a scene.
I am talking about complex cases where there are some linked instance collection containing linked instance collection.

Is there a way to manage it?


I don’t think there’s a good Python API for this. I think it would be useful, also for example for some Cycles features to be able to have more info about collections of evaluated objects.

The Alembic and USD exporters use an internal AbstractHierarchyIterator though I don’t know the implementation details of that, not sure if it’s possible to replicate that in Python. It would make sense to expose this or build its functionality into the depsgraph iterators somehow.


Maybe I’m misunderstanding the question, but can’t you walk the .parent of objects to get the hierarchy (backwards at least)

You can get the object parenting hierarchy that way, but not the collection hierarchy I think.

We can’t use the ‘parent’ of instance, that refers to instancer in current file, but not the real instance of parent of original object. That means that we cant get the real hierarchy of instances.

If we are trying to manage objects instead of instance, we can’t get world_matrix of instances that way.

I am currently working a of refactoring of glTF exporter, but I can’t manage all cases because of this lack on bpy.