[英]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.