2017-03-27 72 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; 
     }