[英]How to rotate 3D model automatically in helix WPF
您好,我正在研究顯示3D模型的項目,並且我使用了helix 3D工具包,所以這里有xaml代碼:
<h:HelixViewport3D Name="hlx" ZoomExtentsWhenLoaded="True" RotateAroundMouseDownPoint="False" ShowViewCube="False" Opacity="0.8" Grid.Column="4" Grid.ColumnSpan="2" Grid.Row="4" Grid.RowSpan="3">
<h:DefaultLights/>
</h:HelixViewport3D>
和這里的C#代碼:
void C()
{
ModelVisual3D model = new ModelVisual3D();
model.Content = Display3d(@"D:\tests for projects\Em organic compounds\Em organic compounds\Car.3DS");
hlx.Children.Add(model);
}
private Model3D Display3d(string mdl)
{
Model3D device = null;
try
{
hlx.RotateGesture = new MouseGesture(MouseAction.LeftClick);
ModelImporter import = new ModelImporter();
device = import.Load(mdl);
}
catch (Exception e)
{
MessageBox.Show("Exception Error : " + e.StackTrace);
}
return device;
}
很好。 問題是我想像汽車展示廳一樣將3D模型旋轉360度,但我不知道該怎么辦。
您可以使用RotateManipulator控件,該控件允許用戶在特定軸上旋轉模型
void C()
{
ModelVisual3D model = new ModelVisual3D();
model.Content = Display3d(@"D:\tests for projects\Em organic compounds\Em organic compounds\Car.3DS");
RotateManipulator manipulator = new RotateManipulator()
{
//rotate on X axis
Axis = new Vector3D(1, 0, 0),
Diameter = 5 //
};
Binding b = new Binding()
{
ElementName = nameof(model),
Path = new PropertyPath("Transform")
};
BindingOperations.SetBinding(manipulator, RotateManipulator.TransformProperty, b);
BindingOperations.SetBinding(manipulator, RotateManipulator.TargetTransformProperty, b);
view1.Children.Add(manipulator);
view1.Children.Add(model);
}
private Model3D Display3d(string mdl)
{
Model3D device = null;
try
{
// view1.RotateGesture = new MouseGesture(MouseAction.LeftClick);
ModelImporter import = new ModelImporter();
device = import.Load(mdl);
}
catch (Exception e)
{
MessageBox.Show("Exception Error : " + e.StackTrace);
}
return device;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.