<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="uiMesh"
      TriangleIndices="0,1,2 3,4,5"
      Positions="-1,-1,2 1,-1,2 1,1,2 1,1,2 -1,1,2 -1,-1,2 "
      TextureCoordinates="0,1 1,1 1,0 1,0, 0,0 0,1" />

    <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="leftSpin"
      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="rightSpin"
      RepeatBehavior="Forever">
      <DoubleAnimation
        BeginTime="00:00:00"
        Duration="00:00:02"
        Storyboard.TargetName="rightRotate"
        Storyboard.TargetProperty="Angle"
        From="0"
        To="360" />
    </Storyboard>
    <Storyboard
      x:Key="uiSpin"
      RepeatBehavior="Forever">
      <DoubleAnimation
        BeginTime="00:00:00"
        Duration="00:00:5"
        Storyboard.TargetName="uiRotate"
        Storyboard.TargetProperty="Angle"
        From="-45"
        To="+45"
         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 leftSpin}" />
      <BeginStoryboard
        Storyboard="{StaticResource rightSpin}" />
      <BeginStoryboard
        Storyboard="{StaticResource uiSpin}" />
    </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"
          NearPlaneDistance="0.1"
          Position="0,0,15"
          UpDirection="0,1,0" />
      </Viewport3D.Camera>
      <ContainerUIElement3D>
        <ModelUIElement3D
          x:Name="leftCube"
          Model="{StaticResource myGroup}">
          <ModelUIElement3D.Transform>
            <Transform3DGroup>
              <TranslateTransform3D
                OffsetX="-1"
                OffsetY="0"
                OffsetZ="0" />
              <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>
        <ModelUIElement3D
          x:Name="rightCube"
          Model="{StaticResource myGroup}">
          <ModelUIElement3D.Transform>
            <Transform3DGroup>
              <TranslateTransform3D
                OffsetX="1"
                OffsetY="0"
                OffsetZ="0" />
              <ScaleTransform3D
                ScaleX="1"
                ScaleY="1"
                ScaleZ="1" />
              <RotateTransform3D>
                <RotateTransform3D.Rotation>
                  <AxisAngleRotation3D
                    x:Name="rightRotate"
                    Axis="1,1,1"
                    Angle="0" />
                </RotateTransform3D.Rotation>

              </RotateTransform3D>
            </Transform3DGroup>
          </ModelUIElement3D.Transform>
        </ModelUIElement3D>
        <Viewport2DVisual3D
          Geometry="{StaticResource uiMesh}">
          <Viewport2DVisual3D.Transform>
            <RotateTransform3D>
              <RotateTransform3D.Rotation>
                <AxisAngleRotation3D
                  x:Name="uiRotate"
                  Axis="0,1,0"
                  Angle="0" />
              </RotateTransform3D.Rotation>
            </RotateTransform3D>
          </Viewport2DVisual3D.Transform>
          <Viewport2DVisual3D.Material>
            <DiffuseMaterial
              Viewport2DVisual3D.IsVisualHostMaterial="true"
              Color="White"
              Brush="Blue" />
          </Viewport2DVisual3D.Material>
          <Viewport2DVisual3D.Visual>
            <Grid Opacity="0.9">
              <Grid.RowDefinitions>
               <RowDefinition/>
               <RowDefinition/>
              </Grid.RowDefinitions>
              <Button Content="Click Me" Margin="2"/>
              <TextBox Text="Edit Me" Margin="2" Grid.Row="1"/>
            </Grid>
            
          </Viewport2DVisual3D.Visual>
        </Viewport2DVisual3D>
      </ContainerUIElement3D>
    </Viewport3D>
  </DockPanel>
</Page>

