lo48576 / fbxcel-dom

FBX DOM library for Rust. // See https://github.com/lo48576/fbx-viewer for working example application // rework (total rewrite) is planned
Apache License 2.0
25 stars 10 forks source link

Easy Traversal of Scene Graph? #2

Open Kleptine opened 3 years ago

Kleptine commented 3 years ago

It looks like there's no functionality to traverse a scene graph (ie. parent/child connections). Is that correct? Just checking in case I'm blind, before I implement it myself.

I see the connections iterator on objects, just not an easy way to, for instance, get the root objects of the scene or get the parent of an existing object.

lo48576 commented 3 years ago

I implemented object connections iterators to traverse the graph, but yeah it wouldn't be an easy stuff to use. This is because some object nodes have multiple parents, and I don't know who can have multiple parents and who won't. (See https://github.com/lo48576/fbx_objects_depviz/blob/master/examples/texture-and-mesh.dot.png and https://raw.githubusercontent.com/lo48576/fbx_objects_depviz/91e41fed2a7d0acbc0d8a93e64aa20638a30db57/examples/all.dot.svg for example.) That is, at least for now, you have to filter parents by object node type, in order to get the "parent" node you really want to.

To get scene nodes, you can use v7400::Document::scene().

To get parents and children, create v7400::object::ObjectHandle for the object and call source_objects() and/or destination_objects() methods of it. source_objects() returns children, and destination_nodes() returns parents. (Yeah I think these names are awful, but "source object" and "destination object" are terms used in FBX SDK...)

Kleptine commented 3 years ago

Ah, gotcha. Is it correct to say that a Mesh object will always have 0 or 1 parent Mesh objects? Having multiple parents definitely makes sense for Materials and other objects that could be linked to multiple things.

So it would be sensible to expose a traversable structure (similar to tree()) that exposed the tree structure of Mesh Objects?

Kleptine commented 3 years ago

Or, maybe I mean a Model object, not a Mesh object?

lo48576 commented 3 years ago

As far as I investigate, usually Model (Null) nodes and Model (Mesh) nodes would have at most 1 parent Model (Null or Mesh) nodes. (A Model (Null) node here means an object node with class == "Model" and subclass == "Null".)

However, I know a counter example, where Model (Null) node have no Model (Null or Mesh) as a parent, but have Model (LimbNode) instead. I had not been able to understand what this node and structure mean, and gave up understanding them. screenshot-2021-03-11-032539+0900 This is one of the reason I didn't implement such convenient sub-tree access API: I have no way to know restrictions for parents-children relations (because FBX is proprietary format), and additionally there are many sets of object types which makes tree structure. (fbx_object_depviz and example filters is a helper tool to observe such objects structure formed by subset of nodes...)

So, in short, I think that a Model (Null or Mesh) may have 0 or 1 Model (Null or Mesh) parent and they make tree structure, but there could be exceptions, and I don't have any guarantees and am not confident.