Search code examples
c#wpfhelix-3d-toolkit

How to set up a 3d model using HelixToolkit.Wpf.SharpDX?


I try to render 3d models in WPF using HelixToolkit.Wpf.SharpDX.

My models are static and consist of a vertex buffer and a set of triangles. Each triangle has a material assigned to and each triangle point has a UV coordinate and a normal.

How do I set up the model to achieve:

  • not to duplicate the index buffer for each group of triangles with the same material
  • making the whole model selectable with a mouse click
  • using the Helix Toolkit's PhongMaterial
  • making the setup MVVM compatible
  • good rendering performance

I went through all the examples in the Helix Tookit's repository, but I'm really confused with all the MeshGeometry3D, MeshGeometryModel3D, Model3DCollection, Model3DGroup, Visual3D, and UIElement3D classes, some of which seem to only exist in WPF or Helix, but some of them exist in both namespaces but behave differently.

I tried to create a UIElement3D with a Model3DGroup for each model, then add a GeometryModel3D having a PhongMaterial and a MeshGeometry3D with all triangles for each material to the Model3DGroup.

I'm especially unsure about how to deal with the vertex buffer which I have to define for each MeshGeometry3D. Does that mean it will be duplicated when rendering? Do I need to separate all vertices into vertex buffers for each group of triangles with the same material or can I just assign the same vertex buffer to each triangle group?

I'm familiar with OpenGL and DirectX but I'm new to WPF and Helix Toolkit.


Solution

  • Helix toolkit doesn't take vertex buffer directly. You need to convert your vertex and triangle index data into helix toolkit MeshGeometry3D and pass both material and MeshGeometry3D to a MeshGeometryModel3D.

    Also you seems to be confused about the HelixToolkit.wpf and HelixToolkit.wpf.sharpdx. These are two separate libraries.

    Model3DCollection, Model3DGroup, Visual3D, and UIElement3D are only available in Helixtoolk.wpf, not Helixtoolkit.wpf.sharpdx.

    Please refer to the wiki page and examples for more info.