<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
    <Grid.RowDefinitions>
      <RowDefinition Height="4*"/>
      <RowDefinition/>
    </Grid.RowDefinitions>
    <!-- TODO I used a video for this but here I've replaced it with a 3D cube -->
    <!-- <MediaElement Margin="5" Source=""
      HorizontalAlignment="Stretch" Stretch="Fill">
    </MediaElement> -->
    <StackPanel x:Name="myStackPanel">
    <StackPanel.BitmapEffect>
     <BlurBitmapEffect Radius="{Binding ElementName=mySlider,Path=Value}"/>
    </StackPanel.BitmapEffect>
          <StackPanel.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>
      </StackPanel.Resources>
      <StackPanel.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
          <BeginStoryboard Storyboard="{StaticResource SpinCube}"/>
          <BeginStoryboard Storyboard="{StaticResource SpinCamera}"/>
        </EventTrigger>
      </StackPanel.Triggers>
      <Grid Background="Black"
            Height="192"
            Margin="10">
        <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>
      </Grid>
    </StackPanel>
        
    <Slider x:Name="mySlider" Grid.Row="1" Margin="10" Minimum="0" Maximum="10" FontSize="24"
      Width="192"/>
      
  </Grid>
</Page>
