如何在WPF/XAML中对MeshGeometry3D中的点进行动画处理?

3

你找到解决方案了吗? - tabby
我很抱歉,我从未找到解决方案。 - Lee Englestone
1个回答

0

可能不太好看

Xaml

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

CodeBehind

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接