Easy 3D
Written by Mike James   
Tuesday, 11 August 2009
Article Index
Easy 3D
The Mesh
Rendering
The scene
Spin and storyboards

A renderable object

Now that we have a demonstration mesh we can begin to construct the 3D model and its view. The best place for this code is in the Window Loaded event handler. To add the event handler select Window1 in the designer, select events in the property window and double click the Loaded event.

Banner

All of the drawing instructions are entered into the generated load event handler:

private void Window_Loaded(
object sender,
RoutedEventArgs e)
{

Creating the mesh isn’t quite the end of the story. To be rendered a mesh needs to be associated with a “material” which defines its colour and texture. As you are very likely to want to create multiple 3D objects with the same mesh, but perhaps in different colours and textures, it makes sense to use another class which stores a mesh and a material. This is what the GeometryModel3D class does and it is the simplest object that can be rendered.

We next create a GeometryModel3D and store the mesh in its Geometry property:

GeometryModel3D Cube1 = new
GeometryModel3D();
MeshGeometry3D cubeMesh = MCube();
Cube1.Geometry = cubeMesh;

All we need to complete the model is to assign a material:

Cube1.Material = new
DiffuseMaterial(
new SolidColorBrush(Colors.Red));

This makes our cube render in as if it was covered in a matt red paint. There are other types of material and you can apply more complex brushes such as image brushes and the best way to find out how these work is to experiment.

Banner

<ASIN:1932394818>

<ASIN:1590597826>

<ASIN:0596510373>



Last Updated ( Tuesday, 13 August 2013 )
 
 

   
RSS feed of all content
I Programmer - full contents
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.