Extending Visual3D - Sphere, Cone, and Cylinder

Update: The source has been updated for the December or January CTP (either will work).

In my previous post I mentioned that one of the motivations for Visual3D was sub-classing.  Prior to the September CTP of the Windows Presentation Foundation (formerly code-named Avalon) there was no extensibility point for creating your own 3D scene nodes.  One of the many possible uses for this new extensibility point is to build a library of 3D primitives.  I put together a short sample which derives a Sphere, a Cone, and a Cylinder primitive from ModelVisual3D.  (Source available here.)

You will notice that these primitives are directly usable from Xaml:

<Viewport3D Camera=”{Camera}” >
<my:Sphere3D Transform=”{XForm1}” Material=”{Azul}” />
<my:Cone3D Transform=”{XForm2}” Material=”{Tulips}” />
<my:Cylinder3D Transform=”{XForm3}” Material=”{Autumn}” />

The primitives are centered at the origin and have a natural size of Radius=1 and Height=2 (i.e., they are bounded by (-1,-1,-1) – (1,1,1)).

This sample does not constitute a terribly complete or expressive library of 3D primitives, but it does illustrate how one could be built.  More compelling examples include deriving from Visual3Ds to add new events and behavior (like collision detection) or surfacing properties like databindable properties which dynamically generate 3D charts and graphs.