<Window x:Class="SphereMaterials.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    FocusManager.FocusedElement="{Binding ElementName=materialSelector}"
    Title="SphereMaterials" Height="300" Width="300"
    >
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition />
    </Grid.RowDefinitions>
    <Grid.Resources>
      <DataTemplate DataType="{x:Type PerspectiveCamera}">
        <StackPanel Orientation="Horizontal">
          <TextBlock Text="Position: " />
          <TextBlock Text="{Binding Position}" />
          <TextBlock Text=", LookDirection: " />
          <TextBlock Text="{Binding LookDirection}" />
          <TextBlock Text=", UpDirection: " />
          <TextBlock Text="{Binding UpDirection}" />
          <TextBlock Text=", FieldOfView: " />
          <TextBlock Text="{Binding FieldOfView}" />
        </StackPanel>
      </DataTemplate>
      <DataTemplate DataType="{x:Type OrthographicCamera}">
        <StackPanel Orientation="Horizontal">
          <TextBlock Text="(Orthographic) Position: " />
          <TextBlock Text="{Binding Position}" />
          <TextBlock Text=", LookDirection: " />
          <TextBlock Text="{Binding LookDirection}" />
          <TextBlock Text=", UpDirection: " />
          <TextBlock Text="{Binding UpDirection}" />
          <TextBlock Text=", Width: " />
          <TextBlock Text="{Binding Width}" />
        </StackPanel>
      </DataTemplate>

      <x:Array x:Key="materials">
        <!-- Example 17-5. DiffuseMaterial -->

        <DiffuseMaterial Brush="#00FFFF" />

        <!-- End of Example 17-5. -->

        <!-- Example 17-6. SpecularMaterial -->

        <SpecularMaterial SpecularPower="30" Brush="White" />

        <!-- End of Example 17-6. -->

        <SpecularMaterial SpecularPower="5" Brush="White" />
        <SpecularMaterial SpecularPower="100" Brush="White" />

        
        <!-- Example 17-7. EmissiveMaterial -->

        <EmissiveMaterial Brush="#00FFFF" />

        <!-- End of Example 17-7. -->

        
        <!-- Example 17-8. Diffuse and specular materials in a MaterialGroup -->
        <MaterialGroup>
          <DiffuseMaterial Brush="#00FFFF" />
          <SpecularMaterial SpecularPower="30" Brush="White" />
        </MaterialGroup>

        <!-- End of Example 17-8. -->


        <!-- Example 17-9. MaterialGroup with EmissiveMaterial -->
        <MaterialGroup>
          <DiffuseMaterial Brush="#0000FF" />
          <SpecularMaterial SpecularPower="30" Brush="White" />
          <EmissiveMaterial>
            <EmissiveMaterial.Brush>
              <VisualBrush ViewboxUnits="Absolute" Viewbox="0,0,150,50">
                <VisualBrush.Transform>
                  <TransformGroup>
                    <TranslateTransform X="0.35" Y="0.5" />
                  </TransformGroup>
                </VisualBrush.Transform>
                <VisualBrush.Visual>
                  <Grid Width="150" Height="50">
                    <TextBlock FontSize="8" Text="Glow!" Foreground="#ff80a0"
                               HorizontalAlignment="Center">
                      <TextBlock.BitmapEffect>
                        <OuterGlowBitmapEffect GlowColor="#ff8000" GlowSize="1" />
                      </TextBlock.BitmapEffect>
                    </TextBlock>
                  </Grid>
                </VisualBrush.Visual>
              </VisualBrush>
            </EmissiveMaterial.Brush>
          </EmissiveMaterial>
        </MaterialGroup>

        <!-- End of Example 17-9. -->

      </x:Array>
    </Grid.Resources>

    <ListBox SelectedIndex="0" x:Name="materialSelector" DataContext="{StaticResource materials}" ItemsSource="{Binding Items}" />

    <CheckBox Grid.Row="1" x:Name="blackBackground" Content="_Black background" />

    <Rectangle Grid.Row="2">
      <Rectangle.Style>
        <Style>
          <Style.Triggers>
            <DataTrigger Binding="{Binding ElementName=blackBackground,Path=IsChecked}" Value="True">
              <Setter Property="Rectangle.Fill" Value="Black" />
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </Rectangle.Style>
    </Rectangle>
    <Viewbox Grid.Row="2" ClipToBounds="True">
      <Border BorderBrush="Black" BorderThickness="1" Margin="2">

        <Viewport3D ClipToBounds="True" Width="300" Height="200">
          <Viewport3D.Camera>
            <PerspectiveCamera Position="0,0,4" LookDirection="0,0,-1"
                   UpDirection="0,1,0" FieldOfView="45" />
          </Viewport3D.Camera>
          <Viewport3D.Resources>
            <ResourceDictionary>
              <GeometryModel3D x:Key="sphereModel"
                               Geometry="{StaticResource sphereMesh}"
                               Material="{Binding ElementName=materialSelector,Path=SelectedItem}" />

            </ResourceDictionary>
          </Viewport3D.Resources>

          <ModelVisual3D>
            <ModelVisual3D.Content>
              <Model3DGroup>
                <AmbientLight Color="#333333" />
                <DirectionalLight Color="#FFFFFF" Direction="0.0156948,-0.897322,-0.4410982" />
                <DirectionalLight Color="#FFFFFF" Direction="0.795738,0.0155303,-0.605442" />
              </Model3DGroup>
            </ModelVisual3D.Content>

            <ModelVisual3D Content="{StaticResource sphereModel}">
              <ModelVisual3D.Transform>
                <ScaleTransform3D ScaleY="-1" />
              </ModelVisual3D.Transform>
            </ModelVisual3D>

          </ModelVisual3D>
        </Viewport3D>

      </Border>
    </Viewbox>
  </Grid>
</Window>
