Page 3 of 5
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.
All of the drawing instructions are entered into the generated load event handler:
private void Window_Loaded(
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
MeshGeometry3D cubeMesh = MCube();
Cube1.Geometry = cubeMesh;
All we need to complete the model is to assign a material:
Cube1.Material = new
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.