Adding the same SceneNode to a SceneNodeGroupModel3D with HelixToolkit and SharpDX in C#

58 Views Asked by At

I have a Viewport3DX binded to a ModelGroup (which is a SceneNodeGroupModel3D). In my case, I have to import an .obj file as a SceneNode and add it to the ModelGroup using the function ModelGroup.AddNode(node). I do it as it follows:

var importer = new Importer();
HelixToolkitScene scene = importer.Load("PathToTheModel");
ModelGroup.AddNode(scene.Root)

But as soon as I try to add the same SceneNode (because I want to import the same model but then place it in a different position), it doesn't work. In fact, the second ModelGroup.AddNode(scene.Root) will return false, because we alredy have such SceneNode in the SceneNodeGroupModel3D.

The solution I found is using again the importer, but I feel like it's not the way how to do it because once I loaded the model, it does not make sense reloading it, right?

As far as I saw, when you use the importer, the SceneNode is linked to a new GUID (globally unique identifier) and the function .AddNode() checks for the existing nodes of the SceneNodeGroupModel3D and in case of match, ignores the command. Then in case of using the same scene.Root just adds one, and if I import twice, I am able to get the two identical models in the group, but with differents GUIDs.

So, the question is how could add to SceneNode and a clone to the same SceneNodeGroupModel3D? I don't mind if it's modifying the GUIDs, clonning the whole SceneNode or any workaround you might suggest. For this example might be not a problem, but imagine if we have 1 model but 100 times, importing and loading the same model all the time would be a waste of resources.

Thanks in advance!

0

There are 0 best solutions below