スペキュラ、発光のサンプル
「スペキュラ、発光」がありますが、リンク先がなくなっていました。
代わりになるようにスクリプトを載せておきます。
このページのサンプルは、HTMLの iframe で、XAMLスクリプトをホストしたものです。
Silverlightには3Dがありませんが、Loose XAMLでは、WPFと同じ記述が可能です。
ただし、Loose XAMLは常に表示されるわけではなく、ブラウザやインターネットオプションによって表示されないこともあります。
Loose XAMLは、WPFと同じ仕組みで表示され、Viewport3DなどSilverlightにない機能も有効です。
この例は、スライダやコンボボックスで、SpecularPower などを変化させて見た目の変化を確認しようとするものです。
この例は、XAMLスクリプトファイルだけでできています。Silverlightアプリケーションではありません。
球を描く Geometry(sphere.xaml) は大きなファイルなので、概略だけを示します。このファイルは、POV-Ray で作成したものです。
このページでは、HTML中に以下の記述をして表示しています。
- <IFRAME height=300
- src="http://.../iframe_sphere2.xaml" width=480>
- </IFRAME>
sphere.xamlの概要
- <ResourceDictionary
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
- <MeshGeometry3D x:Key="_sphere"
- Positions="-0.000001 -0.000001 -1.0 (座標が続く...)"
- TextureCoordinates=""
- TriangleIndices="0 1 2 3 (連番が続く...)"
- />
- </ResourceDictionary>
iframe_sphere2.xaml
- <Page ShowsNavigationUI="False"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
- <!--リソース-->
- <Page.Resources>
- <ResourceDictionary>
- <ResourceDictionary.MergedDictionaries>
- <!--ジオメトリを別のXAMLファイルから読み込む-->
- <ResourceDictionary Source="sphere.xaml"/>
- </ResourceDictionary.MergedDictionaries>
- </ResourceDictionary>
- </Page.Resources>
- <Grid Background="OldLace">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="240"/>
- <ColumnDefinition Width="200"/>
- </Grid.ColumnDefinitions>
- <Viewport3D x:Name="viewport1" Grid.Column="0" Height="200" >
- <Viewport3D.Camera>
- <!--カメラ-->
- <PerspectiveCamera
- LookDirection="-1, -1, -1" Position="2,2,2" FieldOfView="45">
- </PerspectiveCamera>
- </Viewport3D.Camera>
- <ModelVisual3D>
- <ModelVisual3D.Content>
- <!--ライト-->
- <DirectionalLight Color="White" Direction="1,-1,-1" />
- </ModelVisual3D.Content>
- </ModelVisual3D>
- <ModelVisual3D>
- <ModelVisual3D.Content>
- <!--リソースで定義したジオメトリを使用-->
- <GeometryModel3D Geometry="{StaticResource _sphere}">
- <GeometryModel3D.Material>
- <MaterialGroup>
- <!--物体の色-->
- <DiffuseMaterial Brush="Yellow"/>
- <!--ハイライト-->
- <SpecularMaterial
- Brush="{Binding ElementName=cmb_specular_color, Path=Text}"
- SpecularPower="{Binding ElementName=slider1, Path=Value}"/>
- <!--物体の発光-->
- <EmissiveMaterial
- Brush="{Binding ElementName=cmb_emissive_color,Path=Text}"/>
- </MaterialGroup>
- </GeometryModel3D.Material>
- </GeometryModel3D>
- </ModelVisual3D.Content>
- </ModelVisual3D>
- </Viewport3D>
- <StackPanel Grid.Column="1">
- <StackPanel Margin="2,4,0,4">
- <StackPanel Orientation="Horizontal" Background="AliceBlue">
- <TextBlock Text="SpecularPower :" Foreground="Maroon"/>
- <TextBlock Text="{Binding ElementName=slider1, Path=Value}"/>
- </StackPanel>
- <Slider Name="slider1" Minimum="2" Maximum="100" Value="10" Ticks="0.1"
- Background="AliceBlue" Margin="0,0,0,0"/>
- </StackPanel>
- <StackPanel Margin="2,0,4,4" Background="AliceBlue">
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="Specular Color :" Foreground="Maroon"/>
- <TextBlock Text="{Binding ElementName=cmb_specular_color, Path=Text}"/>
- </StackPanel>
- <ComboBox Name="cmb_specular_color" SelectedIndex="0">
- <ComboBox.Items>
- <Color A="255" R="128" G="128" B="128"/>
- <Color A="255" R="64" G="64" B="64"/>
- <Color A="255" R="32" G="32" B="32"/>
- <Color A="255" R="255" G="0" B="0"/>
- <Color A="255" R="0" G="255" B="0"/>
- <Color A="255" R="0" G="0" B="255"/>
- </ComboBox.Items>
- </ComboBox>
- </StackPanel>
- <StackPanel Margin="2,4,4,4" Background="PeachPuff">
- <StackPanel Orientation="Horizontal">
- <TextBlock Text="EmissiveMaterial Color :" Foreground="Maroon"/>
- <TextBlock Text="{Binding ElementName=cmb_emissive_color, Path=Text}"/>
- </StackPanel>
- <ComboBox Name="cmb_emissive_color" SelectedIndex="0">
- <ComboBox.Items>
- <Color A="255" R="128" G="128" B="128"/>
- <Color A="255" R="64" G="64" B="64"/>
- <Color A="255" R="32" G="32" B="32"/>
- <Color A="255" R="255" G="0" B="0"/>
- <Color A="255" R="0" G="255" B="0"/>
- <Color A="255" R="0" G="0" B="255"/>
- </ComboBox.Items>
- </ComboBox>
- </StackPanel>
- </StackPanel>
- </Grid>
- </Page>
|