|
Introduction
When Microsoft published Avalon as Community Technology Preview I became very interested
in its 3D functionality. I believe that 3D is a natural step in evolution of displays.
The evolution went from teleprinters to black & white monitors (and black &
green and better black & orange). Then the first color monitors came. And now
their time is almost over - LCD monitors have already taken their place. 10 years
ago it was hard even to imagine that 1 cm deep monitor could show such a picture.
And the evolution is of course not over. The first 3D monitors are already on the
market. If you enter “3d display” into web search, you will get lots of links to
different devices that show picture in 3D. Some of them enable 360 degrees view,
some are similar to LCD monitors but have extendeb 3D view. The primary market
for such devices is currently high-tech medical equipment and research labs but
as always the technology will come to our homes. In the time of writting this article
Sharp was selling its 15" 3D LCD monitor for just $449.
I believe that in the future, all the icons, buttons and windows in OS will be three
dimensional. And we will also see them in 3D. For me, Windows Presentation Foundation
(Avalon) is the beginning of such a world.
There are two ways to define 3D objects in Avalon. They can be defined in code-behind
or in XAML. The definition in code-behind is usually used for objects that can be
mathematically defined, like sphere or torus. In this case all the points, triangle
indices and normals can be calculated using mathematical formulas.
In XAML object definition, all the data are written in text format. The following
code represents the definition for a simple tetrahedron:
<GeometryModel3D.Geometry>
<MeshGeometry3D
TriangleIndices="0 1 2 1 2 3 2 3 0 0 1 3"
Normals="-1,-1,0 1,-1,0 1,0,0 0,0,1"
Positions="-2,-2,-2 2,-2,-2 0,2,-2 0,0,1"/>
</GeometryModel3D.Geometry>
As you can see, even for very simple 3D objects, the XAML definition is quite complicated.
Note that the above definition is for the simplest 3D object - it has only four
corners (Positions) and four triangles (TriangleIndices). For such an object, it
is still possible to define the data on your own - with pencil and a sheet of paper.
But already for a simple cube this can become a breath-taking job. Furthermore,
the common 3D objects can have hundreds of corners and triangles with complicated
normals and texture coordinates. So there is almost no way to calculate the data
for the 3D objects on your own.
On the other hand, there are great 3D modeling programs. It would be very convenient
to define objects in those programs and import them directly into WPF.
One solution is to install an add-in into modeling application that exports 3D model
information into xaml text that can be used in WPF. Such exporters exist for Maya
and Blender. This can be very handy solution because you just insert the exported
text into your xaml file and you can already show and use the 3D objects.
But on the other hand when we need to use a picture or an icon in our application
we do not expect to export the picture into lines and dots. We simply draw or more
commonly get the picture from internet and import it directly into our application.
Wouldn’t it be great if we could do the same with our 3D content?
|