WPF學習日誌 ~ 3DTools ~

摘要:WPF學習日誌 ~ 3DTools ~

Note:本篇開發工具使用VS2008,.net framework版本3.5
雖然XAML Code還不會但是還是很想嘗試看看WPF 3D的功能,在WIndowsClient看了Building an Interactive 3D Video Player的範例,實在是手很癢..於是乎就照著範例測試了一下,不過其中播放影片的那個UserControl的XAML Code我沒有阿..殘念,沒關係,我用老朋友Button來測試,嘿嘿..
首先要到CodePlex下載3DTools的Dll檔,上面有bin(編譯好的),或是scr(未編譯的),看你是想要用哪一種,檔案準備好了之後,把它加到我們專案的參考進來,下面我們就看看XAML Code吧

也可以到這邊下載VS2008的專案檔來看

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Inter3D="clr-namespace:_3DTools;assembly=3DTools"
    x:Class="Window1"
    Title="Window1" Height="346" Width="469">
    <Window.Resources>
        <MeshGeometry3D x:Key="palnMesh" Positions="-1,-1,0 1,-1,0 1,1,0 -1,1,0" TextureCoordinates="0,1 1,1 1,0 0,0" TriangleIndices="0 1 2 0 2 3" />
    </Window.Resources>
    <Grid>
        <Inter3D:TrackballDecorator>
            <Inter3D:Interactive3DDecorator>
        <Viewport3D>
            <Viewport3D.Camera>
                <PerspectiveCamera Position="1,1,10" LookDirection="0,0,-1"></PerspectiveCamera>
            </Viewport3D.Camera>
           
            <ModelVisual3D>
                <ModelVisual3D.Content>
                    <AmbientLight/>
                </ModelVisual3D.Content>      
             </ModelVisual3D>
 
             <Inter3D:InteractiveVisual3D  Geometry="{StaticResource palnMesh}">
                <Inter3D:InteractiveVisual3D.Visual>
                            <Button Content="Cleck Me" />
                        </Inter3D:InteractiveVisual3D.Visual>
            </Inter3D:InteractiveVisual3D>
        </Viewport3D>
        </Inter3D:Interactive3DDecorator>
        </Inter3D:TrackballDecorator>
       
    </Grid>
</Window>
 
執行程式之後,你可以按著滑鼠左鍵,然後移動滑鼠(嘿嘿..我的button會旋轉耶..),或是右鍵,可以拉近拉遠,很炫吧。
其中我們看看下面這幾行
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Inter3D="clr-namespace:_3DTools;assembly=3DTools"

上面兩行是預設引入的,Inter3D是加上去的,這感覺像是引入(Imports)命名空間的感覺,有加進來的話才會有相關功能可以用,好啦,不多說了,馬上動手去測試看看吧。
另外Button的部分我們也可以改成下面這樣,也可以放影片喔
 
         <mediaelement source="D:\blendButton.wmv"></mediaelement>