如何在WPF Viewport3d中自动调整相机LookDirection?

问题描述:

我使用HelixToolKit的ModelImporter函数向我的Viewport3d添加了一个模型(STL文件),但首先没有显示出来。要查看添加的3D模型,我必须缩小。我的问题是,是否有任何方法可以动态/编程地缩小或旋转相机到新添加的模型或任何需要立即显示的相机。如何在WPF Viewport3d中自动调整相机LookDirection?

我正在为项目使用C#WPF的helix工具包。

更新:为此,有一种称为ZoomExtents的方法。问题已解决。 更新#2:感谢@sideshowbarker的警告;

//in this case currModel= Model3D and mainViewport=HelixViewport3D  
ModelVisual3D device3D = new ModelVisual3D(); 
device3D.Content = currModel; 
mainViewport.Children.Add(device3D); 
mainViewport.ZoomExtents(); 
//after loading 3D-Model into viewport you can just call the ZoomExtents() method in namespace of HelixToolkit.Wpf 
//Then your 3D Models will automatically fits into viewport frame. 
+0

很好,你找到了一个解决方案,但为了这里的其他人的利益,你可能会考虑扩大这个答案 - 可能会添加一个简短的代码示例。 – sideshowbarker

+0

在视口中有一个ZoomExtentsWhenLoaded属性,这会导致视图在加载时自动执行此操作。 – henon