2016-12-15 9 views
1

TLDR:以下のWPF 3Dアプリのような単純な「こんにちはの世界」に何が間違っているのか教えていただけますか?WPF 3Dコードは空白のウィンドウを表示します。どうすれば修正できますか?

ロングバージョン:

私はWPFの例を与えるコンピュータグラフィックスの本を読んでいます。この特定の例では、完全なソースコードを提供するのではなく、部分的にコードを導入しています。

私が今までに持っている唯一の違いは、<Page>をルートオブジェクトとして使用していることです。これは<Window>です。

私はウィンドウ内に黄色い三角形が表示されるはずですが、空のWindowsウィンドウが表示されています。

私はVisual Studio 2015 Community Editionを使用しています。

MainWindow.xamlのコードは以下のとおりです。 WPF Windowsプロジェクトを作成した後、このファイルのみを変更しました。

<Window x:Class="WpfApplication1.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:WpfApplication1" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 

    <Window.Resources> 
     <MeshGeometry3D x:Key="RSRCmeshPyramid" 
         Positions="0,75,0 -50,0,50 50,0,50" 
         TriangleIndices="0 1 2" /> 
     <DiffuseMaterial x:Key="RSRCmaterialFront" Brush="Yellow"/> 
     <DiffuseMaterial x:Key="RSRCmaterialBack" Brush="Red"/> 
    </Window.Resources> 


    <Viewport3D > 
     <Viewport3D.Camera> 
      <PerspectiveCamera Position="57, 247, 41" 
            LookDirection="-0.2, 0, -0.9" 
            UpDirection="0,1,0" 
            NearPlaneDistance="0.02" 
            FarPlaneDistance="1000" 
            FieldOfView="45"/> 
     </Viewport3D.Camera> 

     <!-- scene --> 
     <ModelVisual3D> 
      <ModelVisual3D.Content> 
       <Model3DGroup> 
        <AmbientLight Color="White"/> 
        <DirectionalLight Color="Green" Direction="1,-1,-0.9"/> 
        <GeometryModel3D 
          Geometry="{StaticResource RSRCmeshPyramid}" 
          Material="{StaticResource RSRCmaterialFront}"/> 
       </Model3DGroup> 
      </ModelVisual3D.Content> 
     </ModelVisual3D> 
    </Viewport3D> 


</Window> 

答えて

1

原点にごMeshGeometry3D近くを持参し、以下のように、それをお使いのカメラのポイントを作る:XAML

enter image description here

<Window x:Class="WpfApplication343.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:WpfApplication343" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525"> 

<Window.Resources> 
    <MeshGeometry3D x:Key="RSRCmeshPyramid" 
        Positions="0,3,0 -2,0,2 2,0,2" 
        TriangleIndices="0 1 2" /> 
    <DiffuseMaterial x:Key="RSRCmaterialFront" Brush="Yellow"/> 
    <DiffuseMaterial x:Key="RSRCmaterialBack" Brush="Red"/> 
</Window.Resources> 

<Grid> 


    <Viewport3D > 
     <Viewport3D.Camera> 
      <PerspectiveCamera Position="10,10,10" 
           LookDirection="-1,-1,-1" 
           UpDirection="0,1,0" 
           NearPlaneDistance="0.02" 
           FarPlaneDistance="1000" 
           FieldOfView="45"/> 
     </Viewport3D.Camera> 

     <!-- scene --> 
     <ModelVisual3D> 
      <ModelVisual3D.Content> 
       <Model3DGroup> 
        <AmbientLight Color="White"/> 
        <DirectionalLight Color="Green" Direction="1,-1,-0.9"/> 
        <GeometryModel3D 
         Geometry="{StaticResource RSRCmeshPyramid}" 
         Material="{StaticResource RSRCmaterialFront}"/> 
       </Model3DGroup> 
      </ModelVisual3D.Content> 
     </ModelVisual3D> 
    </Viewport3D> 

</Grid> 

関連する問題