[英]How to use Xbim in WPF to visualise an .IFC in 3D
I'm trying to learn how to use Xbim in a WPF app to create a 3D view of a model that the user can spin around and view.我正在尝试学习如何在 WPF 应用程序中使用 Xbim 创建 model 的 3D 视图,用户可以旋转并查看该视图。 I load my ifc file in the C# code as follows:
我在 C# 代码中加载我的 ifc 文件,如下所示:
var model = IfcStore.Open("Images/test.ifc"); var model = IfcStore.Open("Images/test.ifc");
var context = new Xbim3DModelContext(model); var context = new Xbim3DModelContext(模型);
context.CreateContext(); context.CreateContext();
I then set up a viewport in XAML as follows:然后我在 XAML 中设置了一个视口,如下所示:
<xbim:DrawingControl3D Name="test3D"></xbim:DrawingControl3D> <xbim:DrawingControl3D Name="test3D"></xbim:DrawingControl3D>
I am struggling to work out how to link the two and display the loaded model in the viewport.我正在努力弄清楚如何链接两者并在视口中显示加载的 model。 Would anyone be able to advise / point be towards a good tutorial?
任何人都可以建议/指出一个好的教程吗? If I run the app as stands I can see an empty viewport that I can move around, just need to get the model in there.
如果我以站立方式运行应用程序,我可以看到一个可以四处移动的空视口,只需要将 model 放在那里。
Thanks!谢谢!
You need some more code.你需要更多的代码。
private ObjectDataProvider ModelProvider
{
get
{
return MainFrame.DataContext as ObjectDataProvider;
}
}
public void openFile()
{
var model = IfcStore.Open("Images/test.ifc");
var context = new Xbim3DModelContext(model);
context.CreateContext();
ModelProvider.ObjectInstance = model;
ModelProvider.Refresh();
}
And on the xaml side:在 xaml 方面:
<Window.Resources>
<ObjectDataProvider x:Key="ModelProvider" IsInitialLoadEnabled="False" />
</Window.Resources>
<Grid Name="MainFrame" DataContext="{StaticResource ModelProvider}">
<xbim:DrawingControl3D x:Name="test3D" Model="{Binding}" />
</Grid>
Thank you for all those comments.感谢您的所有评论。 Sadly, this did not work for me.
可悲的是,这对我不起作用。 I had to move the line ModelProvider.Refresh();
我不得不移动行 ModelProvider.Refresh(); to an event named
一个名为的事件
void MainWindow_Loaded( object sender, RoutedEventArgs e )
{
ModelProvider.Refresh();
}
also, i added in the xaml file follwing Loaded="MainWindow_Loaded">另外,我在 xaml 文件中添加了 Loaded="MainWindow_Loaded">
Now, my two files look like this:现在,我的两个文件如下所示:
<Window x:Class="wpf2bim.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:wpf2bim"
xmlns:presentation="http://schemas.Xbim.com/Presentation"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525"
Loaded="MainWindow_Loaded">
<Window.Resources>
<ObjectDataProvider x:Key="ModelProvider" IsInitialLoadEnabled="False" />
</Window.Resources>
<Grid Name="MainFrame" DataContext="{StaticResource ModelProvider}">
<presentation:DrawingControl3D x:Name="test3D" Model="{Binding}" />
</Grid>
and the c# file和 c# 文件
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
openFile();
}
void MainWindow_Loaded( object sender, RoutedEventArgs e )
{
ModelProvider.Refresh();
}
private ObjectDataProvider ModelProvider
{
get
{
return MainFrame.DataContext as ObjectDataProvider;
}
}
public void openFile()
{
var model = IfcStore.Open(@"C:\SampleHouse.ifc");
var context = new Xbim3DModelContext(model);
context.CreateContext();
ModelProvider.ObjectInstance = model;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.