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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14295195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:59:50  来源:igfitidea点击:

How to import a 3D model in WPF using Helix Toolkit?

c#wpf3d-modellinghelix-3d-toolkit

提问by Ali Naqi

I am trying to import a 3D model using Helix Toolkit.i can't figure out how to do it. Is there any online guide about importing a 3D model using this Toolkit or if there is another easier way to import a 3D model except Helix.

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

Regards

问候

This is my Code:

这是我的代码:

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:\Hyman_Shephard\Hyman_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;
    }

}
}

回答by Mark Hall

Their documentation is still being constructed, but in looking at their source code, it appears that you want the ModelImporterMethod. It returns a Model3dGroupand its usage will look like this.

他们的文档仍在构建中,但在查看他们的源代码时,您似乎需要ModelImporter方法。它返回 aModel3dGroup并且它的用法看起来像这样。

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

回答by Juan BW

Only you need to put this:

只有你需要把这个:

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