The Tiniest 3D Program
January 19, 2007
Roscoe, NY
This, I believe, is the world's tiniest functional WPF 3D program:
-
<Viewport3D xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ModelVisual3D>
<ModelVisual3D.Content>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="-1 0 -8, 1 0 -8, 0 1 -8" />
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial Brush="Red" />
</GeometryModel3D.Material>
</GeometryModel3D>
</ModelVisual3D.Content>
</ModelVisual3D>
<Viewport3D.Camera>
<PerspectiveCamera />
</Viewport3D.Camera>
</Viewport3D>
This XAML file achieves its "tiniest" status in several ways. It defines only a single triangle, but includes only the Positions property and relies on an automatically-generated TriangleIndices property containing the indicies 0, 1, and 2. It does not include a light source, which means the triangle won't have any color and will be displayed as black regardless of the Material setting. Finally, it relies upon the defaults for PerspectiveCamera, which place the camera at the origin looking staight back along the negative Z axis.