WPF编程--3D控件HelixToolkit

目录

1. 环境

2. NuGet导入依赖

3. 编辑MainWindow.xaml.cs

4. 编辑MainWindow.xaml


WPF编程--3D控件HelixToolkit_第1张图片

源码:https://github.com/liugang198409/WpfDemo/tree/master/3DDemo 

视频:WPF编程--3D Demo_哔哩哔哩_bilibili

stl文件:https://download.csdn.net/download/liugang590/87426104

1. 环境

Visual Studio 2019 + .NET Framework 4.8.1

2. NuGet导入依赖

HelixToolkit

HelixToolkit.Wpf

WPF编程--3D控件HelixToolkit_第2张图片

3. 编辑MainWindow.xaml.cs

using HelixToolkit.Wpf;
using System;
using System.Windows;
using System.Windows.Media.Media3D;

namespace _3DDemo
{
    /// 
    /// MainWindow.xaml 的交互逻辑
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            //模型加载
            string modelPath1 = AppDomain.CurrentDomain.BaseDirectory + "A.stl"; //模型地址

            ModelImporter import = new ModelImporter();
            var initGroup1 = import.Load(modelPath1);

            string modelPath2 = AppDomain.CurrentDomain.BaseDirectory + "B.stl";

            var initGroup2 = import.Load(modelPath2);
            //材质
            //GeometryModel3D geometryModel3D = initGroup.Children[0] as GeometryModel3D;
            //DiffuseMaterial diffMat = new DiffuseMaterial(new SolidColorBrush(Colors.White));
            //geometryModel3D.Material = diffMat;
            //ViewPort3D进行显示
            ModelVisual3D modelVisual3d1 = new ModelVisual3D();
            modelVisual3d1.Content = initGroup1;
            viewPort3D.Children.Add(modelVisual3d1);
            ModelVisual3D modelVisual3d2 = new ModelVisual3D();
            modelVisual3d2.Content = initGroup2;
            viewPort3D.Children.Add(modelVisual3d2);

        }
    }
}

4. 编辑MainWindow.xaml


    

        
        
            
            
                
            
            

            
        

    


你可能感兴趣的:(WPF,HelixToolkit,3D控件,wpf)