2017-03-27 121 views
0

你好我工作的项目,显示3D模型和我用螺旋3D工具包,所以我的XAML代码在这里:如何螺旋WPF自动旋转3D模型

<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

[这](http://stackoverflow.com/questions/36437858/helix-toolkit-rotate-3d模型)必须帮助你。只需点击按钮即可自动旋转计时器。并检查[this](http://stackoverflow.com/questions/28940267/rotate-an-object-in-helixviewport3d-in-a-wpf-app)。 – Shakra

回答

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; 
     }