Reputation: 725
TLDR: Can you tell me what is wrong with the simple "hello world" like WPF 3D app below?
Long version:
I am reading a Computer Graphics book that gives examples in WPF. In this particular example, they do not supply the full source code, but introduce the code part by part.
The only difference I have so far is that they use a <Page>
as the root object, for which I use <Window>
.
I am supposed to see a yellow triangle in the window, but I am seeing an empty Windows window.
I am using Visual Studio 2015 Community Edition.
Code of the MainWindow.xaml is below. After creating the WPF Windows project, I changed only this file.
<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>
Upvotes: 2
Views: 254
Reputation: 13188
Bring your MeshGeometry3D
close to the origin and make your camera point at it, like below:
XAML:
<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>
Upvotes: 1