你好我正在研究展示3D模型的项目,我使用了螺旋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;
}
它的工作非常棒。问题是我想像汽车展厅一样360度旋转3D模型,但我不知道该怎么做。
答案 0 :(得分:0)
您可以使用 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;
}