gpt4 book ai didi

wpf - 如何在 WPF/XAML 中为 MeshGeometry3D 中的点设置动画?

转载 作者:行者123 更新时间:2023-12-04 19:41:58 27 4
gpt4 key购买 nike

是否可以为 MeshGeometry3D 中的点设置动画?在 XAML 或 C# 代码中。

我似乎找不到一种方法来随着时间的推移为点的 X、Y、Z 位置设置动画。有什么想法吗?

这可能有帮助.. WPF and 3D how do you change a single position point in 3D space?

最佳答案

也许不漂亮

XAML

<Viewport3D>
<ModelVisual3D x:Name="VisualHost"/>
</Viewport3D>

代码隐藏

public partial class MyUserControl : UserControl
{
#region TargetZ Property
public static readonly DependencyProperty TargetZProperty =
DependencyProperty.RegisterAttached("TargetZ", typeof(double), typeof(MyUserControl), new PropertyMetadata(TargetZ_Changed));

private static void TargetZ_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var positions = ((MeshGeometry3D)((GeometryModel3D)d).Geometry).Positions;
var point = positions[0];
positions[0] = new Point3D(point.X, point.Y, point.Z + (double)e.NewValue);
}

public void SetTargetZ(GeometryModel3D d, double value)
{
d.SetValue(TargetZProperty, value);
}
public double GetTargetZ(GeometryModel3D d)
{
return (double)d.GetValue(TargetZProperty);
}
#endregion

public MyUserControl()
{
InitializeComponent();
}

private void SetNewZ(double newValue)
{
var animationTime = TimeSpan.FromSeconds(1);

var model = (GeometryModel3D)VisualHost.Content;

var zAnimation = new DoubleAnimation(newValue, animationTime) { FillBehavior = FillBehavior.HoldEnd };
model.BeginAnimation(TargetZProperty, zAnimation);
}
}

关于wpf - 如何在 WPF/XAML 中为 MeshGeometry3D 中的点设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32012680/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com