在Helix 3D Toolkit中为HelixViewport3D添加模型/内容

 风过无痕啦啦 发布于 2023-02-12 19:06

我试图在HelixViewport3D中加载并显示一个3d模型.

我可以加载模型(OBJ),但我无法理解如何将模型放入视口.

这是我的WPF表单的截图...主要形式

viewprot被命名为'myView' - 我想我可以加入我的模型,但我没有看到任何明显的使用.

这是我的XAML形式:

 

    
        
            
            
            
            
        
    

这是我的表单的代码.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Windows.Media.Media3D;
using HelixToolkit.Wpf;

namespace HelixTrial
{

/// 
/// Interaction logic for MainWindow.xaml
/// 
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        ObjReader CurrentHelixObjReader = new ObjReader();
        Model3DGroup MyModel = CurrentHelixObjReader.Read("C:/Users/Roger/Desktop/cube/cube.obj");

       // Now how to load it into the viewport... ?
    }    
}

}

你可以看到我被困在哪里.有人可以让我帮助我走上正轨.

1 个回答
  • 经过一些实验,我找到了解决方案.

    我在XAML中添加了以下内容:

     <ModelVisual3D x:Name="foo"/>
    

    诀窍是给它一个名字,例如'foo'.XAML现在看起来像这样:

     <Window x:Class="HelixTrial.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
        Title="MainWindow"  >
    <Grid>
        <Grid HorizontalAlignment="Left"  Margin="241,37,0,0" VerticalAlignment="Top" >
            <HelixToolkit:HelixViewport3D x:Name="myView" ZoomExtentsWhenLoaded="True">
                <!-- Remember to add light to the scene -->
                <HelixToolkit:SunLight/>
                <ModelVisual3D x:Name="foo"/>
                <!-- You can also add elements here in the xaml -->
                <HelixToolkit:GridLinesVisual3D  Length="8" MinorDistance="1" MajorDistance="1" Thickness="0.01"/>
            </HelixToolkit:HelixViewport3D>
        </Grid>
    </Grid>
    

    然后在代码中(根据我在上面的原始问题中发布的内容),你可以这样做:

     ObjReader CurrentHelixObjReader = new ObjReader();
            Model3DGroup MyModel = CurrentHelixObjReader.Read("C:/Users/Roger/Desktop/cube/cube.obj");
    
            // Display the model
            foo.Content = MyModel;
    

    当你发现如何时很容易;)

    2023-02-12 19:08 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有