The Geometries of Balder provides many existing models, such as cubes and columns. However, when developing games, we usually use 3D design tools to create custom 3D models, this article describes how to import and display a custom 3D model.
First, let's look at the built-in Geometries model. You can view it in the object browser or Geometries.
The Heightmap in it will be introduced later. This time we will mainly introduce Mesh (Mesh object) and use it to import custom models.
Then, prepare a 3D design tool, 3Dmax, Maya, Lightwave, or ......, Well, let's simply use the popular 3 DMax to open the Max software, pull a pot from the Object, select File-> export, and select the ASE file format.
Save the name as teapot. the ase file is added to our project. This project can be modified from L1. See or download Silverlight C # Game Development: L1 3D world construction.
Change the file compilation method to Resource, that is, Resource mode. Set the Silverlight Control name to Lesson02 and add the following code to the constructor:
// L1
Game game = new Game () {Width = 600, Height = 400 };
Game. Camera = new Camera ();
Game. Camera. Position = new Coordinate (100,150,100 );
Game. Camera. Target = new Coordinate (0, 0, 0 );
Game. Children. Add (new OmniLight () {Position = new Coordinate (0, 0, 0 )});
// L2
// A new Mesh object Mesh
Mesh Teapot = new Mesh ();
// Set coordinates
Teapot. Position = new Coordinate (0, 0, 0 );
// Enable interaction (you can use the mouse to rotate)
Teapot. InteractionEnabled = true;
// Read the file name. Currently, the file format of ase is supported.
Teapot. AssetName = new Uri ("/Balder_Studio; component/Res/teapot. ase", UriKind. Relative );
// Add the teapot to the Game
Game. Children. Add (Teapot );
LayoutRoot. Children. Add (game );
Please note that the directory of the Uri assigned by AssetName must be the same as the location you added to. If this is not too clear, please refer to the project that comes with it and download the source code.
In this case, you may find some errors because the namecontrol reference is not added and the namespace Using is added to the file header:
Using Balder. Execution;
Using Balder. Lighting;
Using Balder. View;
Using Balder. Math;
Using Balder. Objects. Geometries;
Well, don't forget to add the control in MainPage to Lesson02. Run it and check the effect. The following is the Silverlight program:
If you think it is too small, you can modify the camera coordinates to adjust the observed range. We will introduce the camera and light in the next chapter.
Source code: Click here to download the project
If Balder. dll is missing in the project, download it quickly here: SL4_Balder.rar
We recommend the Silverlight game development blog:Dark blue right hand