vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
470 stars 75 forks source link

Append node #10

Closed promontis closed 5 years ago

promontis commented 5 years ago

Hi @vpenades !

What's the reasoning for building the node hierarchy exclusively via CreateNode()?

I'm traversing my application's DOM depth first, and I would like to create nodes independently from it's parent.

So say we have a DOM like this:

A
- B
   - C

I would like to:

So, I need something like AppendNode(), which would append the node to a node's children.

Is this something we could add?

vpenades commented 5 years ago

If you notice, it's not only in nodes, I try to avoid to create isolated gltf objects as much as possible across the whole API.

It could be possible to include an AddNode function, which would also require to add a CreateLogicalNode at root level.

The reasons are these:

If I allow isolated objects to be created, I need to prevent somehow, that a Node created in a model is not added in the scene of a different model.

Even if the new node is owned by the model, there's lots of breaking use cases that need to be checked: Self references. Circular dependencies. The root node in a scene, added to the child in another scene.

So for now, the best way to ensure the created tree is correct, is with the current API

promontis commented 5 years ago

Understandable :) I will try to work around this... will let you know if it works out!

promontis commented 5 years ago

It works! I now output to an intermediate object, which implements an interface that can be used to generate nodes by passing along a parent node.

vpenades commented 5 years ago

Notice that both Scene and Node already implement such interface, see IVisualNodeContainer

promontis commented 5 years ago

Thanks for the tip! Will try if this interface works as well 👍