<?xml version="1.0" encoding="utf-8"?>
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <Page.Resources>
    <MeshGeometry3D x:Key="mesh1"
                    TriangleIndices="0,1,2 3,4,5"
                    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 "/>
    <MeshGeometry3D x:Key="mesh2"
                    TriangleIndices="0,1,2 3,4,5"
                    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 "/>
    <MeshGeometry3D x:Key="mesh3"
                    TriangleIndices="0,1,2 3,4,5"
                    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 "/>
    <MeshGeometry3D x:Key="mesh4"
                    TriangleIndices="0,1,2 3,4,5"
                    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 "/>
    <MeshGeometry3D x:Key="mesh5"
                    TriangleIndices="0,1,2 3,4,5"
                    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 "/>
    <MeshGeometry3D x:Key="mesh6"
                    TriangleIndices="1,2,0 3,0,2"
                    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"/>
    <Storyboard x:Key="SpinCube"
                RepeatBehavior="Forever">
      <DoubleAnimation BeginTime="00:00:00"
                       Duration="00:00:02"
                       Storyboard.TargetName="leftRotate"
                       Storyboard.TargetProperty="Angle"
                       From="0"
                       To="360"/>
    </Storyboard>
    <Storyboard x:Key="SpinCamera"
                RepeatBehavior="Forever">
      <Point3DAnimation BeginTime="00:00:00"
                        Duration="00:00:1"
                        Storyboard.TargetName="Camera"
                        Storyboard.TargetProperty="Position"
                        From="0,0,15"
                        To="0,0,5"
                        RepeatBehavior="Forever"
                        AutoReverse="True"/>
    </Storyboard>
    <Model3DGroup x:Key="myGroup">
      <GeometryModel3D Geometry="{StaticResource mesh1}">
        <GeometryModel3D.Material>
          <DiffuseMaterial Brush="#FF222222" />
        </GeometryModel3D.Material>
      </GeometryModel3D>
      <GeometryModel3D Geometry="{StaticResource mesh2}">
        <GeometryModel3D.Material>
          <DiffuseMaterial Brush="#FF444444" />
        </GeometryModel3D.Material>
      </GeometryModel3D>
      <GeometryModel3D Geometry="{StaticResource mesh3}">
        <GeometryModel3D.Material>
          <DiffuseMaterial Brush="#FF666666" />
        </GeometryModel3D.Material>
      </GeometryModel3D>
      <GeometryModel3D Geometry="{StaticResource mesh4}">
        <GeometryModel3D.Material>
          <DiffuseMaterial Brush="#FF888888" />
        </GeometryModel3D.Material>
      </GeometryModel3D>
      <GeometryModel3D Geometry="{StaticResource mesh5}">
        <GeometryModel3D.Material>
          <DiffuseMaterial Brush="#FFAAAAAA" />
        </GeometryModel3D.Material>
      </GeometryModel3D>
      <GeometryModel3D Geometry="{StaticResource mesh6}">
        <GeometryModel3D.Material>
          <DiffuseMaterial Brush="#FFCCCCCC" />
        </GeometryModel3D.Material>
      </GeometryModel3D>
      <AmbientLight Color="#FFFFFFFF"/>
    </Model3DGroup>
  </Page.Resources>
  <Page.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
      <BeginStoryboard Storyboard="{StaticResource SpinCube}"/>
      <BeginStoryboard Storyboard="{StaticResource SpinCamera}"/>
    </EventTrigger>
  </Page.Triggers>
  <DockPanel Background="Black">
    <Viewport3D HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch">
      <Viewport3D.Camera>
        <PerspectiveCamera x:Name="Camera"
                           FieldOfView="45"
                           FarPlaneDistance="100"
                           LookDirection="0,0,-5"
                           Position="0,0,15"
                           NearPlaneDistance="0.1"
                           UpDirection="0,1,0">
        </PerspectiveCamera>
      </Viewport3D.Camera>
      <ModelUIElement3D Model="{StaticResource myGroup}">
        <ModelUIElement3D.Transform>
          <Transform3DGroup>
            <ScaleTransform3D ScaleX="1"
                              ScaleY="1"
                              ScaleZ="1"/>
            <RotateTransform3D>
              <RotateTransform3D.Rotation>
                <AxisAngleRotation3D x:Name="leftRotate"
                                     Axis="1,1,1"
                                     Angle="0" />
              </RotateTransform3D.Rotation>

            </RotateTransform3D>
          </Transform3DGroup>
        </ModelUIElement3D.Transform>
      </ModelUIElement3D>
    </Viewport3D>
  </DockPanel>
</Page>

