如何将 BeginAnimation 添加到 WPF Viewport3D?
我正在尝试在 Viewport3D 中旋转图像,但看不到要将动画应用到哪个对象。
这在代码中有效
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 100;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
Button1.BeginAnimation(Button.HeightProperty, da);
并且这也有效
RotateTransform3D myRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 30));
Model.Transform = myRotateTransform;
那么为什么我不能这样做呢?
Rotation3DAnimation r3D = new Rotation3DAnimation();
r3D.From = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0);
r3D.To = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 45);
r3D.Duration = new Duration(TimeSpan.FromSeconds(10));
Model.BeginAnimation(ModelVisual3D.TransformProperty, r3D, HandoffBehavior.SnapshotAndReplace);
我在 Model.BeginAnimation 行上收到错误。 我尝试了许多对象而不是 ModelVisual3D,但每次都会遇到不同的错误。 我应该使用什么对象类型?
感谢您的帮助 理查德·
XAML
<ModelVisual3D x:Name="ModelContainer">
<ModelVisual3D.Content>
<GeometryModel3D x:Name="Model" d:Bounds="-37.2388059701493,-10,0,74.4776119402985,20,0">
<GeometryModel3D.Geometry>
<MeshGeometry3D Normals="0,0,1 ..." />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush ImageSource="pack://siteoforigin:,,,/Staff-4.tif" Stretch="Fill"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
<ModelVisual3D.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</ModelVisual3D.Transform>
</ModelVisual3D>
<ModelVisual3D x:Name="AmbientContainer">
<ModelVisual3D.Content>
<AmbientLight x:Name="Ambient" Color="Gray"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="DirectionalContainer">
<ModelVisual3D.Content>
<DirectionalLight x:Name="Directional" Color="#FF7F7F7F" Direction="0,0,-1">
<DirectionalLight.Transform>
<TranslateTransform3D OffsetZ="3" OffsetX="0" OffsetY="0"/>
</DirectionalLight.Transform>
</DirectionalLight>
</ModelVisual3D.Content>
</ModelVisual3D>
I'm trying to rotate an image in a Viewport3D but I can't see which object to apply the animation to.
This works in code
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 100;
da.Duration = new Duration(TimeSpan.FromSeconds(1));
Button1.BeginAnimation(Button.HeightProperty, da);
and This also works
RotateTransform3D myRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 30));
Model.Transform = myRotateTransform;
So why can't I do this?
Rotation3DAnimation r3D = new Rotation3DAnimation();
r3D.From = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0);
r3D.To = new AxisAngleRotation3D(new Vector3D(1, 0, 0), 45);
r3D.Duration = new Duration(TimeSpan.FromSeconds(10));
Model.BeginAnimation(ModelVisual3D.TransformProperty, r3D, HandoffBehavior.SnapshotAndReplace);
I get an error on the Model.BeginAnimation line.
I've tried a number of objects instead of ModelVisual3D but I get different errors each time.
What object type should I be using?
Thanks for any help
Richard
XAML
<ModelVisual3D x:Name="ModelContainer">
<ModelVisual3D.Content>
<GeometryModel3D x:Name="Model" d:Bounds="-37.2388059701493,-10,0,74.4776119402985,20,0">
<GeometryModel3D.Geometry>
<MeshGeometry3D Normals="0,0,1 ..." />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush ImageSource="pack://siteoforigin:,,,/Staff-4.tif" Stretch="Fill"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
<ModelVisual3D.Transform>
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="0"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
</ModelVisual3D.Transform>
</ModelVisual3D>
<ModelVisual3D x:Name="AmbientContainer">
<ModelVisual3D.Content>
<AmbientLight x:Name="Ambient" Color="Gray"/>
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="DirectionalContainer">
<ModelVisual3D.Content>
<DirectionalLight x:Name="Directional" Color="#FF7F7F7F" Direction="0,0,-1">
<DirectionalLight.Transform>
<TranslateTransform3D OffsetZ="3" OffsetX="0" OffsetY="0"/>
</DirectionalLight.Transform>
</DirectionalLight>
</ModelVisual3D.Content>
</ModelVisual3D>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是您不能在动画中使用 AxisAngleRotation3D。
您必须将其分解为矢量和角度的两个组成部分,并独立地对它们进行动画处理。
The answer is that you can't use the AxisAngleRotation3D in an animation.
You have to break apart it's 2 components of vector and angle and animate them independently.