1

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"?

Dawnkeeper
  • 2,844
  • 1
  • 25
  • 41
  • Does `node` have some kind of `Parent` property? Because the obvious way is to store parent before `RemoveSelf` which prolly remove parent and then use `parent.AddNode(mg)` ... **Disclamer: I've never use `HelixToolkit` but it's common in node-like structures** – Selvin Jul 15 '21 at 14:16
  • Helixtoolkit have a great set of [examples](https://github.com/helix-toolkit/helix-toolkit/tree/master/Source/Examples). Many issues can be solved by finding a example that does what you want, and checking how it works. – JonasH Jul 15 '21 at 14:32
  • @Selvin yes, but it is read only. – Dawnkeeper Jul 15 '21 at 16:08
  • @JonasH I have looked at a bunch of them already, but have not found what I'm looking for. I'll continue with it ^^ – Dawnkeeper Jul 15 '21 at 16:09

1 Answers1

2

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

Lance H
  • 886
  • 1
  • 9
  • 14
  • as GroupNode does not have a Transform property I ended up using `modelgrout.ModelMatrix = transform.ToMatrix()`. Is this the correct way to do it? – Dawnkeeper Jul 22 '21 at 10:02
  • 1
    Yes, transform is WPF specific class. Eventually it is converted into model matrix and being used by scene node. – Lance H Jul 22 '21 at 16:43