0

Loading .OBJ 3D files

P S V Ramaraju 2 years ago in Question • updated by anonymous 3 months ago 6

Hello!!! I am using helix tool kit for one of my visual studio project i.e, loading 3D models. With that I am able to successfully load stl files. Is it possible to load 3d .OBJ files?? Thanks in advance.

While I'm still just beginning here also, this seems to work (converted from VB.net).


Model3DGroup MdlGrp = null;
switch (Path.GetExtension(FilDia.FileName).ToUpper) {
    case ".3DS":
        StudioReader ObjRed = new StudioReader();
        MdlGrp = ObjRed.Read(FilDia.FileName);
        break;
    case ".LWO":
        LwoReader ObjRed = new LwoReader();
        MdlGrp = ObjRed.Read(FilDia.FileName);
        break;
    case ".OFF":
        OffReader ObjRed = new OffReader();
        MdlGrp = ObjRed.Read(FilDia.FileName);
        break;
    case ".OBJ":
        ObjReader ObjRed = new ObjReader();
        //ObjRed.DefaultMaterial = UseMat
        MdlGrp = ObjRed.Read(FilDia.FileName);
        break;
    case ".STL":
        StLReader ObjRed = new StLReader();
        MdlGrp = ObjRed.Read(FilDia.FileName);
        break;
}

My code is this. Please help me to integrate with your code. Thanks in advance :)


using HelixToolkit.Wpf;
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Media3D;
namespace Display3DModel
{
    public partial class MainWindow : Window
    {
        private const string MODEL_PATH = "D:/vs/display3D-master/Display3DModel/bicycle.stl";
        public object FilDia { get; private set; }
        public MainWindow()
        {
            InitializeComponent();
            Model3DGroup MdlGrp = null; 

            ModelVisual3D device3D = new ModelVisual3D();
            device3D.Content = Display3d(MODEL_PATH);
            viewPort3d.Children.Add(device3D);         
        }
        private Model3D Display3d(string model)
        {
            Model3D device = null;
            try
            {
                Console.WriteLine("Hello!!!");
                viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);
                ModelImporter import = new ModelImporter();
                device = import.Load(model);
            }
            catch (Exception e)
            {       
                MessageBox.Show("Exception Error : " + e.StackTrace);
            }
            return device;
        }     
    }
}


Something like this:


      Model3DGroup MdlGrp = null;
      ModelVisual3D device3D = new ModelVisual3D();
      ObjReader ObjRed = new ObjReader();
      MdlGrp = ObjRed.Read(MODEL_PATH);
      device3D.Content = MdlGrp;
      ViewWindow.Children.Add(device3D);
      ViewWindow.Children.Add(new DefaultLights());
      ViewWindow.ZoomExtents(0.0);