我正在尝试使用Helix Toolkit导入3D模型.我无法弄清楚如何做到这一点.是否有任何关于使用此工具包导入3D模型的在线指南,或者是否有另一种更简单的方法来导入除Helix之外的3D模型.
问候
这是我的代码:
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 …Run Code Online (Sandbox Code Playgroud) 我想在helix-toolkit中将任何MeshElement3D(例如BoxVisual3d)显示为线框.如何实现这一目标?
编辑:
感谢Erno de Weerd的回答,我能够编写以下代码
扩展BoxVisual3D的类
public class GeometryBoxVisual3D : BoxVisual3D
{
public MeshGeometry3D Geometry()
{
return Tessellate();
}
}
Run Code Online (Sandbox Code Playgroud)将框的实例添加到视口:
GeometryBoxVisual3D box = new GeometryBoxVisual3D();
box.Fill = new SolidColorBrush(Colors.Red);
Viewport3D.Children.Add(box);
MeshGeometry3D geometry3 = box.Geometry();
LinesVisual3D lines = new LinesVisual3D();
lines.Thickness = 3;
lines.Points = geometry3.Positions;
lines.Transform = new TranslateTransform3D(3,1,1);
Viewport3D.Children.Add(lines);
Run Code Online (Sandbox Code Playgroud)这导致以下显示:

如果我隐藏原始框并将LinesVisual3D放在框的顶部,我可以将wirefrime显示为原始对象,但它仍然缺少边的边缘.
我的任务是使用Helix Toolkit可视化标量的3D字段。输入数组包含双精度值,没有限制,但通常在[-50000,+50000]之间。标量值影响多维数据集的颜色:最小值具有蓝色,0-白色,最大值-红色。所有其他颜色值均与该值进行插值。
现在,我正在尝试了解HelixToolkit.Wpf.SharpDX中的颜色转移贴图如何工作。为此,我创建了一个2x2x1标量的简单字段。
MainWindow.xaml
<hx:Viewport3DX
Name="view1"
Grid.Row="1"
BackgroundColor="SkyBlue"
Camera="{Binding Camera}"
EffectsManager="{Binding EffectsManager}"
EnableDesignModeRendering="True"
UseDefaultGestures="False"
CameraRotationMode="Trackball">
<hx:Viewport3DX.InputBindings>
<KeyBinding Key="B" Command="hx:ViewportCommands.BackView" />
<KeyBinding Key="F" Command="hx:ViewportCommands.FrontView" />
<KeyBinding Key="U" Command="hx:ViewportCommands.TopView" />
<KeyBinding Key="D" Command="hx:ViewportCommands.BottomView" />
<KeyBinding Key="L" Command="hx:ViewportCommands.LeftView" />
<KeyBinding Key="R" Command="hx:ViewportCommands.RightView" />
<KeyBinding Command="hx:ViewportCommands.ZoomExtents" Gesture="Control+E" />
<MouseBinding Command="hx:ViewportCommands.Rotate" Gesture="RightClick" />
<MouseBinding Command="hx:ViewportCommands.Zoom" Gesture="MiddleClick" />
<MouseBinding Command="hx:ViewportCommands.Pan" Gesture="LeftClick" />
</hx:Viewport3DX.InputBindings>
<hx:VolumeTextureModel3D VolumeMaterial="{Binding VolumeMaterial}" />
</hx:Viewport3DX>
Run Code Online (Sandbox Code Playgroud)
MainWindowViewModel.cs
public MainWindowViewModel()
{
Nx = 2;
Ny = 2;
Nz = 1;
var m = new VolumeTextureDiffuseMaterial(); …Run Code Online (Sandbox Code Playgroud) 我试图在HelixViewport3D中加载并显示一个3d模型.
我可以加载模型(OBJ),但我无法理解如何将模型放入视口.
这是我的WPF表单的截图...
viewprot被命名为'myView' - 我想我可以加入我的模型,但我没有看到任何明显的使用.
这是我的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" Height="350" Width="525">
<Grid>
<Grid HorizontalAlignment="Left" Height="250" Margin="241,37,0,0" VerticalAlignment="Top" Width="250">
<HelixToolkit:HelixViewport3D x:Name="myView" ZoomExtentsWhenLoaded="True">
<!-- Remember to add light to the scene -->
<HelixToolkit:SunLight/>
<!-- You can also add elements here in the xaml -->
<HelixToolkit:GridLinesVisual3D Width="8" Length="8" MinorDistance="1" MajorDistance="1" Thickness="0.01"/>
</HelixToolkit:HelixViewport3D>
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这是我的表单的代码.
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; …Run Code Online (Sandbox Code Playgroud) 我正在使用 C# WPF,并且尝试从 3D 模型渲染 2D 视图,我可以将其用作 ui 项目的预览图像。
为了实现这一目标,我尝试正确使用此类:
RenderTargetBitmap 类( https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap(v=vs.110).aspx )
这就是我尝试使用它的方式:
更新后就无所谓了
public void SetModelImage()
{
RenderTargetBitmap bmp = new RenderTargetBitmap(200, 200, 96, 96, PixelFormats.Pbgra32);
PngBitmapEncoder png = new PngBitmapEncoder();
Viewport3D myViewport3d = new Viewport3D();
ModelVisual3D myModelVisual3D = new ModelVisual3D();
Model3DGroup myModel3DGroup = new Model3DGroup();
GeometryModel3D myGeometryModel = new GeometryModel3D();
this.previewModel = new PngBitmapEncoder();
PerspectiveCamera myPCamera = new PerspectiveCamera();
myModel3DGroup.Children.Add(this.content);// ajoute le modele
myModelVisual3D.Content = myModel3DGroup;
myModelVisual3D.Content = this.content;
myViewport3d.Children.Add(myModelVisual3D);
bmp.Render(myViewport3d);
this.previewModel.Frames.Add(BitmapFrame.Create(bmp));
string filepath = …Run Code Online (Sandbox Code Playgroud) 注意:我在 XAML 片段中省略了相机和灯光定义,主要关注真正的问题。
我想以类似于以下的方式将 绑定ObservableCollection到 WPF 的 3D 类之一(如ModelVisual3D):
<Viewport3D>
<Viewport3D.Children>
<Some3DClass ItemsSource="{Binding Objects}">
<Some3DClass.ItemTemplate>
<!-- definition of the template -->
</Some3DClass.ItemTemplate>
</Viewport3D.Children>
</Viewport3D>
Run Code Online (Sandbox Code Playgroud)
但是,经过一些研究和测试,我在 WPF 中没有发现任何类似的东西。
Helix 工具包是一个为 WPF 提供一组 3D 组件的库。此外,我发现其中一个示例 ( DataTemplate ) 声称提供了我所需要的。
下面是示例中 xaml 部分的类似实现:
<helix:HelixViewport3D>
<local:ItemsVisual3D ItemsSource="{Binding Objects}">
<local:ItemsVisual3D.ItemTemplate>
<DataTemplate3D>
<CubeVisual3D Center="{Binding Position}" SideLength="3" Fill="OrangeRed"/>
</DataTemplate3D>
</local:ItemsVisual3D.ItemTemplate>
</local:ItemsVisual3D>
</helix:HelixViewport3D>
Run Code Online (Sandbox Code Playgroud)
这个例子的工作归功于两个类:
ItemsVisual3D:扩展ModelVisual3D为包含IEnumerable ItemsSource依赖属性的类。它还包含一个DataTemplate3D来控制集合中单个元素的呈现。DataTemplate3D:一个自定义模板,派生自DispatcherObject使用 a …我正在使用HelixToolkit来展示一些3D模型.窗口右下方有一个图标.它怎么能被隐藏?请看这个截图:

我在HelixToolKit中创建了一个点云。我需要为每个点应用颜色。当我使用PointVisual3D时,没有为每个点设置颜色的选项。它为整个点云设置颜色。当我在 Helix 工具包中使用PointGeometryModel3D(使用 SharpDX)时,我也无法为每个点设置颜色。可以为点云中的每个点设置颜色。
谢谢...
我正在尝试使用helixtoolkit在WPF应用程序中显示一个3d对象,并根据沿x,y,z轴的3个变量(用户输入)旋转它.但我没有找到螺旋工具包中的一个函数来旋转3d对象.
C#代码
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
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ModelImporter importer = new ModelImporter();
Model3D model = importer.Load("D:\\Crate1.obj");
Models.Content = model;
// need to apply rotation to the model using three x,y,z variables
}
}
}
Run Code Online (Sandbox Code Playgroud)
XAML代码
<Window x:Class="HelixTrial.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" …Run Code Online (Sandbox Code Playgroud) 我是WPF的新手,我正在尝试制作一个显示3D模型的程序(保存在我的计算机上)并根据按钮点击进行旋转.我想有三个按钮来围绕x,y和z轴旋转对象.我有代码显示模型,但我不确定如何使用按钮单击旋转它.这是我到目前为止所拥有的;
C#
public MainWindow()
{
InitializeComponent();
ModelVisual3D device3D = new ModelVisual3D();
device3D.Content = Display3d(MODEL_PATH);
// Add to view port
viewPort3d.Children.Add(device3D);
}
private Model3D Display3d(string model)
{
Model3D device = null;
try
{
//Adding a gesture here
viewPort3d.RotateGesture = new MouseGesture(MouseAction.LeftClick);
//Import 3D model file
ModelImporter import = new ModelImporter();
//Load the 3D model file
device = import.Load(model);
}
catch (Exception e)
{
// Handle exception in case can not find the 3D model file
MessageBox.Show("Exception Error : " + e.StackTrace); …Run Code Online (Sandbox Code Playgroud) helix-3d-toolkit ×10
wpf ×8
c# ×7
3d ×2
helix ×2
3d-modelling ×1
bitmap ×1
data-binding ×1
point-clouds ×1
rotation ×1
sharpdx ×1
xaml ×1