vpenades / SharpGLTF

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

No way to add a dummy (empty) node #29

Closed gleblebedev closed 3 years ago

gleblebedev commented 4 years ago

It seems that currently there is no way to add a dummy node into scene. There are several methods to add a node: AddMesh AddCamera AddLight AddSkinnedMesh

but there is no way to add just a node.

vpenades commented 4 years ago

The Scene builder in the Toolkit works differently than the one in the Schema2 namespace.

I assume you want to create a node tree, and then add some meshes to some of the nodes, right?

To do so, you create a NodeBuilder, and add child nodes to it. Finally, you call Scene.AddMesh(mesh, node); and the whole node tree will be automatically added to the final scene.

Something like this:

var root = new NodeBuilder(root);
var child1 = root.CreateNode("Child1");
var child2 = root.CreateNode("Child2");

var scene = new SceneBuilder();
scene.AddMesh(mesh1, child1);
scene.AddMesh(mesh2, child2);

Internally, SceneBuilder detects that each mesh is using the same NodeBuilder tree and uses it just once.

Notice that AddSkinnedMesh works in the same way, but instead of using 1 node, it uses many nodes, there's no need to create a "skin" object.