如何使用HelixToolkit旋转3D模型?

时间:2019-02-26 16:12:49

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

在视觉工作室的WPF项目中,我需要一些旋转3D模型的帮助。我已经通过使用helix工具包导入了模型。但是我找不到任何有关如何在线旋转3D模型的示例。我发现了一些C#和xaml示例,但它们似乎主要是在旋转相机而不是旋转模型。

2 个答案:

答案 0 :(得分:0)

WPF 3D Rotation

为您的GeometryModel3D.Transform创建RotateTransform3D

答案 1 :(得分:0)

我发现使用矩阵进行转换特别有用。

在我的情况下,我注意到的是,通常情况下,如果您应用诸如RotateTransform3D之类的转换,然后使用模型的'.transform'属性应用另一个转换,它将覆盖最后一个转换。在大多数情况下,您希望将新转换应用于最后一个转换。

这就是我的轮换方式:

Vector3D axis = new Vector3D (1,0,0) //In case you want to rotate it about the x-axis
Matrix3D transformationMatrix = model.Content.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix.Rotate(new Quaternion(axis, angle)) //Makes a rotation transformation over this matrix
model.Content.Transform = new MatrixTransform3D(transformationMatrix); //Applies the transformation to your model

别忘了,如果您希望模型在其自身的中心旋转,而不是'.Rotate',请使用'.RotateAt',如下所示:

transformationMatrix.RotateAt(new Quaternion(axis, angle), modelCenter); //modelCenter is the Point3D variable indicating the center