■ ParallelTimeline 엘리먼트 사용하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainWindow.xaml

 

 

<Window x:Class="TestProject.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="800"

    Height="600"

    Title="ParallelTimeline 엘리먼트 사용하기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Window.Resources>

        <DiffuseMaterial x:Key="DiffuseMaterialKey"

            Brush="Yellow" />

        <DiffuseMaterial x:Key="BackDiffuseMaterialKey"

            Brush="Red" />

        <GeometryModel3D x:Key="SideGeometryModel3DKey"

            Material="{StaticResource DiffuseMaterialKey}"

            BackMaterial="{StaticResource BackDiffuseMaterialKey}" >

            <GeometryModel3D.Geometry>

                <MeshGeometry3D

                    Positions="-1 0 1, -1 0 -1, 1 0 -1, 1 0 1"

                    TriangleIndices="0 1 2, 0 2 3" />

            </GeometryModel3D.Geometry>

        </GeometryModel3D>

    </Window.Resources>

    <Viewport3D>

        <ModelVisual3D>

            <!-- 상자 아래쪽 면 -->

            <ModelVisual3D Content="{StaticResource SideGeometryModel3DKey}" />

            <!-- 상자 왼쪽 면 -->

            <ModelVisual3D Content="{StaticResource SideGeometryModel3DKey}">

                <ModelVisual3D.Transform>

                    <Transform3DGroup>

                        <TranslateTransform3D OffsetX="-2" />

                        <RotateTransform3D CenterX="-1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D x:Name="boxLeftAxisAngleRotation3D"

                                    Axis="0 0 -1" />

                            </RotateTransform3D.Rotation>

                        </RotateTransform3D>

                    </Transform3DGroup>

                </ModelVisual3D.Transform>

            </ModelVisual3D>

            <!-- 상자 오른쪽 면 -->

            <ModelVisual3D Content="{StaticResource SideGeometryModel3DKey}">

                <ModelVisual3D.Transform>

                    <Transform3DGroup>

                        <TranslateTransform3D OffsetX="2" />

                        <RotateTransform3D CenterX="1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D x:Name="boxRightAxisAngleRotation3D"

                                    Axis="0 0 1" />

                            </RotateTransform3D.Rotation>

                        </RotateTransform3D>

                    </Transform3DGroup>

                </ModelVisual3D.Transform>

            </ModelVisual3D>

            <!-- 상자 전면 -->

            <ModelVisual3D Content="{StaticResource SideGeometryModel3DKey}">

                <ModelVisual3D.Transform>

                    <Transform3DGroup>

                        <TranslateTransform3D OffsetZ="2" />

                        <RotateTransform3D CenterZ="1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D x:Name="boxFrontAxisAngleRotation3D"

                                    Axis="-1 0 0" />

                            </RotateTransform3D.Rotation>

                        </RotateTransform3D>

                    </Transform3DGroup>

                </ModelVisual3D.Transform>

            </ModelVisual3D>

            <!-- 상자 후면 -->

            <ModelVisual3D Content="{StaticResource SideGeometryModel3DKey}">

                <ModelVisual3D.Transform>

                    <Transform3DGroup>

                        <TranslateTransform3D OffsetZ="-2" />

                        <RotateTransform3D CenterZ="-1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D x:Name="boxRearAxisAngleRotation3D"

                                    Axis="1 0 0" />

                            </RotateTransform3D.Rotation>

                        </RotateTransform3D>

                    </Transform3DGroup>

                </ModelVisual3D.Transform>

            </ModelVisual3D>

            <!-- 상자 위쪽 면 -->

            <ModelVisual3D Content="{StaticResource SideGeometryModel3DKey}">

                <ModelVisual3D.Transform>

                    <Transform3DGroup>

                        <RotateTransform3D CenterY="-2" CenterZ="1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D

                                    Axis="1 0 0"

                                    Angle="90" />

                            </RotateTransform3D.Rotation>

                        </RotateTransform3D>

                        <RotateTransform3D CenterZ="1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D x:Name="boxTopAxisAngleRotation3D1"

                                    Axis="-1 0 0" />

                            </RotateTransform3D.Rotation>

                        </RotateTransform3D>

                        <RotateTransform3D CenterY="2" CenterZ="1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D x:Name="boxTopAxisAngleRotation3D2"

                                    Axis="-1 0 0" />

                            </RotateTransform3D.Rotation>

                        </RotateTransform3D>

                        <RotateTransform3D CenterY="2" CenterZ="-1">

                            <RotateTransform3D.Rotation>

                                <AxisAngleRotation3D x:Name="boxTopAxisAngleRotation3D3"

                                    Axis="-1 0 0" />

                            </RotateTransform3D.Rotation>

                       </RotateTransform3D>

                    </Transform3DGroup>

                </ModelVisual3D.Transform>

            </ModelVisual3D>

            <ModelVisual3D.Content>

                <!-- 상자 내부 정육면체 -->

                <GeometryModel3D>

                    <GeometryModel3D.Geometry>

                        <MeshGeometry3D

                            Positions="-0.5  0.5  0.5,  0.5  0.5  0.5,

                                       -0.5 -0.5  0.5,  0.5 -0.5  0.5,

                                        0.5  0.5 -0.5, -0.5  0.5 -0.5,

                                        0.5 -0.5 -0.5, -0.5 -0.5 -0.5,

                                       -0.5  0.5 -0.5, -0.5  0.5  0.5,

                                       -0.5 -0.5 -0.5, -0.5 -0.5  0.5,

                                        0.5  0.5  0.5,  0.5  0.5 -0.5,

                                        0.5 -0.5  0.5,  0.5 -0.5 -0.5,

                                       -0.5  0.5 -0.5,  0.5  0.5 -0.5,

                                       -0.5  0.5  0.5,  0.5  0.5  0.5,

                                        0.5 -0.5 -0.5, -0.5 -0.5 -0.5,

                                        0.5 -0.5  0.5, -0.5 -0.5  0.5"

                           TriangleIndices=" 0  2  1,  1  2  3

                                             4  6  5,  5  6  7,

                                             8 10  9,  9 10 11,

                                            12 14 13, 13 14 15

                                            16 18 17, 17 18 19

                                            20 22 21, 21 22 23" />

                    </GeometryModel3D.Geometry>

                    <GeometryModel3D.Material>

                        <DiffuseMaterial Brush="Gold" />

                    </GeometryModel3D.Material>

                    <GeometryModel3D.Transform>

                        <TranslateTransform3D x:Name="cubeTranslateTransform3D"

                            OffsetY="-100"

                            OffsetZ="0" />

                    </GeometryModel3D.Transform>

                </GeometryModel3D>

            </ModelVisual3D.Content>

            <ModelVisual3D.Transform>

                <RotateTransform3D>

                    <RotateTransform3D.Rotation>

                        <AxisAngleRotation3D x:Name="modelAxisAngleRotation3D"

                            Axis="0 1 0"

                            Angle="30" />

                    </RotateTransform3D.Rotation>

                </RotateTransform3D>

            </ModelVisual3D.Transform>

        </ModelVisual3D>

        <ModelVisual3D>

            <ModelVisual3D.Content>

                <Model3DGroup>

                    <AmbientLight Color="#606060" />

                    <DirectionalLight

                        Color="#a0a0a0"

                        Direction="1 -3 -2" />

                </Model3DGroup>

            </ModelVisual3D.Content>

        </ModelVisual3D>

        <Viewport3D.Camera>

            <PerspectiveCamera

                Position="0 6 20"

                LookDirection="0 -2 -10"

                UpDirection="0 1 0"

                FieldOfView="30" />

        </Viewport3D.Camera>

    </Viewport3D>

    <Window.Triggers>

        <EventTrigger RoutedEvent="Window.Loaded">

            <BeginStoryboard>

                <Storyboard

                    SpeedRatio="1.5"

                    RepeatBehavior="Forever">

                    <DoubleAnimation

                        Storyboard.TargetName="modelAxisAngleRotation3D"

                        Storyboard.TargetProperty="Angle"

                        From="0"

                        To="360"

                        Duration="0:0:20"

                        RepeatBehavior="8x" />

                    <ParallelTimeline

                        Duration="0:1:20"

                        AutoReverse="True">

                        <DoubleAnimation

                            Storyboard.TargetName="boxLeftAxisAngleRotation3D"

                            Storyboard.TargetProperty="Angle"

                            From="0"

                            To="90"

                            Duration="0:0:30" />

                        <DoubleAnimation

                            Storyboard.TargetName="boxRightAxisAngleRotation3D"

                            Storyboard.TargetProperty="Angle"

                            From="0"

                            To="90"

                            Duration="0:0:30" />

                        <DoubleAnimation

                            Storyboard.TargetName="boxFrontAxisAngleRotation3D"

                            Storyboard.TargetProperty="Angle"

                            From="0"

                            To="90"

                            Duration="0:0:30" />

                        <DoubleAnimation

                            Storyboard.TargetName="boxRearAxisAngleRotation3D"

                            Storyboard.TargetProperty="Angle"

                            From="0"

                            To="90"

                            Duration="0:0:30" />

                        <DoubleAnimation

                            Storyboard.TargetName="boxTopAxisAngleRotation3D1"

                            Storyboard.TargetProperty="Angle"

                            From="0"

                            To="90"

                            Duration="0:0:30" />

                        <DoubleAnimation

                            Storyboard.TargetName="boxTopAxisAngleRotation3D2"

                            Storyboard.TargetProperty="Angle"

                            BeginTime="0:0:30"

                            From="0"

                            To="180"

                            Duration="0:0:15" />

                        <DoubleAnimation

                            Storyboard.TargetName="boxTopAxisAngleRotation3D3"

                            Storyboard.TargetProperty="Angle"

                            BeginTime="0:0:45"

                            From="0"

                            To="90"

                            Duration="0:0:15" />

                        <DoubleAnimation

                            Storyboard.TargetName="cubeTranslateTransform3D"

                            Storyboard.TargetProperty="OffsetY"

                            BeginTime="0:0:45"

                            From="0.5"

                            To="6"

                            Duration="0:0:35" />

                    </ParallelTimeline>

               </Storyboard>

            </BeginStoryboard>

        </EventTrigger>

    </Window.Triggers>

</Window>

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요