Helix Toolkit动画

时间:2013-07-24 13:13:15

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

我正试图用C#在我的WPF世界中为一条鱼制作动画 我正在使用helixtoolkit导入并显示对象

现在要创建的代码如下:

public MainViewModel()
{
   var worldGroup = new Model3DGroup();
   var fishGroup = new Model3DGroup();

   Model3D world = ModelImporter.Load(@".\Models\1.obj");
   Model3D fish = ModelImporter.Load(@".\Models\2.obj");

   worldGroup.Children.Add(world);
   fishGroup.Children.Add(fish);

   WorldModel = worldGroup;
   FishModel = fishGroup;
}

但是我不知道如何设置它的动画,我很乐意让它让鱼在由点定义的自定义路径中游泳(或者如果可能的话,只需从3ds max导入样条线)

是否可以使用3dsmax中的关键帧让鱼游泳 或者在模型本身中有一些动画(就像一个动画体)

1 个答案:

答案 0 :(得分:1)

能够使用以下XAML简单地为其设置动画:

<Window x:Class="_3D.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:HelixToolkit="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"
    Title="MainWindow" Height="350" Width="525">

<Grid>

    <HelixToolkit:HelixViewport3D ZoomExtentsWhenLoaded="True" Name="MyAnimatedObject">

        <HelixToolkit:SunLight />

        <ModelVisual3D Content="{Binding FishModel}">
            <ModelVisual3D.Transform>
                <TranslateTransform3D x:Name="MyTranslateTransform3D" OffsetX="0" OffsetY="0" OffsetZ="0" />
            </ModelVisual3D.Transform>
        </ModelVisual3D>
        <ModelVisual3D Content="{Binding WorldModel}" />

        <HelixToolkit:HelixViewport3D.Triggers>
            <EventTrigger RoutedEvent="HelixToolkit:HelixViewport3D.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetName="MyTranslateTransform3D"
                            Storyboard.TargetProperty="OffsetX"
                            To="10"
                            AutoReverse="True" RepeatBehavior="Forever" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </HelixToolkit:HelixViewport3D.Triggers>
    </HelixToolkit:HelixViewport3D>
</Grid>