如何使用Helix Toolkit在WPF中导入3D模型

本文关键字:导入 3D 模型 WPF 何使用 Helix Toolkit | 更新日期: 2023-09-27 17:51:26

我正在尝试使用Helix Toolkit导入3D模型。我不知道该怎么做。是否有任何关于使用此工具包导入3D模型的在线指南,或者是否有其他更简单的方法来导入3D模型,除了Helix。

这是我的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System;
using System.IO;
using System.Windows.Media.Media3D;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
    Model3DGroup group = HelixToolkit.Wpf.ModelImporter.Load(@"C:'Jack_Shephard'Jack_Shephard.obj");
     public static Model3DGroup Load(string path)
    {
        if (path == null)
        {
            return null;
        }
        Model3DGroup model = null;
        string ext = System.IO.Path.GetExtension(path).ToLower();
        switch (ext)
        {
            case ".3ds":
                {
                    var r = new HelixToolkit.Wpf.StudioReader();
                    model = r.Read(path);
                    break;
                }
            case ".lwo":
                {
                    var r = new HelixToolkit.Wpf.LwoReader();
                    model = r.Read(path);
                    break;
                }
            case ".obj":
                {
                    var r = new HelixToolkit.Wpf.ObjReader();
                    model = r.Read(path);
                    break;
                }
            case ".objz":
                {
                    var r = new HelixToolkit.Wpf.ObjReader();
                    model = r.ReadZ(path);
                    break;
                }
            case ".stl":
                {
                    var r = new HelixToolkit.Wpf.StLReader();
                    model = r.Read(path);
                    break;
                }
            case ".off":
                {
                    var r = new HelixToolkit.Wpf.OffReader();
                    model = r.Read(path);
                    break;
                }
            default:
                throw new InvalidOperationException("File format not supported.");
        }
        return model;
    }
}
}

如何使用Helix Toolkit在WPF中导入3D模型

他们的文档仍在构建中,但在查看他们的源代码时,似乎需要ModelImporter方法。它返回一个Model3dGroup,其用法如下所示:

 Model3DGroup group = HelixToolkit.Wpf.ModelImporter.Load(@"Your path here");

你只需要写这个:

<HelixToolkit:FileModelVisual3D x:Name="model1" Source="C:'$path'test_obj.obj"/>