mikeo_410


 スペキュラ、発光のサンプル

  「スペキュラ、発光」がありますが、リンク先がなくなっていました。
  代わりになるようにスクリプトを載せておきます。

  このページのサンプルは、HTMLの iframe で、XAMLスクリプトをホストしたものです。
  Silverlightには3Dがありませんが、Loose XAMLでは、WPFと同じ記述が可能です。
  ただし、Loose XAMLは常に表示されるわけではなく、ブラウザやインターネットオプションによって表示されないこともあります。
  Loose XAMLは、WPFと同じ仕組みで表示され、Viewport3DなどSilverlightにない機能も有効です。

 

  この例は、スライダやコンボボックスで、SpecularPower などを変化させて見た目の変化を確認しようとするものです。

  この例は、XAMLスクリプトファイルだけでできています。Silverlightアプリケーションではありません。
  球を描く Geometry(sphere.xaml) は大きなファイルなので、概略だけを示します。このファイルは、POV-Ray で作成したものです。
  このページでは、HTML中に以下の記述をして表示しています。

  1. <IFRAME height=300 
  2.   src="http://.../iframe_sphere2.xaml" width=480>
  3. </IFRAME>

  sphere.xamlの概要

  1. <ResourceDictionary
  2.   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  3.   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  4.     <MeshGeometry3D x:Key="_sphere"
  5.      Positions="-0.000001 -0.000001 -1.0 (座標が続く...)"
  6.      TextureCoordinates=""
  7.      TriangleIndices="0 1 2 3 (連番が続く...)"
  8.     />
  9. </ResourceDictionary>

  iframe_sphere2.xaml

  1. <Page ShowsNavigationUI="False"
  2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  4.     <!--リソース-->
  5.     <Page.Resources>
  6.         <ResourceDictionary>
  7.             <ResourceDictionary.MergedDictionaries>
  8.                 <!--ジオメトリを別のXAMLファイルから読み込む-->
  9.                 <ResourceDictionary Source="sphere.xaml"/>
  10.             </ResourceDictionary.MergedDictionaries>
  11.         </ResourceDictionary>
  12.     </Page.Resources>
  13.     <Grid Background="OldLace">
  14.         <Grid.ColumnDefinitions>
  15.             <ColumnDefinition Width="240"/>
  16.             <ColumnDefinition Width="200"/>
  17.         </Grid.ColumnDefinitions>
  18.         <Viewport3D x:Name="viewport1" Grid.Column="0" Height="200" >
  19.             <Viewport3D.Camera>
  20.                 <!--カメラ-->
  21.                 <PerspectiveCamera 
  22.                      LookDirection="-1, -1, -1" Position="2,2,2" FieldOfView="45">
  23.                 </PerspectiveCamera>
  24.             </Viewport3D.Camera>
  25.             <ModelVisual3D>
  26.                 <ModelVisual3D.Content>
  27.                     <!--ライト-->
  28.                     <DirectionalLight Color="White" Direction="1,-1,-1" />
  29.                 </ModelVisual3D.Content>
  30.             </ModelVisual3D>
  31.             <ModelVisual3D>
  32.                 <ModelVisual3D.Content>
  33.                     <!--リソースで定義したジオメトリを使用-->
  34.                     <GeometryModel3D Geometry="{StaticResource _sphere}">
  35.                         <GeometryModel3D.Material>
  36.                             <MaterialGroup>
  37.                                 <!--物体の色-->
  38.                                 <DiffuseMaterial Brush="Yellow"/>
  39.                                 <!--ハイライト-->
  40.                                 <SpecularMaterial 
  41.                                     Brush="{Binding ElementName=cmb_specular_color, Path=Text}" 
  42.                                     SpecularPower="{Binding ElementName=slider1, Path=Value}"/>
  43.                                 <!--物体の発光-->
  44.                                 <EmissiveMaterial 
  45.                                     Brush="{Binding ElementName=cmb_emissive_color,Path=Text}"/>
  46.                             </MaterialGroup>
  47.                         </GeometryModel3D.Material>
  48.                     </GeometryModel3D>
  49.                 </ModelVisual3D.Content>
  50.             </ModelVisual3D>
  51.         </Viewport3D>
  52.         <StackPanel Grid.Column="1">
  53.             <StackPanel Margin="2,4,0,4">
  54.                 <StackPanel Orientation="Horizontal" Background="AliceBlue">
  55.                     <TextBlock Text="SpecularPower :" Foreground="Maroon"/>
  56.                     <TextBlock Text="{Binding ElementName=slider1, Path=Value}"/>
  57.                 </StackPanel>
  58.                 <Slider Name="slider1"  Minimum="2" Maximum="100" Value="10" Ticks="0.1"
  59.                         Background="AliceBlue" Margin="0,0,0,0"/>
  60.             </StackPanel>
  61.             <StackPanel Margin="2,0,4,4" Background="AliceBlue">
  62.                 <StackPanel Orientation="Horizontal">
  63.                     <TextBlock Text="Specular Color :" Foreground="Maroon"/>
  64.                     <TextBlock Text="{Binding ElementName=cmb_specular_color, Path=Text}"/>
  65.                 </StackPanel>
  66.                 <ComboBox Name="cmb_specular_color" SelectedIndex="0">
  67.                     <ComboBox.Items>
  68.                         <Color A="255" R="128" G="128" B="128"/>
  69.                         <Color A="255" R="64" G="64" B="64"/>
  70.                         <Color A="255" R="32" G="32" B="32"/>
  71.                         <Color A="255" R="255" G="0" B="0"/>
  72.                         <Color A="255" R="0" G="255" B="0"/>
  73.                         <Color A="255" R="0" G="0" B="255"/>
  74.                     </ComboBox.Items>
  75.                 </ComboBox>
  76.             </StackPanel>
  77.             <StackPanel Margin="2,4,4,4" Background="PeachPuff">
  78.                 <StackPanel Orientation="Horizontal">
  79.                     <TextBlock Text="EmissiveMaterial Color :" Foreground="Maroon"/>
  80.                     <TextBlock Text="{Binding ElementName=cmb_emissive_color, Path=Text}"/>
  81.                 </StackPanel>
  82.                 <ComboBox Name="cmb_emissive_color" SelectedIndex="0">
  83.                     <ComboBox.Items>
  84.                         <Color A="255" R="128" G="128" B="128"/>
  85.                         <Color A="255" R="64" G="64" B="64"/>
  86.                         <Color A="255" R="32" G="32" B="32"/>
  87.                         <Color A="255" R="255" G="0" B="0"/>
  88.                         <Color A="255" R="0" G="255" B="0"/>
  89.                         <Color A="255" R="0" G="0" B="255"/>
  90.                     </ComboBox.Items>
  91.                 </ComboBox>
  92.             </StackPanel>
  93.         </StackPanel>
  94.     </Grid>
  95. </Page>

mikeo_410@hotmail.com