Search code examples
c#wpfhelix-3d-toolkit

HelixToolkit scene manipulation


I'm using HelixToolkit to import a model and display it.
Now I want to take one of the objects of the model and rotate it.
Unfortunately I can't find a way to edit the scene the importer gives me.

var imp = new HelixToolkit.SharpDX.Core.Assimp.Importer();

var scene = imp.Load(".\\test.obj");

foreach (var node in scene.Root.Traverse().ToList())
{
    if (node.Name.Contains("gate"))
    {
        node.RemoveSelf(); // remove from scene to be able to add to group
        var mg = new SceneNodeGroupModel3D();
        mg.AddNode(node);
        mg.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1,0,0), 45 ));
        // could not find a way to add the group back
    }
}

this.ModelGroup.AddNode(scene.Root); // That's the SceneNodeGroupModel3D that is bound to the Viewport3DX for displaying

While I can remove the object and add it to the rotation group I can't add it back to the scene.

The SceneNodeGroupModel3Ds Parent property is not settable and a SceneNode also has no way to add children to it.

So How does scene editing work with HelixToolkit"?


Solution

  • Helix toolkit has two types of nodes, scene node type and element 3d model. Element 3d model types are wrappers of scene node to provide wpf dependency properties for xaml mvvm bindings. However, element 3d model types cannot be added into scene node tree, but scene node type can be added into element model type tree with SceneNodeGroupModel3D.

    Assimp importer only provides scene node type results, since it's not wpf dependant. You need to use Group node instead of GroupModel3D to add your model. Then find another group node in the scene graph to add your group node. Or you can add it under the root node, which is a Group node.

    Here is the wiki for more details https://github.com/helix-toolkit/helix-toolkit/wiki/Use-Element3D-or-SceneNode-under-WPF.SharpDX-or-UWP