3D models are the mesh objects that are to be placed in the 3D scene. A mesh is a series of polygons grouped to form a surface. They can include hall, terrain, roads, factory, machines, cars, people, and the like. Design the 3D mesh objects (animated or unanimated) in any 3D graphics software available (for example, 3D Studio Max, Maya, Light Wave, and so on) and covert them into a format that can be imported in .NET (as in the .x file format for DirectX). Other file formats are also supported by the engine. I have used 3D Studio Max to design the mesh objects and converted them to X files using Panda Exporter. You can find many other 3D graphics software available both for purchase and for free to download on the Web. The other easy way is to download pre-built 3D models uploaded at many different Web sites like www.amazing3d.com and www.3dcafe.com.
You have created 10 objects here. They are to be placed at different positions in the room, as shown in the first picture above.
//Declaring our 3D mesh objects here
TVMesh Obj1, Obj2, Obj3, Obj4, Obj5, Obj6, Obj7, Obj8,
Obj9, Obj10;
TrueVision3D.TVMeshClass Room;
In the Form1_Load event, you add:
//Initialize all 3D objects as TVMesh class objects
Obj1 = new TVMesh();
//Create a 3D Room mesh
Room = (TVMeshClass)TVScene.CreateMeshBuilder("roommesh");
The engine can load these types of textures:
Standard window formats: BMP, JPG, PNG, DIB, TGA
DirectX texture format: DDS
PNG, TGA, and DDS can have an alpha channel that controls the transparency of the texture.
The function for loading texture in this engine is "LoadTexture" that can be called by the TVScene object or the TextureFactory object. It returns the Texture index in the texture factory. The list of the parameters is as follows:
I hope all the arguments of the "LoadTexture" are clear enough to understand except for two. The colorkey of the texture will not be rendered, resulting in transparency. The multialpha is used to mask; if multialpha is true, you have only two possible alpha values (0 and 1). If it's set to false, the alpha value has 64 possible values, or 256 if it's 32bits. Now, it's time to load all the textures in the code:
//Load all the textures
TVScene.LoadTexture("Media\\Textures\\9.bmp",-1,-1,"RoomTexture");
TexFactory.LoadTexture("Media\\Textures\\bottom.bmp", "Carpet", -1, -1,
CONST_TV_COLORKEY.TV_COLORKEY_NO, true, true);
TexFactory.LoadTexture("Media\\Textures\\floor1.bmp", "Wall", -1, -1,
CONST_TV_COLORKEY.TV_COLORKEY_NO, true, true);
Now, move on to building a room having four walls and two floors (including a ceiling). The TrueVision engine contains three functions for creating the wall and adding it to a single mesh "Room" that you created. These are:
AddWall
Creates a wall (quad) that is perpendicular to the y plane along a line.
AddWall2
Creates a wall (quad) that is perpendicular to the y plane along a line with different y altitudes.
This simple method allows you to create textured walls easily. The X and Z coordinates are the same that for a line on a plane. This method allows the wall to start at a specified altitude and to stop at another, so it's a little more powerful than TVMesh.AddWall2.
The above function adds a floor face to the current mesh. Floor face is a rectangular horizontal plane on the Y plane.
// Like the "add wall" method, we will add a floor to this room.
Room.AddFloor(global.GetTex("RoomTexture"), -350.0f, -350-0f, 350.0f, 350.0f,
-50.0f, 10.0f, 10.0f, true, false);
Room.AddFloor(global.GetTex("RoomTexture"), -350.0f, -350-0f, 350.0f, 350.0f,
300.0f, 10.0f, 10.0f, true, false);
Then, you load the Room mesh at the proper location in the Scene specifying the values of x, y, and z as follows:
//Set the position of the room mesh
Room.SetPosition(x_move, y_move, z_move);
The 3D room with the "RoomTexture" applied to it looks like this:
Figure 5: Creating a Room mesh and loading it in the scene
About the Author
Fatima Ahmed is a B.S. in Computer Sciences and recently working in VC++ and .NET applications. Her interests include teaching, helping others, travelling, writing articles on different topics and studying more and more.
Add www.codeguru.com to your favorites Add www.codeguru.com to your browser search box IE 7 | Firefox 2.0 | Firefox 1.5.xReceive news via our XML/RSS feed
RATE THIS ARTICLE:
Excellent Very Good Average Below Average Poor
(You must be signed in to rank an article. Not a member? Click here to register)