【问题标题】:How to rotate 3D model automatically in helix WPF如何在螺旋 WPF 中自动旋转 3D 模型
【发布时间】:2017-04-12 06:32:16
【问题描述】:

您好,我正在开发显示 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 度,但我不知道该怎么做。

【问题讨论】:

  • This 必须帮助您。只需在计时器上自动旋转,而不是在按钮单击时。并检查this

标签: c# wpf 3d helix-3d-toolkit


【解决方案1】:

您可以使用 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;
        }

【讨论】:

    猜你喜欢
    • 2022-10-15
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 2015-07-09
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多