是否可以围绕三个轴中的任何一个旋转Viewport3D?

时间:2018-02-02 23:13:54

标签: wpf wpf-animation viewport3d

我知道ModelVisual3D可以通过AxisAngleRotation3D围绕任意轴旋转,但是可以对包含9 ModelVisual3D s的Viewport3D执行相同操作,因此它们可以一起旋转好像它们是一个对象..例如,我可以使用ModelVisual3D执行此操作:

<Viewport3D.Triggers>
       <EventTrigger RoutedEvent="Viewport3D.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation 
                  Storyboard.TargetName="myVerticalRotation"
                  Storyboard.TargetProperty="Angle"
                  From="0" To="360" Duration="0:0:10"
                  RepeatBehavior="Forever" />
                            <DoubleAnimation 
                  Storyboard.TargetName="myHorizontalRotation"
                  Storyboard.TargetProperty="Angle"
                  From="0" To="360" Duration="0:0:9"
                  RepeatBehavior="Forever" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Viewport3D.Triggers>

但这假定Viewport3D只包含一个ModelVisual3D

1 个答案:

答案 0 :(得分:0)

是的,可以通过在GeometryModel3DModel3DGroup内的ModelUIElement3D内包含所有ContainerUIElement3D个对象来实现,然后我们就可以定义RotateTransform3D中的ContainerUIElement3D.Transform

 <ContainerUIElement3D>
                    <ModelUIElement3D>
                        <Model3DGroup>
                            <GeometryModel3D>...</GeometryModel3D>
                            <GeometryModel3D>...</GeometryModel3D>
                            <GeometryModel3D>...</GeometryModel3D>
                        </Model3DGroup>
                    </ModelUIElement3D>
                    <ContainerUIElement3D.Transform>
                      <Transform3DGroup>
                        <RotateTransform3D >
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D  x:Name="myHorizontalRotation" Angle="142.884" Axis="0 1 0"/>
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                     </Transform3DGroup>
                   </ContainerUIElement3D.Transform>
            </ContainerUIElement3D>