9

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.

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

}
}
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Ali Naqi
  • 101
  • 1
  • 1
  • 3
  • 1
    What have you done? Are you experiencing runtime errors, compile-time errors? Are you getting error messages? Do you not know what code to write? – Rob Jan 13 '13 at 01:02
  • @Rob the problem is i have search it so far for our project. i haven't written any code to do it. and i am beginner in this. i was working on the WPF project it was indeed a need to import a 3D model. thnx fo query Rob – Ali Naqi Jan 13 '13 at 07:16
  • 3
    my questions were designed to lead you to providing more details and getting you to ask the right question. It's as if someone walked up to me, holding the head-side of the hammer and said, "How come this isn't helping me take this screw out of the wall?" Good questions outline what you're trying to accomplish, background about why you're pursuing what you're pursuing, and what you've tried doing. I'm not even sure you've tried writing code at this point, so how can I help you? That's the best way to get good answers on this site. – Rob Jan 13 '13 at 09:28
  • code is given above @Rob . i am new at this. – Ali Naqi Jan 13 '13 at 19:04

2 Answers2

9

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

 Model3DGroup group = HelixToolkit.Wpf.ModelImporter.Load(@"Your path here");
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
2

Only you need to put this:

<HelixToolkit:FileModelVisual3D x:Name="model1" Source="C:\$path\test_obj.obj"/>
Juan BW
  • 21
  • 2