November 29, 2020
Hot Topics:

Creating an Interactive 3D world with C# and DirectX

  • By Fatima Ahmed
  • Send Email »
  • More Articles »

Then, you create the first mesh object to load the "Drawer" in the room:

TVScene.CreateMeshBuilder (Name As String)

Creates a new empty mesh builder (TVMesh) and add it in the scene graph. You must ALWAYS use this method to create a new mesh or to load one; otherwise, it will not be included in the scene graph, and will probably be not rendered.

//Create 3D object mesh
Obj1 = TVScene.CreateMeshBuilder("Obj1");

Then, load the X files here from the 3D object models that you created in 3D Studio Max and exported them as ".x" files. There are three functions to load an X file, depending on whether the file is animated or not or whether you need to import the material and texture from 3D Studio Max.

TVMesh.LoadXFile(Filename As String, LoadTextures As Boolean,
                 LightingMaterial As Boolean)

Loads a X (DirectX Format) static model into this empty mesh.

TVMesh.LoadSkinMesh(Filename As String)

Loads a SKinned Mesh file (x animated file) into this empty mesh.

TVMesh.LoadXFileHierarchy(Filename As String,
                          WithAnimation As Boolean,
                          WithMaterials As Boolean)

Loads a SKinned Mesh file (x animated file) into this empty mesh.

//Here we load the X files for the meshes one by one for all the 10 objects
Obj1.LoadXFile("Media\Meshes\drawer1.x", true, true);

When you load the obj1 object in the scene, you get the following result:


Figure 6: Loading an object in the room

After applying the texture to the floor and the drawer object, your scene is modified to resemble this:

Room.AddFloor(global.GetTex("Carpet"), -350.0f, -350-0f, 350.0f, 350.0f,
              -50.0f, 10.0f, 10.0f, true, false);

Figure 7: Applying texture

I like to change the walls, too, so apply another texture "Wall":

Figure 8: Applying texture to the walls

Likewise, you have to add all the objects in the scene, specifying their positions, textures, and other properties if required.

Page 3 of 7

This article was originally published on February 3, 2006

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date