2017-03-27 33 views
0

안녕하세요 나는 3D 모델을 보여줄 프로젝트를 진행하고 내가 그래서 XAML의 여기 코드가 나선 3D 툴킷을 사용나선 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; 
    } 

잘 작동합니다. 문제는 자동차 쇼룸처럼 3D 모델을 360도 회전시키고 싶지만 무엇을해야할지 모르겠다는 것입니다.

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