helix-toolkit / helix-toolkit

Helix Toolkit is a collection of 3D components for .NET.
http://helix-toolkit.org/
MIT License
1.87k stars 663 forks source link

Loading fbx programmatically #1331

Open PULK4N opened 4 years ago

PULK4N commented 4 years ago

How do I load completely with C# I've already made an app based on BoneSkinDemo, so I already have MainViewModel I only want to have <hx:Viewport3DX x:Name="view"> </hx:Viewport3DX> in MainWindow.xaml and the rest of the code strictly implemented in C# Can someone help me with C# code required to load multiple .fbx models(unspecified number)? NO XAML CODE please

Imbalisimo commented 4 years ago

If your demo works, then the code below will create base necessities for the model to be displayed

view.Camera = new HelixToolkit.Wpf.SharpDX.OrthographicCamera()
            {
                LookDirection = new System.Windows.Media.Media3D.Vector3D(0, -10, -10),
                Position = new System.Windows.Media.Media3D.Point3D(0, 10, 10),
                UpDirection = new System.Windows.Media.Media3D.Vector3D(0, 1, 0),
                FarPlaneDistance = 5000,
                NearPlaneDistance = 0.1f
            };

DirectionalLight3D directionalLight3D = new DirectionalLight3D();
            directionalLight3D.Direction = view.Camera.LookDirection;
            directionalLight3D.Color = Color.FromRgb(214, 214, 214);
            view.Items.Add(directionalLight3D);

            view.EffectsManager = new DefaultEffectsManager();

            MainViewModel mainViewModel1 =
                new MainViewModel("path1");
            MainViewModel mainViewModel2 =
                new MainViewModel("path2");
            List<MainViewModel> models = new List<MainViewModel>();
            models.Add(mainViewModel1);
            models.Add(mainViewModel2);

            foreach (MainViewModel model in models)
            {
                Element3DPresenter element3DPresenter = new Element3DPresenter();
                element3DPresenter.Content = model.GroupModel;
                view.Items.Add(element3DPresenter);
            }

however for this you will need to set MainViewModel constructor to take a string which will be the path to file, and call OpenFile method in the constructor. You also need to set the path in OpenFile to the path you sent in constructor.

This is the code I used, if you have another way to get and set path and open file feel free to use it.